{"problem":{"name":"K. The World of Trains","description":{"content":"In the computer world, a train of the length n can be represented as an array A of the same length. Such an array A contains integer elements between 1 and k, inclusive. Each element in A represents t","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":3000,"memory_limit":524288},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10113K"},"statements":[{"statement_type":"Markdown","content":"In the computer world, a train of the length n can be represented as an array A of the same length. Such an array A contains integer elements between 1 and k, inclusive. Each element in A represents the quality of one carriage. You can notice that there are exactly kn distinct trains.\n\nMike loves to travel and today he is going to do it with his friends. They want to occupy exactly d consecutive carriages. Of course, they want chosen d carriages to be of equal quality.\n\nSomeone saw a train and thus knows an array A. He said that there are exactly t ways for them to choose d consecutive carriages of equal quality. Now, Mike wants to know how many trains satisfy this description. Your task is to count them modulo 109 + 7.\n\nThe only line of the input contains four integers n, d, t and k (1 ≤ d ≤ n ≤ 3333, 0 ≤ t ≤ n - d + 1, 1 ≤ k ≤ 109).\n\nFind the number of distinct trains fitting the given description, and print it modulo 109 + 7.\n\nFor the first sample test the only possible arrays are:\n\n## Input\n\nThe only line of the input contains four integers n, d, t and k (1 ≤ d ≤ n ≤ 3333, 0 ≤ t ≤ n - d + 1, 1 ≤ k ≤ 109).\n\n## Output\n\nFind the number of distinct trains fitting the given description, and print it modulo 109 + 7.\n\n[samples]\n\n## Note\n\nFor the first sample test the only possible arrays are:  {1, 1, 2, 1, 2}  {1, 2, 1, 1, 2}  {1, 2, 1, 2, 2}  {1, 2, 2, 1, 2}  {2, 1, 1, 2, 1}  {2, 1, 2, 1, 1}  {2, 1, 2, 2, 1}  {2, 2, 1, 2, 1}","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n, d, t, k \\in \\mathbb{Z} $ be given integers with $ 1 \\leq d \\leq n \\leq 3333 $, $ 0 \\leq t \\leq n - d + 1 $, $ 1 \\leq k \\leq 10^9 $.  \nLet $ \\mathcal{A} $ be the set of all sequences $ A = (a_1, a_2, \\dots, a_n) $ where each $ a_i \\in \\{1, 2, \\dots, k\\} $.  \nFor a sequence $ A \\in \\mathcal{A} $, define the number of *valid windows* as:  \n$$\nf(A) = \\left| \\left\\{ i \\in \\{1, 2, \\dots, n - d + 1\\} \\mid a_i = a_{i+1} = \\dots = a_{i+d-1} \\right\\} \\right|\n$$\n\n**Constraints**  \n1. $ 1 \\leq d \\leq n \\leq 3333 $  \n2. $ 0 \\leq t \\leq n - d + 1 $  \n3. $ 1 \\leq k \\leq 10^9 $  \n\n**Objective**  \nCompute:  \n$$\n\\left| \\left\\{ A \\in \\mathcal{A} \\mid f(A) = t \\right\\} \\right| \\mod (10^9 + 7)\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10113K","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}