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++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>

// type alias
using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;


/* ----- class ----- */

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;


/* ----- debug ----- */

#if __has_include("../setting/source/debug.hpp")
#include "../setting/source/debug.hpp"
#endif


/* ----- short functions ----- */

template <class T>
inline T sq(T a) { return a * a; }

template <class T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

// 0-indexed
template <class T, class U>
inline T kthbit(T a, U k) { return (a >> k) & 1; }

template <class T, class U>
inline T mask(T a, U k) { return a & ((1 << k) - 1); }

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}


/* ----- constants ----- */

// const int INF = std::numeric_limits<int>::max() / 3;
// const lint INF = std::numeric_limits<lint>::max() / 3;
// const ldouble PI = acos(-1);
// const ldouble EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));


using namespace std;

using Poly = vector<int>;

int p;

int mpow(int b, int n) {
    int ret = 1;
    while (n > 0) {
        if (n & 1) (ret *= b) %= p;
        n >>= 1;
        (b *= b) %= p;
    }
    return ret;
}

// v *= (x - k)
Poly mul(const Poly& v, int k) {
    Poly ret = v;
    ret.insert(ret.begin(), 0);
    ret.pop_back();
    for (int i = 0; i < p; ++i) {
        ret[i] -= (v[i] * k) % p;
        if (ret[i] < 0) ret[i] += p;
    }
    return ret;
}

Poly mulp(const Poly& v, const Poly& w) {
    Poly ret(p, 0);
    for (int i = 0; i < p; ++i) {
        for (int j = 0; i + j < p; ++j) {
            (ret[i + j] += v[i] * w[j] % p) %= p;
        }
    }
    return ret;
}

int main() {
    cin >> p;

    vector<Poly> fore(p, Poly(p, 0));
    fore[0][1] = 1;
    for (int i = 1; i < p; ++i) {
        fore[i] = mul(fore[i - 1], i);
    }
    vector<Poly> back(p + 1, Poly(p, 0));
    back[p][0] = 1;
    for (int i = p - 1; i >= 0; --i) {
        back[i] = mul(back[i + 1], i);
    }


    Poly ans(p, 0);
    for (int i = 0; i < p; ++i) {
        int a;
        cin >> a;
        if (a == 0) continue;

        Poly tmp;
        if (i == 0) {
            tmp = back[i + 1];
        } else {
            tmp = mulp(fore[i - 1], back[i + 1]);
        }

        int div = 1;
        for (int j = 0; j < p; ++j) {
            if (i == j) continue;
            (div *= (i - j)) %= p;
            if (div < 0) div += p;
        }

        // cerr << i << ":" << tmp << "," << div << endl;

        int inv = mpow(div, p - 2);
        for (auto& b : tmp) {
            (b *= inv) %= p;
        }

        // cerr << i << ";" << tmp << endl;

        for (int i = 0; i < p; ++i) {
            (ans[i] += tmp[i]) %= p;
        }
    }

    for (auto a : ans) {
        cout << a << " ";
    }
    return 0;
}