Let p be a prime number and a=(a_0,a_1,…,a_n−1) be an array of n integers, where p=Kn+1 for some positive integer K. We say that the array a^=(a^_0,a^_1,…,a^_n−1) is the Discrete Fourier Transform of the array a if for every k=0,1,…,n−1 the following holds:
a^_k=(∑_j=0n−1a_jwjk)modp
and we simply write a^=DFT(a). Here w denotes a primitive n-th root of unity modulo p, that is, we have wn≡1(modp) and, for every i such that 0<i<n, wi≡1(modp).
Note that there can be multiple choices for w, so the DFT won't be unique. Let us clarify how to uniquely find it for this problem. Let g be a generator modulo p, that is, for every x such that 0<x<p, there exists a positive integer r such that 0≤r<p−1 and x=grmodp. You can find the smallest positive value for g that works and choose w=gKmodp.
Now we define \mathrm{DFT}^{(m)}(a) = \underbrace{\mathrm{DFT}(\mathrm{DFT}( \ldots \mathrm{DFT}(a) \ldots ))}\_{\text{m times}}, so your task is just to find DFT(m)(a).
The first line contains three space-separated integers: n (2≤n≤3⋅105), p (5≤p≤109+7), and m (0≤m≤1018), the parameters of the problem described above. It is guaranteed that p is prime and that n divides p−1 evenly.
The second line contains n space-separated integers a_0,a_1,…,a_n−1 (0≤a_i<p), the array a.
Output n space-separated integers a′_0,a′_1,…,a′_n−1, the resulting array after doing the operation stated in the problem.
In the sample test case, the smallest possible generator for p=61 is g=2. We have that K=661−1=10, so we choose w=210mod61=48 to be the primitive 6-th root of unity modulo 61. The first iterations of the DFT are as follows: