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: Runtime Error)

//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) (cerr<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))
#define rep(i,n) for(int i = 0; i < (n); i++)
#define REP(i,n) for(int i = 1; i <= (n); i++)

using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
typedef pair<ll,ll> pll;
template <typename T> using rkt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-8;
constexpr ll N = 2525, INF = 1e18, MOD = 2147483647, K = 14699;
constexpr inline ll cdiv(ll x, ll m) { return (x+m-1)/m; } // ceiling divide, x/m for flooring divide
template <typename T> void M(T &x, ll m = MOD){x%=m; if(x<0) x+=m;}

ll p,dp[N][N];
ll f[N]={1},t[N],ans[N];
ll mdp(ll e, ll p, ll m) {
    ll r = 1;
    while(p) {
        if(p&1) r=r*e%m;
        e=e*e%m, p>>=1;
    }
    return r;
}
inline ll inv(ll x){return mdp(x,p-2,p);}
signed main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> p;
    for(int i = 0; i < p; i++) cin >> dp[1][i];
    for(int L = 2; L <= p; L++) {
        for(int i = 0; i < p; i++) {
            dp[L][i] = (dp[L-1][i+1] - dp[L-1][i] + p) * inv(L-1) % p;
        }
    }
    for(int i = 0; i < p; i++) {
        for(int j = 0; j < p; j++) ans[j] = (ans[j]+dp[i+1][0]*f[j])%p;
        t[0] = (p-i)*f[0]%p;
        for(int j = 1; j < p; j++) t[j] = (f[j-1] - i*f[j] + p)%p;
        for(int j = 0; j < p; j++) f[j] = t[j];
    }
    for(int i = 0; i < p; i++) cout << ans[i] << " \n"[i==p-1];
    /*for(int i = 0; i < p; i++) {
        ll sum = 0, pwr = 1;
        for(int j = 0; j < p; j++) sum = (sum+ans[j]*pwr)%p, pwr = pwr*i%p;
        cout << sum << " \n"[i==p-1];
    }*/
}