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: Wrong Answer)

# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<Edge>>g;
vector<edge>edges;
vector<Pll>v;
map<string, LL>ma;
multiset<LL>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, a[210000], b[210000], c[3000], fact[6000];
string str, ss;
bool f[110000];
//char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL modpow(LL a, LL n = MOD - 2) {
	LL r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % MOD, a = a * a%MOD, n >>= 1;
	return r;
}
int main() {
	cin >> n;
	MOD = n;
	rep(i, n) {
		cin >> a[i];
	}
	c[0] = 1;
	rep(i, n) {
		LL C[3000] = {};
		rep(j, i+2) {
			C[j] = (j > 0 ? c[j - 1] : 0) - (c[j]*i)%MOD;
			if (C[j] < 0)C[j] += MOD;
			C[j] %= MOD;
		}
		rep(j, n+1)c[j] = C[j];
	}
	fact[0] = 1;
	rep(i, n*2+1) {
		if ((i + 1) % MOD == 0)fact[i+1] = fact[i];
		else fact[i+1] = fact[i]*(i + 1) % MOD;
	}
	rep(i, n) {
		LL cur = a[i], C[3000] = {};
	
		cur *= modpow(fact[i+n-2] * modpow(fact[i]) % MOD);
		Rrep(j, n) {
			if (j == n - 1)C[j] = c[j + 1];
			else C[j] = c[j + 1] + C[j + 1] * i;
			if (C[j] < 0)C[j] += n;
			C[j] %= MOD;
			b[j] += C[j] * cur;
			b[j] %= MOD;
		}
	}
	rep(i, n) {
		if (i)cout << " ";
		cout << b[i];
	}
	cout << endl;
	return 0;
}