Problem:
Score : 600 points

Problem Statement

Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.

Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:

For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.

For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.

Constraints

2 \leq p \leq 2999

p is a prime number.

0 \leq a_i \leq 1

Input

Input is given from Standard Input in the following format:

p
a_0 a_1 \ldots a_{p-1}

Output

Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.

It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.

Sample Input 1

2
1 0

Sample Output 1

1 1

f(x) = x + 1 satisfies the conditions, as follows:

f(0) = 0 + 1 = 1 \equiv 1 \pmod 2

f(1) = 1 + 1 = 2 \equiv 0 \pmod 2

Sample Input 2

3
0 0 0

Sample Output 2

0 0 0

f(x) = 0 is also valid.

Sample Input 3

5
0 1 0 1 0

Sample Output 3

0 2 0 1 3

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
//using System.Threading.Tasks;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void solve()
    {
        int P = cin.nextint;
        var y = cin.scanlong;
        var x = new long[P];
        for (int i = 0; i < P; i++)
        {
            x[i] = i;
        }

        var L = new LagrangePolynomial(x, y, P);
        L.calc();


    }

}


class FastFourierTransform
{
    public FastFourierTransform() { }

    public Complex[] Convolute(Complex[] G, Complex[] H)
    {
        int sz = G.Length + H.Length + 1;
        int N = 1; while (N < sz) N <<= 1;
        Array.Resize(ref G, N);
        Array.Resize(ref H, N);

        FFT(G); FFT(H);
        Complex[] F = new Complex[N];
        for (int i = 0; i < N; i++)
        {
            F[i] = G[i] * H[i];
        }

        FFT(F, -1);
        return F;
    }
    public long[] Convolute(long[] P, long[] Q)
    {
        int sz = P.Length + Q.Length + 1;
        int N = 1; while (N < sz) N <<= 1;
        var G = new Complex[N];
        var H = new Complex[N];
        for (int i = 0; i < P.Length; i++)
        {
            G[i] = new Complex(P[i], 0);
        }
        for (int i = 0; i < Q.Length; i++)
        {
            H[i] = new Complex(Q[i], 0);
        }

        FFT(G); FFT(H);
        Complex[] F = new Complex[N];
        for (int i = 0; i < N; i++)
        {
            F[i] = G[i] * H[i];
        }

        FFT(F, -1);

        long[] ret = new long[sz];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = (long)(Round(F[i].Real));
        }

        return ret;
    }
    void FFT(Complex[] F, int rev = 1)
    {
        for (int i = 0, j = 1; j < F.Length - 1; j++)
        {
            for (int k = F.Length >> 1; k > (i ^= k); k >>= 1) ;
            if (j < i) swap(ref F[i], ref F[j]);
        }

        for (int i = 2; i <= F.Length; i <<= 1)
        {
            int m = i >> 1;
            // zeta = exp(rev * PI / m * i)
            Complex zeta = new Complex(Cos(PI / m), Sin(PI / m) * rev);

            for (int j = 0; j < F.Length; j += i)
            {
                Complex zeta_pow = Complex.One;
                for (int u = j, v = j + m; v < j + i; u++, v++)
                {
                    Complex vl = F[u], vr = zeta_pow * F[v];
                    F[u] = vl + vr;
                    F[v] = vl - vr;
                    zeta_pow = zeta_pow * zeta;
                }
            }
        }

        if (rev == -1)
        {
            for (int i = 0; i < F.Length; i++)
            {
                F[i] /= F.Length;
            }
        }
    }

    void swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}

class LagrangePolynomial
{
    readonly long[] X, Y;
    readonly long mod;
    public LagrangePolynomial(long[] X, long[] Y, long p)
    {
        this.X = X;
        this.Y = Y;
        mod = p;
        for (int i = 0; i < X.Length; i++)
        {
            long tmp = 1;
            for (int j = 0; j < X.Length; j++)
            {
                if (i == j) continue;
                tmp *= X[i] - X[j];
            }
            Y[i] *= modpow(tmp, mod - 2, mod);
        }
    }
    public long[] calc()
    {
        var ret = new long[mod];
        var FFT = new FastFourierTransform();

        for (int i = 0; i < Y.Length; i++)
        {
            var tmp = new long[1];
            tmp[0] = 1;
            for (int j = 0; j < X.Length; j++)
            {
                if (i == j) continue;

                var next = new long[2];
                next[0] = -X[j];
                next[1] = 1;

                tmp = FFT.Convolute(tmp, next);

                //Write($"j={j},X[j]={X[j]} ");
                //tmp.join();
            }

            for (int j = 0; j < Min(ret.Length, tmp.Length); j++)
            {
                ret[j] += tmp[j] * Y[i] % mod;
            }
        }

        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] %= mod;
            if (ret[i] < 0) ret[i] += mod;
        }

        ret.join();

        return ret;
    }

    /// <summary>
    /// return y=f(x), O(dim^2).
    /// </summary>
    /// <param name="x"></param>
    /// <returns></returns>
    public long this[long x]
    {
        get
        {
            long ret = 0;
            for (int i = 0; i < Y.Length; i++)
            {
                long product = Y[i];
                for (int j = 0; j < X.Length; j++)
                {
                    if (i == j) continue;
                    product *= x - X[j];
                }
                ret += product;
            }
            return ret;
        }
    }



    //a^b(mod p) solution works in O(logb).
    long modpow(long a, long b, long p)
    {
        if (b == 0) return 1;
        if (b % 2 == 0)
        {
            long d = modpow(a, b / 2, p);
            return d * d % p;
        }
        else
        {
            return a * modpow(a, b - 1, p) % p;
        }
    }
}

//class BinomialCoefficient
//{
//    public ModInt[] fact, ifact;
//    /// <summary>
//    /// <paramref name="n"/>は <paramref name="Mod"/>未満でお願いします。
//    /// </summary>
//    /// <param name="n"></param>
//    public BinomialCoefficient(ModInt _n)
//    {
//        int n = (int)_n.num;
//        fact = new ModInt[n + 1];
//        ifact = new ModInt[n + 1];
//        fact[0] = 1;
//        for (int i = 1; i <= n; i++)
//            fact[i] = fact[i - 1] * i;
//        ifact[n] = ModInt.Inverse(fact[n]);
//        for (int i = n - 1; i >= 0; i--)
//            ifact[i] = ifact[i + 1] * (i + 1);
//        ifact[0] = ifact[1];
//    }
//    public ModInt this[int n, int r]
//    {
//        get
//        {
//            if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;
//            return fact[n] * ifact[n - r] * ifact[r];
//        }
//    }
//    public ModInt RepeatedCombination(int n, int k)
//    {
//        if (k == 0) return 1;
//        return this[n + k - 1, k];
//    }
//}

static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}