AtCoder Beginner Contest 137 - Polynomial Construction

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-----
2
1 0

-----Sample Output-----
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

Source: atcoder | Difficulty: MEDIUM_HARD


Solutions:
p = int(input())
a = list(map(int, input().split()))
MAX = 3000
fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
	fact[i] = fact[i - 1] * i % p
inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
	inv[i] = inv[p % i] * (p - p // i) % p
fact_inv = [1] * (MAX + 1)
for i in range(1, MAX + 1):
	fact_inv[i] = fact_inv[i - 1] * inv[i] % p

def comb(n, k):
	if n < k:
		return 0
	return fact[n] * fact_inv[n - k] * fact_inv[k] % p
ans = [0] * p
for (i, ai) in enumerate(a):
	if ai == 1:
		ans[-1] += 1
		for j in range(p):
			ans[j] -= pow(-i, j, p) * comb(p - 1, j)
			ans[j] %= p
print(*ans[::-1])


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
p = int(readline())
a = list(map(int, readline().split()))
MAX = 3000
fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
	fact[i] = fact[i - 1] * i % p
inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
	inv[i] = inv[p % i] * (p - p // i) % p
fact_inv = [1] * (MAX + 1)
for i in range(1, MAX + 1):
	fact_inv[i] = fact_inv[i - 1] * inv[i] % p

def comb(n, k):
	if n < k:
		return 0
	return fact[n] * fact_inv[n - k] * fact_inv[k] % p
ans = [0] * p
for (i, ai) in enumerate(a):
	if ai == 1:
		ans[-1] += 1
		for j in range(p):
			ans[j] -= pow(-i, j, p) * comb(p - 1, j) % p
			ans[j] %= p
print(*ans[::-1])


p = int(input())
A = [[1] * p for _ in range(p)]
a = list(map(int, input().split()))
for n in range(p):
	for m in range(p - 1):
		A[n][m + 1] = n * A[n][m] % p
c = [0] * p
f = [1] * p
for n in range(1, p):
	f[n] = n * f[n - 1] % p
for m in range(p):
	c[m] = f[p - 1] * pow(f[m], p - 2, p) * pow(f[p - 1 - m], p - 2, p) % p
b = [0] * p
for n in range(p):
	if a[n] == 0:
		continue
	b[0] += 1
	b[0] %= p
	for m in range(p):
		b[m] -= A[n][p - 1 - m] * c[m] * (1 - m % 2 * 2)
		b[m] %= p
print(' '.join([str(x) for x in b]))


import sys
input = sys.stdin.readline
p = int(input())
A = tuple(map(int, input().split()))
B = [0] * p
U = p - 1
MOD = p
fact = [1] * (U + 1)
fact_inv = [1] * (U + 1)
for i in range(1, U + 1):
	fact[i] = fact[i - 1] * i % MOD
fact_inv[U] = pow(fact[U], MOD - 2, MOD)
for i in range(U, 0, -1):
	fact_inv[i - 1] = fact_inv[i] * i % MOD

def comb(n, k):
	if k < 0 or k > n:
		return 0
	z = fact[n]
	z *= fact_inv[k]
	z %= MOD
	z *= fact_inv[n - k]
	z %= MOD
	return z
for (j, a) in enumerate(A):
	if a:
		B[0] += 1
		temp = 1
		for i in range(p - 1, -1, -1):
			B[i] -= (-1) ** (i % 2) * temp * comb(p - 1, i)
			temp *= j
			temp %= p
			B[i] %= p
print(*B)


def ext_euc(a, b):
	if b == 0:
		return (1, 0, a)
	(y, x, v) = ext_euc(b, a % b)
	y -= a // b * x
	return (x, y, v)

def mod_inv(a, mod):
	(x, _, _) = ext_euc(a, mod)
	return x % mod

def main():
	p = int(input())
	A = list(map(int, input().split()))
	comb = [1] * p
	for i in range(1, p):
		v = comb[i - 1]
		v *= p - i
		v *= mod_inv(i, p)
		comb[i] = v % p
	b = [0] * p
	for (k, a) in enumerate(A):
		if a == 0:
			continue
		pw = [1] * p
		for i in range(1, p):
			pw[-(i + 1)] = pw[-i] * -k % p
		for i in range(p):
			if i == 0:
				b[i] += 1
			b[i] -= comb[i] * pw[i]
			b[i] %= p
	print(' '.join(map(str, b)))
main()


p = int(input())
b_list = [0 for _ in range(p - 1)]
a_list = list(map(int, input().split()))

def frac(n):
	if a_list[n] == 1:
		t = 1
		for j in range(p - 1):
			b_list[j] -= t
			t = t * n % p
if a_list[0] == 1:
	b_list[0] -= 1
for i in range(p - 1):
	frac(i + 1)
b_list.reverse()
print(a_list[0], end=' ')
for j in b_list:
	print(j % p, end=' ')


def solve():
	p = int(input())
	(*A,) = map(int, input().split())
	B = [0] * p
	C = [0] * p
	C[0] = 1
	zeros = [0] * p
	Y = [0] * p
	R = [0] * p
	for i in range(p):
		v = 0
		b = 1
		for j in range(i):
			v += Y[j] * b
			b = b * (i - j) % p
		Y[i] = y = (A[i] - v) * pow(b, p - 2, p) % p
		for j in range(i + 1):
			R[j] += y * C[j]
		if i < p - 1:
			C[1:] = ((b - a * i) % p for (a, b) in zip(C[1:], C))
			C[0] = 0
	for i in range(p):
		R[i] %= p
	print(*R)
solve()


class Combi:

	def __init__(self, N, mod):
		self.power = [1 for _ in range(N + 1)]
		self.rev = [1 for _ in range(N + 1)]
		self.mod = mod
		for i in range(2, N + 1):
			self.power[i] = self.power[i - 1] * i % self.mod
		self.rev[N] = pow(self.power[N], self.mod - 2, self.mod)
		for j in range(N, 0, -1):
			self.rev[j - 1] = self.rev[j] * j % self.mod

	def C(self, K, R):
		if K < R:
			return 0
		else:
			return self.power[K] * self.rev[K - R] * self.rev[R] % self.mod

	def P(self, K, R):
		if K < R:
			return 0
		else:
			return self.power[K] * self.rev[K - R] % self.mod
P = int(input())
c = Combi(P - 1, P)
A = list(map(int, input().split()))
power = [1 for i in range(P)]
ans = [0 for i in range(P)]
for i in range(P):
	if A[i] != 0:
		ans[0] += 1
		power[0]
		for _ in range(1, P):
			power[_] = power[_ - 1] * -i % P
		for j in range(P):
			ans[j] -= c.C(P - 1, j) * power[P - 1 - j]
for i in range(P):
	ans[i] %= P
print(*ans)


P = int(input())
A = [int(_) for _ in input().split()]

class Factorial:

	def __init__(self, max_fact, mod):
		f = [1] * (max_fact + 1)
		for idx in range(2, max_fact + 1):
			f[idx] = f[idx - 1] * idx
			f[idx] %= mod
		fi = [pow(f[-1], mod - 2, mod)]
		for idx in range(max_fact, 0, -1):
			fi += [fi[-1] * idx % mod]
		fi = fi[::-1]
		self.mod = mod
		self.f = f
		self.fi = fi

	def factorial(self, n):
		return self.f[n]

	def factorial_inverse(self, n):
		return self.fi[n]

	def combination(self, n, r):
		f = self.f
		fi = self.fi
		return f[n] * fi[r] * fi[n - r] % self.mod

	def permutation(self, n, r):
		return self.f[n] * self.fi[n - r] % self.mod

	def homogeneous_product(self, n, r):
		f = self.f
		fi = self.fi
		return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod
max_fact = P - 1
mod = P
fact_instance = Factorial(max_fact, mod)
comb = fact_instance.combination
perm = fact_instance.permutation
combrep = fact_instance.homogeneous_product
ans = [0] * P
for (i, a) in enumerate(A):
	if a:
		ans[0] += 1
		for r in range(P):
			ans[r] -= comb(P - 1, r) * pow(-i, P - 1 - r, P)
			ans[r] %= mod
print(*ans)


import sys
import math
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7

def I():
	return int(input())

def II():
	return map(int, input().split())

def III():
	return list(map(int, input().split()))

def Line(N):
	read_all = [tuple(map(int, input().split())) for _ in range(N)]
	return map(list, zip(*read_all))

def extgcd(a, b):
	r = [1, 0, a]
	w = [0, 1, b]
	while w[2] != 1:
		q = r[2] // w[2]
		r2 = w
		w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
		r = r2
		w = w2
	return [w[0], w[1]]

def mod_inv(a, M=mod):
	x = extgcd(a, M)[0]
	return (M + x % M) % M

def fact(a, M=mod):
	ans = 1
	for i in range(2, a + 1):
		ans = ans * i
		ans = ans % M
	return ans
p = I()
a = III()
beki = [[1] * p for _ in range(p)]
for i in range(p):
	for j in range(1, p):
		beki[i][j] = beki[i][j - 1] * -i
		beki[i][j] = beki[i][j] % p
fact_inv = [0] * p
for i in range(p):
	fact_inv[i] = mod_inv(fact(i, p), p)
pfact = fact(p - 1, p)
ans = [0] * p
for j in range(p):
	if a[j] == 0:
		continue
	else:
		ans[0] += 1
		for i in range(p):
			ans[i] -= pfact * fact_inv[i] * fact_inv[p - 1 - i] * beki[j][p - 1 - i]
			ans[i] %= p
print(*ans)


import sys
import functools
INF = float('inf')

def solve(p: int, a: 'List[int]'):
	N = p + 1
	MOD = p
	inv = [0] * N
	inv[1] = 1
	for i in range(2, N):
		inv[i] = -inv[MOD % i] * (MOD // i) % MOD
	b = [0] * p
	for (ai, av) in enumerate(a):
		if av == 0:
			continue
		c = 1
		d = 1
		for i in range(p - 1, -1, -1):
			b[i] += -c * d
			b[i] %= p
			c = c * i * inv[p - i] % p
			d = -d * ai % p
		b[0] += 1
		b[0] %= p
	print(*b, sep=' ')
	return

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	p = int(next(tokens))
	a = [int(next(tokens)) for _ in range(p - 1 - 0 + 1)]
	solve(p, a)
main()


import sys

def I():
	return int(sys.stdin.readline().rstrip())

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))
p = I()
a = LI()
C = [1]
for i in range(1, p):
	C.append(C[-1] * (p - i) * pow(i, p - 2, p) % p)
ANS = [a[0]]
for i in range(1, p):
	s = -C[i] % p
	t = sum((a[j] * pow(-j, p - 1 - i, p) for j in range(p))) % p
	ANS.append(s * t % p)
print(*ANS)


p = int(input())
A = list(map(int, input().split()))
comb = [0] * p
comb[0] = 1
for i in range(1, p):
	comb[i] = comb[i - 1] * (p - i) * pow(i, p - 2, p) % p
B = [0] * p
for i in range(p):
	if A[i] == 0:
		continue
	B[0] += 1
	Pow = 1
	for j in range(p):
		B[p - 1 - j] = (B[p - 1 - j] - comb[j] * Pow) % p
		Pow = Pow * -i % p
print(*[b % p for b in B])


p = int(input())
A = tuple(map(int, input().split()))
Fact = [1]
for i in range(1, p):
	Fact.append(Fact[i - 1] * i % p)
Finv = [0] * p
Finv[-1] = pow(Fact[-1], p - 2, p)
for i in range(p - 2, -1, -1):
	Finv[i] = Finv[i + 1] * (i + 1) % p

def comb(n, r):
	if n < r:
		return 0
	return Fact[n] * Finv[r] * Finv[n - r] % p
B = [0] * p
B[0] = sum(A)
for (i, a) in enumerate(A):
	if a:
		k = 1
		for j in reversed(range(p)):
			B[j] += -comb(p - 1, j) * k
			B[j] %= p
			k *= -i
			k %= p
print(*B)


p = int(input())
a_list = list(map(int, input().split()))
r_list = [0] * p
fact = [0] * p
fact[0] = 1
for i in range(1, p):
	fact[i] = fact[i - 1] * i % p
fact_inv = [0] * p
fact_inv[-1] = pow(fact[-1], p - 2, p)
for i in range(p - 2, -1, -1):
	fact_inv[i] = fact_inv[i + 1] * (i + 1) % p
ncr = [fact[p - 1] * fact_inv[p - 1 - i] * fact_inv[i] % p for i in range(p)]
for j in range(p):
	if a_list[j] == 0:
		continue
	k = 1
	for i in range(p - 1, -1, -1):
		r_list[i] -= ncr[i] * k
		r_list[i] %= p
		k *= -j
		k %= p
	r_list[0] += 1
r_list[0] %= p
print(*r_list)


p = int(input())
a = list(map(int, input().split()))
list_size = p - 1
f_list = [1] * list_size
f_r_list = [1] * list_size
for i in range(list_size - 1):
	f_list[i + 1] = int(f_list[i] * (i + 2) % p)
f_r_list[-1] = pow(f_list[-1], p - 2, p)
for i in range(2, list_size + 1):
	f_r_list[-i] = int(f_r_list[-i + 1] * (list_size + 2 - i) % p)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return f_list[n - 1] * f_r_list[n - r - 1] % p * f_r_list[r - 1] % p
pows = [[1] for x in range(p)]
for i in range(p):
	for _ in range(p - 1):
		pows[i].append(pows[i][-1] * i % p)
ans = [0 for _ in range(p)]
for (i, x) in enumerate(a):
	if x == 0:
		continue
	ans[0] += 1
	ans[0] %= p
	for j in range(p):
		ans[j] -= pows[(p - i) % p][p - 1 - j] * comb(p - 1, j)
		ans[j] %= p
print(*ans)


def modinv(x, mod):
	(a, b) = (x, mod)
	(u, v) = (1, 0)
	while b:
		t = a // b
		a -= t * b
		(a, b) = (b, a)
		u -= t * v
		(u, v) = (v, u)
	return u % mod

def Lagrange_interpolation(X, Y, mod):
	n = len(X) - 1
	for i in range(n + 1):
		t = 1
		for j in range(n + 1):
			if i != j:
				t = t * (X[i] - X[j]) % mod
		Y[i] = Y[i] * modinv(t, mod) % mod
	(cur, nxt) = (0, 1)
	dp = [[0] * (n + 2) for _ in range(2)]
	(dp[0][0], dp[0][1]) = (-X[0], 1)
	for i in range(1, n + 1):
		for j in range(n + 2):
			dp[nxt][j] = dp[cur][j] * -X[i] % mod
			if j:
				dp[nxt][j] = (dp[nxt][j] + dp[cur][j - 1]) % mod
		(cur, nxt) = (nxt, cur)
	xinv = [modinv(v, mod) for v in X]
	ret = [0] * (n + 1)
	for i in range(n + 1):
		if Y[i] == 0:
			continue
		if X[i] == 0:
			for j in range(n + 1):
				ret[j] = (ret[j] + dp[cur][j + 1] * Y[i]) % mod
		else:
			ret[0] = (ret[0] - dp[cur][0] * xinv[i] * Y[i]) % mod
			pre = -dp[cur][0] * xinv[i] % mod
			for j in range(1, n + 1):
				ret[j] = (ret[j] - (dp[cur][j] - pre) * xinv[i] * Y[i]) % mod
				pre = (pre - dp[cur][j]) * xinv[i] % mod
	return ret
p = int(input())
a = list(map(int, input().split()))
x = list(range(p))
res = Lagrange_interpolation(x, a, p)
print(*res)


from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10 ** 6)

def SI():
	return input().split()

def MI():
	return map(int, input().split())

def I():
	return int(input())

def LI():
	return [int(i) for i in input().split()]
YN = ['Yes', 'No']
mo = 10 ** 9 + 7
p = I()
a = LI()
mo = float('inf')
mo = p

class polynomial:
	coeff = []

	def __init__(self, ls):
		self.coeff = [i for i in ls]

	def show(self):
		s = ''
		f = self.coeff
		n = len(f)
		for i in range(n):
			if f[n - 1 - i] == 0:
				continue
			s += ('+' if f[n - 1 - i] >= 0 else '') + str(f[n - 1 - i]) + ('x^' + str(n - 1 - i) if i != n - 1 else '')
		print(s[1:])

	def value(self, x):
		x_p = 1
		rt = 0
		for i in self.coeff:
			rt += i * x_p
			x_p *= x
		return rt

	def mod(self):
		self.coeff = [i % mo for i in self.coeff]

	def add(self, poly):
		g = poly.coeff
		n = len(self.coeff)
		m = len(g)
		if n > m:
			g += [0] * (n - m)
		else:
			self.coeff += [0] * (m - n)
		self.coeff = [i + j for (i, j) in zip(self.coeff, g)]
		return self

	def mult(self, poly):
		if type(poly) in (int, float):
			poly = polynomial([poly])
		f = self.coeff
		g = poly.coeff
		n = len(self.coeff)
		m = len(g)
		h = [0] * (n + m - 1)
		for i in range(n):
			for j in range(m):
				h[i + j] += f[i] * g[j]
		self.coeff = h
		return self

	def div(self, poly):
		f = [i for i in self.coeff]
		g = poly.coeff
		n = len(f)
		m = len(g)
		d = []
		if g[-1] == 0:
			return None
		if m > n:
			return (0, f)
		for i in range(n - m + 1):
			c = div(f[n - 1 - i], g[m - 1])
			d += [c]
			for j in range(m):
				f[n - 1 - i - j] -= c * g[m - 1 - j]
		return (polynomial(d[::-1]), polynomial(f[:n - m + 1]))
inv = [0] * p
for i in range(p):
	for j in range(p):
		if i * j % p == 1:
			inv[i] = j
			break

def p_inv(x, p):
	return inv[x]

def div(a, b):
	return a * p_inv(b, p) % p
L = polynomial([0, 1])
for i in range(1, p):
	L.mult(polynomial([-i, 1]))
	L.mod()
S = [L.div(polynomial([i, -1]))[0] for i in range(p)]
A = polynomial([0] * p)
for i in range(p):
	if a[i] == 1:
		A.add(S[i])
print(*[i % mo for i in A.coeff])


def solve():
	p = int(input())
	(*A,) = map(int, input().split())
	L = p - 1
	fact = [1] * (L + 1)
	rfact = [1] * (L + 1)
	r = 1
	for i in range(1, L + 1):
		fact[i] = r = r * i % p
	rfact[L] = r = pow(r, p - 2, p)
	for i in range(L, 0, -1):
		rfact[i - 1] = r = r * i % p
	V = [-fact[p - 1] * rfact[k] * rfact[p - 1 - k] % p for k in range(p)]
	B = [-i for i in range(p)]
	R = [0] * p
	I = [i for (i, a) in enumerate(A) if a]
	C = [a for a in A]
	for k in range(p):
		r = 0
		R[k] = V[k] * sum(C) % p
		for i in I:
			C[i] = C[i] * B[i] % p
	R[-1] += len(I)
	for k in range(p):
		R[k] %= p
	R.reverse()
	print(*R)
solve()


import sys
input = sys.stdin.readline
p = int(input())
A = [int(i) for i in input().split()]
mod = p
B = [0] * p
for i in range(p):
	C = [1] * p
	B[0] = (B[0] - A[i]) % mod
	for j in range(1, p):
		C[j] = C[j - 1] * i % mod
		B[j] = (B[j] - A[i] * C[j]) % mod
		if j == p - 1:
			B[j] = (B[j] + A[i]) % mod
B = B[::-1]
print(*B)


p = int(input())
aaa = list(map(int, input().split()))
coefs = [0] * p
coefs[0] = sum(aaa)
invs = [pow(x, p - 2, p) for x in range(p + 1)]
for (i, a) in enumerate(aaa):
	if a == 0:
		continue
	b = 1
	c = 1
	for j in range(p - 1, -1, -1):
		coefs[j] = (coefs[j] - b * c) % p
		b = -b * i % p
		c = c * j * invs[p - j] % p
print(*coefs)


p = int(input())
A = list(map(int, input().split()))
cmb = [0] * p
cmb[0] = 1
for i in range(1, p):
	cmb[i] = cmb[i - 1] * (p - i) * pow(i, p - 2, p) % p
ans = [0] * p
for i in range(p):
	if A[i] == 1:
		b = 1
		ans[0] = ans[0] + 1
		for j in range(p):
			ans[p - j - 1] = (ans[p - j - 1] - cmb[j] * b) % p
			b = b * -i % p
for i in range(p - 1):
	print(ans[i], end=' ')
print(ans[p - 1])


import sys
stdin = sys.stdin
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()

def inv(a, mod):
	b = mod
	p = 1
	q = 0
	while b > 0:
		c = a // b
		(a, b) = (b, a % b)
		(p, q) = (q, p - c * q)
	return p + mod if p < 0 else p

def guess(mod, y):
	n = len(y)
	dp = [0] * (n + 1)
	dp[0] = 1
	for i in range(n):
		for j in range(i, -1, -1):
			dp[j + 1] += dp[j]
			if dp[j + 1] >= mod:
				dp[j + 1] -= mod
			dp[j] = dp[j] * -i % mod
			if dp[j] < 0:
				dp[j] += mod
	f = [0] * (n + 1)
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % mod
	ret = [0] * n
	for i in range(n):
		den = f[i] * f[n - 1 - i] % mod
		if (i ^ n - 1) & 1 == 1:
			den = mod - den
		iden = inv(den, mod) * y[i] % mod
		minus = 0
		for j in range(n - 1, -1, -1):
			minus = (dp[j + 1] + minus * i) % mod
			ret[j] = (ret[j] + minus * iden) % mod
	return ret
p = ni()
a = na()
f = guess(p, a)
for i in range(p):
	sys.stdout.write(str(f[i]) + ' ')


p = int(input())
a = [int(i) for i in input().split()]
b = [0 for i in range(p)]
c = [0 for i in range(p + 1)]
c[1] = -1
c[-1] = 1

def inv(x):
	return pow(x, p - 2, p)

def divide(k):
	tmp = [c[i] for i in range(p + 1)]
	res = [0 for i in range(p)]
	for i in range(p - 1, -1, -1):
		res[i] = tmp[i + 1]
		tmp[i] += k * tmp[i + 1]
		tmp[i] %= p
	return res
Fact = [0 for i in range(p)]
Finv = [0 for i in range(p)]
Fact[0] = 1
for i in range(p - 1):
	Fact[i + 1] = (i + 1) * Fact[i] % p
Finv[p - 1] = inv(Fact[p - 1])
for i in range(p - 1)[::-1]:
	Finv[i] = (i + 1) * Finv[i + 1] % p
ans = [0 for i in range(p)]
for i in range(p):
	fix = divide(i)
	fixiinv = Finv[i] * Finv[p - i - 1] % p
	fixiinv *= (-1) ** (p - i - 1)
	fixiinv %= p
	for j in range(p):
		ans[j] += a[i] * fix[j] % p * fixiinv % p
		ans[j] %= p
print(*ans)


import sys
sys.setrecursionlimit(2147483647)
INF = float('inf')
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()

def resolve():
	p = int(input())
	invfact = [0] * p
	invfact[p - 1] = p - 1
	for i in range(2, p):
		invfact[p - i] = invfact[p - i + 1] * (p - i + 1) % p
	A = list(map(int, input().split()))
	ans = [0] * p
	ans[0] = A[0]
	r = [0] * (p + 1)
	r[0] = 1
	for k in range(1, p):
		newr = [0] * (p + 1)
		v = 0
		power = 1
		for i in range(p):
			v += ans[i] * power % p
			power *= k
			power %= p
			newr[i] = (r[i - 1] - (k - 1) * r[i]) % p
		r = newr
		for i in range(p):
			ans[i] += (A[k] - v) * invfact[k] * r[i]
			ans[i] %= p
	print(*ans)
resolve()


p = int(input())
alist = list(map(int, input().split()))
fact_list = [1]
fact_inv_list = [1]
for i in range(1, p):
	fact = fact_list[-1] * i % p
	fact_list.append(fact)
	fact_inv_list.append(pow(fact, p - 2, p))

def comb_mod(n, r):
	return fact_list[n] * fact_inv_list[r] * fact_inv_list[n - r]
answer_list = [0] * p
for i in range(p):
	a = alist[i]
	if a == 1:
		coeff_list = [0] * p
		coeff_list[0] = 1
		for j in range(p):
			coeff_list[j] -= comb_mod(p - 1, j) * pow(-i, p - 1 - j, p)
		for i in range(p):
			answer_list[i] += coeff_list[i]
for i in range(p):
	answer_list[i] %= p
print(*answer_list)


p = int(input())
A = [int(x) for x in input().split()]

def modinv(a, m):
	b = m
	u = 1
	v = 0
	while b:
		t = a // b
		a -= t * b
		(a, b) = (b, a)
		u -= t * v
		(u, v) = (v, u)
	u %= m
	if u < 0:
		u += m
	return u
inv_factorial = [1]
prod = 1
for i in range(1, p):
	prod *= i
	prod %= p
	inv_factorial.append(modinv(prod, p))
comb = []
for i in range(p):
	l = i
	r = p - 1 - i
	comb.append(-1 * inv_factorial[l] * inv_factorial[r] % p)
ret = [0] * p
for i in range(p):
	if A[i] == 0:
		continue
	ret[0] += 1
	temp = 1
	for j in range(p):
		ind = p - j - 1
		if j > 0:
			temp *= -i
			temp %= p
		ret[ind] -= comb[ind] * temp
		ret[ind] %= p
print(*ret)


import sys
sys.setrecursionlimit(10 ** 7)
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right
from collections import deque, defaultdict
from collections import Counter
from itertools import accumulate, combinations, permutations, product
from heapq import heapify, heappop, heappush
from functools import reduce, lru_cache
from decimal import Decimal

def input():
	x = sys.stdin.readline()
	return x[:-1] if x[-1] == '\n' else x

def printe(*x):
	print('## ', *x, file=sys.stderr)

def printl(li):
	_ = print(*li, sep='\n') if li else None

def argsort(s, return_sorted=False):
	inds = sorted(range(len(s)), key=lambda k: s[k])
	if return_sorted:
		return (inds, [s[i] for i in inds])
	return inds

def alp2num(c, cap=False):
	return ord(c) - 97 if not cap else ord(c) - 65

def num2alp(i, cap=False):
	return chr(i + 97) if not cap else chr(i + 65)

def matmat(A, B):
	(K, N, M) = (len(B), len(A), len(B[0]))
	return [[sum([A[i][k] * B[k][j] for k in range(K)]) for j in range(M)] for i in range(N)]

def matvec(M, v):
	(N, size) = (len(v), len(M))
	return [sum([M[i][j] * v[j] for j in range(N)]) for i in range(size)]

def T(M):
	(n, m) = (len(M), len(M[0]))
	return [[M[j][i] for j in range(n)] for i in range(m)]

def binr(x):
	return bin(x)[2:]

def bitcount(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x += x >> 8
	x += x >> 16
	x += x >> 32
	return x & 127

def main():
	p = int(input())
	A = tuple(map(int, input().split()))
	mod = p
	maxn = p
	fact = [1] * (maxn + 1)
	invs = [1] * (maxn + 1)
	invs[0] = 0
	ifact = [1] * (maxn + 1)
	for i in range(2, maxn + 1):
		fact[i] = fact[i - 1] * i % mod
		invs[i] = invs[mod % i] * -(mod // i) % mod
		ifact[i] = ifact[i - 1] * invs[i] % mod

	def perm(n, r):
		return fact[n] * ifact[n - r] % mod

	def comb(n, r):
		return fact[n] * ifact[r] % mod * ifact[n - r] % mod

	def multicomb(self, n, *rs):
		ans = fact[n]
		for r in rs:
			ans = ans * self.ifact[r] % self.mod
		return ans
	tot = [0] * p
	tot[0] = sum(A) % mod
	for i in range(p):
		a = A[i]
		if not a:
			continue
		mi = -i % mod
		base = pow(mi, p - 1, mod)
		for j in range(p):
			if j == p - 1:
				base = 1
			tot[j] -= base * comb(p - 1, j) % mod
			tot[j] %= mod
			base *= invs[mi]
			base %= mod
	print(*tot)
main()


p = int(input())
a = list(map(int, input().split()))
mod = p
rng = 10100
fctr = [1]
finv = [1]
for i in range(1, rng):
	fctr.append(fctr[-1] * i % mod)
for i in range(1, rng):
	finv.append(pow(fctr[i], mod - 2, mod))

def inv(x):
	return pow(x, mod - 2, mod)

def cmb(n, k):
	if n < 0 or k < 0:
		return 0
	else:
		return fctr[n] * finv[n - k] * finv[k] % mod
ans = [0] * p
for i in range(p):
	if a[i]:
		ans[0] += 1
		const = 1
		for j in range(p):
			ans[-j - 1] -= (-1) ** (j % 2) * cmb(p - 1, j) * const
			ans[-j - 1] %= mod
			const *= i
			const %= mod
print(*ans)


p = int(input())
A = list(map(int, input().split()))
B = [0] * p
INV = [None] * p
for i in range(1, p):
	INV[i] = pow(i, p - 2, p)
Combi = [None] * p
Combi[0] = 1
for i in range(1, p):
	Combi[i] = Combi[i - 1] * (p - i) * INV[i] % p
for i in range(p):
	if A[i] == 0:
		continue
	B[0] += 1
	POW = 1
	for j in range(p):
		B[p - 1 - j] = (B[p - 1 - j] - Combi[j] * POW) % p
		POW = POW * -i % p
print(*[b % p for b in B])


import sys
input = sys.stdin.readline
p = int(input())
a = [int(i) for i in input().split()]
ans = [0] * p
for (i, j) in enumerate(a):
	if j == 0:
		continue
	ans[0] -= p - 1
	m = 1
	for k in range(p):
		ans[p - 1 - k] -= m
		ans[p - 1 - k] %= p
		m *= i
		m %= p
print(*ans)


p = int(input())
a = [int(item) for item in input().split()]
fac = [1] + [0] * (p - 1)
facinv = [1] + [0] * (p - 1)
for i in range(1, p):
	fac[i] = fac[i - 1] * i % p
	facinv[i] = facinv[i - 1] * pow(i, p - 2, p) % p
comb = [0] * p
for i in range(p):
	comb[i] = fac[p - 1] * facinv[i] * facinv[p - 1 - i] % p
ans = [0] * p
ppowp = [[0] * (p + 1) for _ in range(p + 1)]
for i in range(p + 1):
	val = 1
	for j in range(p + 1):
		ppowp[i][j] = val
		val *= i
		val %= p
for (i, item) in enumerate(a):
	if item == 1:
		ans[0] += 1
		for j in range(p):
			if j % 2 == 1:
				ans[j] -= ppowp[i][p - 1 - j] * -1 * comb[j] % p
			else:
				ans[j] -= ppowp[i][p - 1 - j] * comb[j] % p
			ans[j] %= p
print(' '.join([str(item) for item in ans]))


p = int(input())
a = [int(i) for i in input().split()]
ans = [0] * p
for (i, j) in enumerate(a):
	if j == 0:
		continue
	ans[0] -= p - 1
	m = 1
	for k in range(p):
		ans[p - 1 - k] -= m
		ans[p - 1 - k] %= p
		m *= i
		m %= p
print(*ans)


p = int(input())
fact = [0] * p
inv = [0] * p

def f(x, m=p - 2):
	ans = 1
	while m:
		if m & 1:
			ans = ans * x % p
		x = x * x % p
		m >>= 1
	return ans
fact[0] = inv[0] = 1
for i in range(1, p):
	fact[i] = fact[i - 1] * i % p
	inv[i] = inv[i - 1] * f(i) % p
r = list(map(int, input().split()))
c = [i for i in range(p) if r[i] == 1]
coeff = [0] * p
for j in c:
	for i in range(p - 1, -1, -1):
		if i & 1:
			coeff[p - 1 - i] += fact[p - 1] * inv[i] * inv[p - 1 - i] * f(j, i) % p
		else:
			coeff[p - 1 - i] -= fact[p - 1] * inv[i] * inv[p - 1 - i] * f(j, i) % p
	coeff[0] += 1
coeff = [(t % p + p) % p for t in coeff]
print(*coeff)


import sys
sys.setrecursionlimit(2147483647)
INF = float('inf')
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()

def resolve():
	p = int(input())
	r = [0] * (p + 1)
	r[1] = -1
	r[p] = 1
	ans = [0] * p
	for (i, a) in enumerate(map(int, input().split())):
		if not a:
			continue
		u = [0] * (p + 1)
		for k in range(p - 1, -1, -1):
			u[k] = (r[k + 1] + i * u[k + 1]) % p
			ans[k] -= u[k]
			ans[k] %= p
	print(*ans)
resolve()


def poly_divide(f, g):
	n = len(g)
	(a, b) = f
	q = [0] * (n - 1)
	r = 0
	q[-1] = g[-1] * inv[b % p] % p
	for i in range(n - 2)[::-1]:
		q[i] = (g[i + 1] - q[i + 1] * a) * inv[b % p] % p
	r = g[0] - q[0]
	return (q, r)

def poly_product(f, g):
	(n, m) = (len(f), len(g))
	res = [0] * (n + m - 1)
	for i in range(n):
		for j in range(m):
			res[i + j] += g[j] * f[i]
			res[i + j] %= p
	return res

def assign(f, x):
	tmp = 1
	res = 0
	n = len(f)
	for i in range(n):
		res += f[i] * tmp
		tmp *= x
		tmp %= p
		res %= p
	return res

def c_mul(c, f):
	n = len(f)
	for i in range(n):
		f[i] *= c
		f[i] %= p
	return f

def poly_add(f, g):
	n = len(g)
	for i in range(n):
		f[i] += g[i]
		f[i] %= p
	return f
p = int(input())
a = list(map(int, input().split()))
inv = [0] * p
P = [1]
for i in range(p):
	inv[i] = pow(i, p - 2, p)
for i in range(p):
	b = [-i, 1]
	P = poly_product(b, P)
R = [0] * p
for i in range(p):
	b = [-i, 1]
	(Q, _) = poly_divide(b, P)
	v = assign(Q, i)
	Q = c_mul(inv[v % p] * a[i], Q)
	R = poly_add(R, Q)
print(*R)


import sys
input = sys.stdin.readline
p = int(input())
a = list(map(int, input().split()))
MOD = p
P = p
fact = [0] * P
fact[0] = 1
for i in range(1, P):
	fact[i] = fact[i - 1] * i
	fact[i] %= MOD
rfact = [0] * P
rfact[P - 1] = pow(fact[P - 1], MOD - 2, MOD)
for i in range(P - 2, -1, -1):
	rfact[i] = rfact[i + 1] * (i + 1)
	rfact[i] %= MOD

def comb(n, k):
	return fact[n] * rfact[n - k] * rfact[k] % MOD
b = [0] * p
for i in range(p):
	if a[i]:
		b[0] += 1
		b[0] %= MOD
		s = 1
		for j in range(p - 1, -1, -1):
			b[j] -= comb(p - 1, j) * s
			b[j] %= MOD
			s *= -i
			s %= MOD
print(*b)


from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def A():
	(a, b) = LI()
	print(max(a + b, a - b, a * b))
	return

def B():
	(k, x) = LI()
	ans = []
	for i in range(x - k + 1, x + k):
		ans.append(i)
	print(*ans)
	return

def C():

	def f(s):
		res = [0] * m
		for i in s:
			res[alp.index(i)] += 1
		return res
	alp = list('abcdefghijklmnopqrstuvwxyz')
	m = len(alp)
	n = I()
	s = [input() for i in range(n)]
	d = defaultdict(lambda : 0)
	for i in s:
		d[tuple(f(i))] += 1
	ans = 0
	for i in d.values():
		ans += i * (i - 1) // 2
	print(ans)
	return

def D():
	(n, m) = LI()
	g = LIR(n)
	g.sort(key=lambda x: x[0])
	ans = 0
	f = [1] * n
	j = 0
	q = []
	for i in range(m)[::-1]:
		while j < n and m - g[j][0] >= i:
			(a, b) = g[j]
			heappush(q, (-b, a))
			j += 1
		if q:
			(x, a) = heappop(q)
			if i + a <= m:
				ans -= x
	print(ans)
	return

def E():

	def dfs(x, f):
		for (y, w) in v[x]:
			if f[y]:
				if dp[y] < dp[x] + w:
					f[y] = 0
					dp[y] = dp[x] + w
					dfs(y, f)
					f[y] = 1
			elif dp[y] < dp[x] + w:
				dp[y] = float('inf')
				dfs(y, f)
	(n, m, p) = LI()
	v = [[] for i in range(n)]
	for i in range(m):
		(a, b, c) = LI()
		a -= 1
		b -= 1
		v[a].append((b, c - p))
	f = [1] * n
	dp = [-float('inf')] * n
	dp[0] = 0
	f[0] = 0
	dfs(0, f)
	ans = dp[n - 1]
	if ans == float('inf') or ans == -float('inf'):
		print(-1)
	elif ans < 0:
		print(0)
	else:
		print(ans)
	return

def F():

	def comb(a, b):
		return fact[a] * inv[b] * inv[a - b] % p
	p = I()
	a = LI()
	fact = [1]
	for i in range(p - 1):
		fact.append(fact[-1] * (i + 1) % p)
	inv = [1] * p
	inv[p - 1] = pow(fact[p - 1], p - 2, p)
	for i in range(1, p)[::-1]:
		inv[i - 1] = inv[i] * i % p
	b = [0] * p
	for i in range(p):
		ai = a[i]
		if ai:
			b[0] += ai
			k = 1
			for j in range(p):
				c = ai * comb(p - 1, j) * k % p
				k *= i
				if k >= p:
					k %= p
				if j % 2:
					b[p - 1 - j] += c
				else:
					b[p - 1 - j] -= c
				b[p - 1 - j] %= p
	print(*b)
	return
F()


p = int(input())
mod = p

def frac(limit):
	frac = [1] * limit
	for i in range(2, limit):
		frac[i] = i * frac[i - 1] % mod
	fraci = [None] * limit
	fraci[-1] = pow(frac[-1], mod - 2, mod)
	for i in range(-2, -limit - 1, -1):
		fraci[i] = fraci[i + 1] * (limit + i + 1) % mod
	return (frac, fraci)
(frac, fraci) = frac(p)
A = list(map(int, input().split()))
C = [0] * p
for i in range(p):
	a = A[i]
	for j in range(i):
		a = a - C[j] * frac[i] * fraci[i - j]
	C[i] = fraci[i] * a % p
B = [0] * p
t = [0] * p
t[0] = 1
for i in range(p):
	for j in range(p):
		B[j] += t[j] * C[i]
	t2 = ([0] + t)[:-1]
	t2 = [(a - b * i) % p for (a, b) in zip(t2, t)]
	t = t2[:]
B = [b % p for b in B]
print(*B)


def com(com_n, com_r):
	return fac[com_n] * inv[com_r] * inv[com_n - com_r] % md
p = int(input())
a = list(map(int, input().split()))
md = p
n_max = p - 1
fac = [1]
inv = [1] * (n_max + 1)
k_fac_inv = 1
for i in range(1, n_max + 1):
	k_fac_inv = k_fac_inv * i % md
	fac.append(k_fac_inv)
k_fac_inv = pow(k_fac_inv, md - 2, md)
for i in range(n_max, 1, -1):
	inv[i] = k_fac_inv
	k_fac_inv = k_fac_inv * i % md
b = [0] * p
for (ai, ak) in enumerate(a):
	if ak:
		b[0] = (b[0] + 1) % p
		s = 1
		for bi in range(p - 1, -1, -1):
			b[bi] = (b[bi] - s * com(p - 1, bi)) % p
			s = -ai * s % p
print(*b)


p = int(input())

def div(a, b):
	n = len(a)
	m = len(b)
	res = [0] * (n - m + 1)
	tmp = pow(b[-1], p - 2, p)
	for i in range(n - m, -1, -1):
		t = a[i + m - 1] * tmp % p
		res[i] = t
		for j in range(m):
			a[i + j] = (a[i + j] - t * b[j]) % p
	return res
a = list(map(int, input().split()))
ans = [0] * p
f = [0] * (p + 1)
f[0] = 1
for i in range(p):
	for j in range(p, 0, -1):
		f[j] += f[j - 1]
		f[j - 1] = -f[j - 1] * i
		f[j] %= p
for i in range(p):
	if a[i] == 1:
		fm = div(f[:], [-i, 1])
		t = 1
		r = 0
		for v in fm:
			r += v * t
			t = t * i % p
		t = pow(r, p - 2, p)
		for j in range(len(fm)):
			ans[j] += fm[j] * t
for i in range(p):
	ans[i] %= p
print(' '.join(map(str, ans)))


import sys
input = sys.stdin.readline
p = int(input())
A = [int(i) for i in input().split()]
B = [0] * p
P = [[0] * p for _ in range(p)]
for i in range(1, p):
	for j in range(1, p):
		if j == 1:
			P[i][j] = i
		else:
			P[i][j] = P[i][j - 1] * i % p
for i in range(p):
	a = A[i]
	B[0] -= a
	for j in range(1, p):
		B[j] -= a * P[i][j]
		if j == p - 1:
			B[j] += a
B = B[::-1]
for i in range(p):
	B[i] %= p
print(*B)


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10 ** 9))
write = lambda x: sys.stdout.write(x + '\n')
p = int(input())
a = list(map(int, input().split()))
M = p
N = 10 ** 4
g1 = [None] * (N + 1)
g2 = [None] * (N + 1)
inverse = [None] * (N + 1)
g1[0] = g1[1] = g2[0] = g2[1] = 1
(inverse[0], inverse[1]) = [0, 1]
for i in range(2, N + 1):
	g1[i] = g1[i - 1] * i % M
	inverse[i] = -inverse[M % i] * (M // i) % M
	g2[i] = g2[i - 1] * inverse[i] % M

def cmb(n, r, M):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % M
ans = [0] * p
for (i, num) in enumerate(a):
	if num == 0:
		continue
	for j in range(p):
		ans[j] += -cmb(p - 1, j, M) * pow(-i, p - 1 - j, M)
		ans[j] %= M
	ans[0] += 1
for i in range(p):
	ans[i] %= M
write(' '.join(map(str, ans)))


from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.buffer.readline().split()]

def I():
	return int(sys.stdin.buffer.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():

	def lagrange_interpolation(x, y, mod=mod):
		n = len(x) - 1
		dp = [0] * (n + 2)
		dp[0] = x[0]
		dp[1] = 1
		for i in range(n):
			nd = [0] * (n + 2)
			ni = i + 1
			for j in range(n + 2):
				nj = j
				nd[nj] += -x[ni] * dp[j]
				nd[nj] %= mod
				if j <= n:
					nj = j + 1
					nd[nj] += dp[j]
					nd[nj] %= mod
			for j in range(n + 2):
				dp[j] = nd[j]
		f = [0] * (n + 1)
		for i in range(n + 1):
			if y[i] == 0:
				continue
			fi = 1
			for j in range(n + 1):
				if i == j:
					continue
				fi *= x[i] - x[j]
				fi %= mod
			fi = pow(fi, mod - 2, mod)
			p = [0] * (n + 1)
			if x[i] == 0:
				for j in range(n + 1):
					p[j] = dp[j + 1]
			else:
				inv = pow(x[i], mod - 2, mod)
				p[0] = -dp[0] * inv % mod
				for j in range(1, n + 1):
					p[j] = (p[j - 1] - dp[j]) * inv % mod
			for j in range(n + 1):
				f[j] += y[i] * fi * p[j]
				f[j] %= mod
		return f
	p = I()
	a = LI()
	f = lagrange_interpolation(list(range(p)), a, p)
	print(*f)
	return
solve()


def f_polynomal_construction(P, A):

	class Combination(object):
		__slots__ = ['mod', 'factorial', 'inverse']

		def __init__(self, max_n: int=10 ** 6, mod: int=10 ** 9 + 7):
			(fac, inv) = ([1], [])
			(fac_append, inv_append) = (fac.append, inv.append)
			for i in range(1, max_n + 1):
				fac_append(fac[-1] * i % mod)
			inv_append(pow(fac[-1], mod - 2, mod))
			for i in range(max_n, 0, -1):
				inv_append(inv[-1] * i % mod)
			(self.mod, self.factorial, self.inverse) = (mod, fac, inv[::-1])

		def combination(self, n, r):
			if n < 0 or r < 0 or n < r:
				return 0
			return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod
	combination = Combination(P - 1, P)
	comb = [combination.combination(P - 1, i) for i in range(P)]
	ans = [0] * P
	for (j, a) in enumerate(A):
		if a == 0:
			continue
		ans[0] += 1
		tmp = 1
		for k in range(P):
			index = P - k - 1
			if k > 0:
				tmp *= -j
				tmp %= P
			ans[index] -= comb[index] * tmp
			ans[index] %= P
	return ' '.join(map(str, ans))
P = int(input())
A = [int(i) for i in input().split()]
print(f_polynomal_construction(P, A))


import os
import sys
if os.getenv('LOCAL'):
	sys.stdin = open('_in.txt', 'r')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
IINF = 10 ** 18
MOD = 10 ** 9 + 7

def get_factorials(max, mod=None):
	ret = [1]
	n = 1
	if mod:
		for i in range(1, max + 1):
			n *= i
			n %= mod
			ret.append(n)
	else:
		for i in range(1, max + 1):
			n *= i
			ret.append(n)
	return ret

def mod_invs(max, mod):
	invs = [1] * (max + 1)
	for x in range(2, max + 1):
		invs[x] = -(mod // x) * invs[mod % x] % mod
	return invs

def factorial_invs(max, mod):
	ret = []
	r = 1
	for inv in mod_invs(max, mod):
		r = r * inv % mod
		ret.append(r)
	return ret

class Combination:

	def __init__(self, max, mod):
		self._factorials = get_factorials(max, mod)
		self._finvs = factorial_invs(max, mod)
		self._mod = mod

	def ncr(self, n, r):
		if n < r:
			return 0
		return self._factorials[n] * self._finvs[r] % self._mod * self._finvs[n - r] % self._mod
P = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
comb = Combination(max=P - 1, mod=P)
ncr = [comb.ncr(P - 1, i) for i in range(P)]
B = [0] * P
for (j, a) in enumerate(A):
	if a == 0:
		continue
	pw = 1
	for i in range(P):
		B[i] -= pw * ncr[i] % P
		B[i] %= P
		pw = pw * -j % P
	B[-1] += 1
	B[-1] %= P
print(*B[::-1])


P = int(input())
A = list(map(int, input().split()))
Q = [1 for _ in range(P)]
for i in range(P):
	if A[i]:
		for k in range(P):
			if i == k:
				continue
			Q[i] *= i - k
			Q[i] %= P
		Q[i] = pow(Q[i], P - 2, P)
	else:
		Q[i] = 0
F = [0 for _ in range(P + 1)]
F[0] = 1
for i in range(P):
	tmp = [0 for _ in range(P + 1)]
	for j in range(1, P + 1):
		tmp[j] += F[j - 1]
		tmp[j] %= P
	for j in range(P + 1):
		tmp[j] += F[j] * -i
		tmp[j] %= P
	F = tmp
res = [0 for _ in range(P)]
for i in range(P):
	G = [0 for _ in range(P)]
	G[P - 1] = F[P]
	res[P - 1] += Q[i] * G[P - 1]
	res[P - 1] %= P
	for j in range(P - 1)[::-1]:
		G[j] = F[j + 1] + i * G[j + 1]
		G[j] %= P
		res[j] += Q[i] * G[j]
		res[j] %= P
print(*res)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
p = int(input())
a = [int(i) for i in input().split()]
ret = [0] * p
fac = [1]
inv = [1]
for i in range(1, p):
	fac.append(fac[-1] * i % p)
	inv.append(pow(fac[-1], p - 2, p))
for i in range(p):
	if a[i] == 0:
		continue
	ret[0] += 1
	power = 1
	for j in range(p - 1, -1, -1):
		ret[j] += -fac[p - 1] * inv[p - 1 - j] * inv[j] * power % p
		ret[j] %= p
		power *= -i
		power %= p
print(' '.join(map(str, ret)))


p = int(input())
a = list(map(int, input().split()))
ans = [0] * p
for i in range(p):
	if a[i] == 0:
		continue
	ans[0] -= p - 1
	m = 1
	for k in range(p):
		ans[p - 1 - k] -= m
		ans[p - 1 - k] %= p
		m *= i
		m %= p
print(*ans)


P = int(input())
A = [int(a) for a in input().split()]
X = [0] * P
fa = [1]
for i in range(1, P):
	fa.append(fa[-1] * i % P)
fainv = [pow(fa[-1], P - 2, P)]
for i in range(1, P)[::-1]:
	fainv.append(fainv[-1] * i % P)
fainv = fainv[::-1]

def C(i):
	return fa[P - 1] * fainv[i] * fainv[P - 1 - i] % P
for i in range(P):
	if A[i]:
		c = 1
		for j in range(P)[::-1]:
			X[j] = (X[j] - C(j) * c) % P
			c = -c * i % P
		X[0] = (X[0] + 1) % P
print(*X)


p = int(input())
a = list(map(int, input().split()))
b = [0] * p
fact = [1] * (p + 1)
for i in range(p):
	fact[i + 1] = (i + 1) * fact[i]
	fact[i + 1] %= p
factinv = [1] * p
for i in range(p):
	factinv[i] = pow(fact[i], p - 2, p)
powl = [[1] * (p + 1) for _ in range(p + 1)]
for i in range(p + 1):
	for j in range(p):
		powl[i][j + 1] = i * powl[i][j] % p
for i in range(1, p):
	k1 = powl[i][p - 2]
	k2 = powl[p - 1][p - 1 - i]
	if a[i] == 1:
		for j in range(1, p):
			kj = powl[k1][j]
			b[j] += kj * k2 * factinv[i] * factinv[p - 1 - i]
			b[j] %= p
if a[0] == 1:
	b[0] += 1
	b[0] %= p
	b[p - 1] += p - 1
	b[p - 1] %= p
print(*b)


import math
import queue
import bisect
from collections import deque, defaultdict
import heapq as hpq
from sys import stdin, setrecursionlimit
ipt = stdin.readline
setrecursionlimit(10 ** 7)
dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]
alp = 'abcdefghijklmnopqrstuvwxyz'

def main():
	p = int(ipt())
	a = [int(i) for i in ipt().split()]
	mod = p
	N = 3000
	g1 = [1, 1]
	g2 = [1, 1]
	inverse = [0, 1]

	def cmb(n, r, mod=p):
		if r < 0 or r > n:
			return 0
		r = min(r, n - r)
		return g1[n] * g2[r] * g2[n - r] % mod
	for i in range(2, N + 1):
		g1.append(g1[-1] * i % mod)
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g2.append(g2[-1] * inverse[-1] % mod)
	ans = [0] * p
	for i in range(p):
		if a[i]:
			ans[0] += 1
			sgn = -1
			ji = 1
			for j in range(p - 1, -1, -1):
				ans[j] += sgn * ji * cmb(p - 1, j, p)
				ji *= i
				ji %= p
				ans[j] %= p
				sgn *= -1
	print(' '.join(map(str, ans)))
	return None
main()


import numpy as np
mod = 998244353

def poly_mul(f, g):
	Lf = len(f)
	Lg = len(g)
	L = Lf + Lg - 1
	if Lf <= 16 or Lg <= 16:
		if Lf == 0 or Lg == 0:
			return np.zeros((0,), dtype=np.int64)
		return (np.convolve(f.astype(np.uint64), g.astype(np.uint64)) % mod).astype(np.int64)
	fft = np.fft.rfft
	ifft = np.fft.irfft
	fft_len = 1 << L.bit_length()
	fl = f & (1 << 15) - 1
	fh = f >> 15
	gl = g & (1 << 15) - 1
	gh = g >> 15
	x = (ifft(fft(fl, fft_len) * fft(gl, fft_len))[:L] + 0.5).astype(np.int64) % mod
	y = (ifft(fft(fl + fh, fft_len) * fft(gl + gh, fft_len))[:L] + 0.5).astype(np.int64) % mod
	z = (ifft(fft(fh, fft_len) * fft(gh, fft_len))[:L] + 0.5).astype(np.int64) % mod
	return (x + (y - x - z << 15) + (z << 30)) % mod

def poly_inv(fps, n=None):
	assert fps[0] != 0
	if n is None:
		n = len(fps)
	res = np.zeros(1 << (n - 1).bit_length(), dtype=np.int64)
	res[0] = pow(int(fps[0]), mod - 2, mod)
	i = 1
	while i < n:
		i <<= 1
		res[:i] = ((res[:i] << 1) - poly_mul(poly_mul(res[:i >> 1], res[:i >> 1]), fps[:i])[:i]) % mod
	return res[:n]

def poly_div(fps1, fps2):
	(n1, n2) = (len(fps1), len(fps2))
	if n1 < n2:
		return np.zeros((0,), dtype=np.int64)
	n = n1 - n2 + 1
	res = poly_mul(fps1[-1:-n - 1:-1], poly_inv(fps2[::-1], n))[n - 1::-1]
	return res

def poly_mod(fps1, fps2):
	(n1, n2) = (len(fps1), len(fps2))
	if n1 < n2:
		return fps1
	res = fps1[:n2 - 1] - poly_mul(poly_div(fps1, fps2), fps2)[:n2 - 1]
	return res % mod

def multipoint_evaluation(fps, xs):
	threshold = 8
	n_xs = len(xs)
	bit = (n_xs - 1).bit_length()
	if bit <= threshold:
		res = np.zeros_like(xs)
		xs_cumprod = np.ones_like(xs)
		for coef in fps:
			res += xs_cumprod * coef
			xs_cumprod *= xs
			xs_cumprod %= mod
		return res
	k = 1 << bit
	fpss = np.zeros((bit + 1, k + 1), dtype=fps.dtype)
	fpss[0, :n_xs] = -xs % mod
	fpss[1, :k:2] = fpss[0, :k:2] * fpss[0, 1::2] % mod
	fpss[1, 1::2] = (fpss[0, :k:2] + fpss[0, 1::2]) % mod
	for i in range(1, bit):
		step = 2 << i
		half = step >> 1
		for j in range(0, k, step):
			f1 = fpss[i, j:j + half + 1].copy()
			f2 = fpss[i, j + half:j + step + 1].copy()
			f1[-1] = f2[-1] = 1
			f = poly_mul(f1, f2)
			fpss[i + 1, j:j + step] = f[:-1]
	f = poly_mod(fps, f)
	fpss[-1, :len(f)] = f
	fpss[-1, len(f):] = 0
	for i in range(bit - 1, threshold - 1, -1):
		step = 2 << i
		half = step >> 1
		for j in range(0, k, step):
			f = fpss[i + 1, j:j + step]
			f1 = fpss[i, j:j + half + 1].copy()
			f2 = fpss[i, j + half:j + step + 1].copy()
			f1[-1] = f2[-1] = 1
			fpss[i, j:j + half] = poly_mod(f, f1)
			fpss[i, j + half:j + step] = poly_mod(f, f2)
	xs = (-fpss[0, :k] % mod).reshape(-1, 1 << threshold)
	xs_cumprod = np.ones_like(xs)
	res = np.zeros_like(xs)
	for i in range(1 << threshold):
		res += fpss[threshold, i:k:1 << threshold, None] * xs_cumprod % mod
		xs_cumprod *= xs
		xs_cumprod %= mod
	return res.reshape(-1)[:n_xs] % mod

def poly_differential(fps):
	return fps[1:] * np.arange(1, len(fps)) % mod

def lagrange_interpolation(X, Y, mod):
	n = len(X)
	g = [0] * (n + 1)
	g[0] = 1
	for (i, x) in enumerate(X):
		for j in range(i, -1, -1):
			g[j + 1] += g[j] * -x % mod
	res = [0] * n
	for (x, y) in zip(X, Y):
		f = g[:]
		denom = 0
		v = 1
		pow_x = [1]
		for _ in range(n - 1):
			v = v * x % mod
			pow_x.append(v)
		pow_x.reverse()
		for (i, po) in enumerate(pow_x):
			f_i = f[i]
			f[i + 1] += f_i * x % mod
			denom = (denom + f_i * po) % mod
		denom_inv = pow(denom, mod - 2, mod)
		for (i, f_i) in enumerate(f[:n]):
			res[i] += f_i * y * denom_inv
	return [v % mod for v in res]

def polynomial_interpolation(xs, ys):
	assert len(xs) == len(ys)
	threshold = 8
	as_strided = np.lib.stride_tricks.as_strided
	n = len(xs)
	if n == 1:
		return ys.copy()
	bit = (n - 1).bit_length()
	if bit <= threshold:
		res = lagrange_interpolation(xs.tolist(), ys.tolist(), mod)
		return np.array(res[::-1], dtype=np.int64)
	k = 1 << bit
	fpss = np.zeros((bit + 1, n + 1), dtype=np.int64)
	fpss[0, :n] = -xs % mod
	for i in range(bit):
		step = 2 << i
		half = step >> 1
		for j in range(0, n, step):
			if j + half >= n:
				fpss[i + 1, j:n] = fpss[i, j:n]
				continue
			f1 = fpss[i, j:j + half + 1].copy()
			f2 = fpss[i, j + half:j + step + 1].copy()
			f1[-1] = f2[-1] = 1
			f = poly_mul(f1, f2)
			fpss[i + 1, j:j + len(f) - 1] = f[:-1]
	fpss2 = np.zeros((bit + 1, k + 1), dtype=np.int64)
	fpss2[bit, :n] = poly_differential(f)
	for i in range(bit - 1, threshold - 1, -1):
		step = 2 << i
		half = step >> 1
		for j in range(0, n, step):
			if j + half >= n:
				fpss2[i, j:n] = fpss2[i + 1, j:n]
				continue
			f = fpss2[i + 1, j:min(j + step, n)]
			f1 = fpss[i, j:j + half + 1].copy()
			f2 = fpss[i, j + half:min(j + step, n) + 1].copy()
			f1[-1] = f2[-1] = 1
			fpss2[i, j:j + half] = poly_mod(f, f1)
			fpss2[i, j + half:min(j + step, n)] = poly_mod(f, f2)
	xs = as_strided(xs, (k >> threshold, 1 << threshold), (8 << threshold, 8))
	xs_cumprod = np.ones_like(xs)
	f = np.zeros_like(xs)
	for i in range(1 << threshold):
		f += fpss2[threshold, i:k:1 << threshold, None] * xs_cumprod % mod
		xs_cumprod *= xs
		xs_cumprod %= mod
	f = f.ravel()
	for j in range(n):
		fpss2[0, j] = ys[j] * pow(int(f[j]), mod - 2, mod) % mod
	for i in range(bit):
		step = 2 << i
		half = step >> 1
		for j in range(0, k, step):
			if j + half >= n:
				fpss2[i + 1, j:n] = fpss2[i, j:n]
				continue
			f1 = fpss[i, j:j + half + 1].copy()
			f2 = fpss[i, j + half:j + step + 1].copy()
			f1[-1] = f2[-1] = 1
			fpss2[i + 1, j:min(j + step, n)] = (poly_mul(fpss2[i, j:j + half], f2) + poly_mul(fpss2[i, j + half:min(j + step, n)], f1)) % mod
	return fpss2[bit, :n]
mod = int(input())
A = np.array(input().split(), dtype=np.int64)
X = np.arange(mod, dtype=np.int64)
Ans = polynomial_interpolation(X, A)
print(' '.join(map(str, Ans.tolist())))


p = int(input())
a = list(map(int, input().split()))
lis = [0] * (p + 1)
for i in range(p):
	if i == 0:
		lis[1] = 1
		lis[0] = 0
	else:
		nlis = [0] * (p + 1)
		for j in range(p + 1):
			nlis[j] += lis[j] * (-1 * i)
			if j != 0:
				nlis[j] += lis[j - 1]
			nlis[j] %= p
		lis = nlis
ans = [0] * p
for i in range(p):
	if a[i] == 0:
		continue
	nlis = [0] * p
	for j in range(p - 1, -1, -1):
		if j == p - 1:
			nlis[j] = lis[j + 1]
		else:
			nlis[j] = (lis[j + 1] - nlis[j + 1] * (-1 * i)) % p
	for j in range(p):
		ans[j] += nlis[j]
for i in range(p):
	ans[i] = (p - ans[i]) % p
print(' '.join(map(str, ans)))


import sys
P = int(input())
As = list(map(int, input().split()))
rs = [0] * P
mod = P
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
	if y == 0:
		return 1
	elif y == 1:
		return x % mod
	elif y % 2 == 0:
		return power(x, y // 2) ** 2 % mod
	else:
		return power(x, (y - 1) // 2) ** 2 * x % mod

def mul(a, b):
	return a % mod * (b % mod) % mod

def div(a, b):
	return mul(a, power(b, mod - 2))

def cmb(n, r):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod
NNN = 3000
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, NNN + 1):
	g1.append(g1[-1] * i % mod)
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
	g2.append(g2[-1] * inverse[-1] % mod)
C = []
for i in range(P):
	C.append(cmb(P - 1, i))
for i in range(P):
	if As[i]:
		rs[0] += 1
		tmp = 1
		for k in range(P):
			k = P - 1 - k
			rs[k] += (-1 + 2 * (k % 2)) * tmp * C[k]
			rs[k] %= mod
			tmp = tmp * i % mod
print(*rs)


import sys
input = sys.stdin.readline
p = int(input())
A = [int(i) for i in input().split()]
B = [0] * p
for i in range(p):
	(a, c) = (A[i], 1)
	B[0] -= a
	for j in range(1, p):
		c = c * i % p
		B[j] -= a * c
		if j == p - 1:
			B[j] += a
B = B[::-1]
for i in range(p):
	B[i] = B[i] % p
print(*B)


p = int(input())
a = list(map(int, input().split()))
L = [0] * (p + 1)
L[1] = 1
for n in range(1, p):
	for m in range(n + 1, 0, -1):
		L[m] = (L[m - 1] - n * L[m]) % p
fact = [1] * p
for n in range(1, p):
	fact[n] = n * fact[n - 1] % p
factinv = [pow(m, p - 2, p) for m in fact]

def Ln(n):
	res = [0] * p
	res[p - 1] = 1
	for m in range(p - 2, -1, -1):
		res[m] = (n * res[m + 1] + L[m + 1]) % p
	res = [(1 - 2 * ((p - 1 - n) % 2)) * factinv[n] * factinv[p - 1 - n] * c % p for c in res]
	return res
ans = [0] * p
for n in range(p):
	if a[n] == 0:
		continue
	l = Ln(n)
	for m in range(p):
		ans[m] += l[m]
		ans[m] %= p
print(' '.join((str(c) for c in ans)))


def main():
	import sys
	input = sys.stdin.readline
	p = int(input())
	A = list(map(int, input().split()))
	ans = [0] * p
	for (i, a) in enumerate(A):
		if not a:
			continue
		ans[-1] += 1
		ij = 1
		ans[0] = (ans[0] - ij) % p
		for j in range(1, p):
			ij = ij * i % p
			ans[j] = (ans[j] - ij) % p
	ans.reverse()
	print(*ans)
main()


import sys
input = sys.stdin.readline

def main():
	P = int(input())
	A = list(map(int, input().split()))
	mod = P

	def cmb(n, r, mod=mod):
		if r < 0 or r > n:
			return 0
		r = min(r, n - r)
		return g1[n] * g2[r] * g2[n - r] % mod
	NN = 10 ** 5
	g1 = [1, 1]
	g2 = [1, 1]
	inverse = [0, 1]
	for i in range(2, NN + 1):
		g1.append(g1[-1] * i % mod)
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g2.append(g2[-1] * inverse[-1] % mod)
	ans = [0] * P
	for (j, a) in enumerate(A):
		if a == 1:
			ans[0] = (ans[0] + 1) % P
			t = 1
			for k in range(P):
				ans[P - 1 - k] = (ans[P - 1 - k] - cmb(P - 1, k) * t) % P
				t = t * -j % P
	print(*ans)
main()


import os
import sys
if os.getenv('LOCAL'):
	sys.stdin = open('_in.txt', 'r')
sys.setrecursionlimit(2147483647)
INF = float('inf')
IINF = 10 ** 18
MOD = 10 ** 9 + 7
P = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

def mod_invs(max, mod):
	invs = [1] * (max + 1)
	for x in range(2, max + 1):
		invs[x] = -(mod // x) * invs[mod % x] % mod
	return invs

def get_ncrs(n, mod):
	invs = mod_invs(n, mod)
	ret = [1]
	ncr = 1
	for i in range(1, n + 1):
		ncr = ncr * (n - i + 1) % mod * invs[i] % mod
		ret.append(ncr)
	return ret
ncr = get_ncrs(P - 1, P)

def poly(j):
	coef = []
	c = 1
	for i in range(P):
		coef.append(-ncr[i] * c)
		c = c * -j % P
	coef.reverse()
	coef[0] += 1
	return coef
ans = [0] * P
for (j, a) in enumerate(A):
	if a == 1:
		for (k, b) in enumerate(poly(j)):
			ans[k] += b
			ans[k] %= P
print(*ans)


def lagrange_interpolation(X, Y, mod):
	n = len(X)
	g = [0] * (n + 1)
	g[0] = 1
	for (i, x) in enumerate(X):
		for j in range(i, -1, -1):
			g[j + 1] += g[j] * -x % mod
	res = [0] * n
	for (x, y) in zip(X, Y):
		f = g[:]
		denom = 0
		v = 1
		pow_x = [1]
		for _ in range(n - 1):
			v = v * x % mod
			pow_x.append(v)
		pow_x.reverse()
		for (i, po) in enumerate(pow_x):
			f_i = f[i]
			f[i + 1] += f_i * x % mod
			denom = denom + f_i * po
		denom_inv = pow(denom, mod - 2, mod)
		for (i, f_i) in enumerate(f[:n]):
			res[i] += f_i * y * denom_inv
	return [v % mod for v in res]
p = int(input())
A = list(map(int, input().split()))
ans = lagrange_interpolation(list(range(p)), A, p)
print(' '.join(map(str, ans[::-1])))


import sys
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
p = int(input())
coeff = [int(i) for i in readline().split()]

def div(t, i):
	res = []
	while len(t) > 1:
		c = t.pop()
		t[-1] += c * i
		t[-1] %= p
		res.append(c)
	return res
ans = [0] * p
for i in range(p):
	res = div([0] + [-1] + [0] * (p - 2) + [1], i)
	for (j, c) in enumerate(res):
		ans[-j - 1] += c * -coeff[i]
for i in range(p):
	ans[i] %= p
print(*ans)


p = int(input())
a = list(map(int, input().split()))
MOD = p
MAX = p + 10
fact = [1] * (MAX + 1)
finv = [1] * (MAX + 1)
iinv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
	fact[i] = fact[i - 1] * i % MOD
	iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i - 1] * iinv[i] % MOD

def comb(n: int, k: int) -> int:
	if n < k or n < 0 or k < 0:
		return 0
	return fact[n] * finv[k] % MOD * finv[n - k] % MOD
b = [0] * p
for j in range(p):
	if a[j] == 1:
		b[0] += 1
		for k in range(p):
			b[k] += comb(p - 1, k) * pow(j, p - 1 - k, MOD) * (-1) ** ((p - k) % 2)
			b[k] %= MOD
print(*b)


def getInv(N, Q):
	inv = [0] * (N + 1)
	inv[1] = 1
	for i in range(2, N + 1):
		inv[i] = -(Q // i) * inv[Q % i] % Q
	return inv

def getCmb(N, Q):
	inv = getInv(N, Q)
	nCr = [1] * (N + 1)
	for i in range(1, N + 1):
		nCr[i] = nCr[i - 1] * (N - i + 1) * inv[i] % Q
	return nCr

def main():
	p = int(input())
	A = list(map(int, input().split()))
	ANS = [A[0]]
	pm1Ck = getCmb(p - 1, p)
	Pow = [[0] * p for _ in range(p + 1)]
	for i in range(p + 1):
		Pow[i][0] = 1
	for i in range(1, p):
		for k in range(p - 1):
			Pow[i][k + 1] = Pow[i][k] * i % p
	for k in range(1, p):
		now = 0
		for i in range(p):
			now -= A[i] * Pow[p - i][p - 1 - k] * pm1Ck[k]
			now %= p
		ANS.append(now)
	print(' '.join(map(str, ANS)))
main()


p = int(input())
a = list(map(int, input().split()))
ans = [0 for _ in range(p)]
chs = [1]
deno = 1
nume = 1
for i in range(1, p):
	nume *= p - i
	deno *= pow(i, p - 2, p)
	chs.append(nume * deno % p)
for i in range(p):
	tmp = 1
	if not a[i]:
		continue
	for j in range(p):
		ans[p - 1 - j] -= chs[p - 1 - j] * tmp
		tmp *= p - i
		tmp %= p
	ans[0] += 1
for i in range(p):
	ans[i] %= p
print(*ans)


class Combination:

	def __init__(self, n, MOD):
		self.fact = [1]
		for i in range(1, n + 1):
			self.fact.append(self.fact[-1] * i % MOD)
		self.inv_fact = [0] * (n + 1)
		self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
		for i in reversed(range(n)):
			self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
		self.MOD = MOD

	def inverse(self, k):
		return self.inv_fact[k] * self.fact[k - 1] % self.MOD

	def factorial(self, k):
		return self.fact[k]

	def inverse_factorial(self, k):
		return self.inv_fact[k]

	def permutation(self, k, r):
		if k < r:
			return 0
		return self.fact[k] * self.inv_fact[k - r] % self.MOD

	def combination(self, k, r):
		if k < r:
			return 0
		return self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r] % self.MOD

	def combination2(self, k, r):
		if k < r:
			return 0
		res = 1
		for l in range(r):
			res *= k - l
			res %= self.MOD
		return res * self.inv_fact[r] % self.MOD
p = int(input())
a = list(map(int, input().split()))
comb = Combination(p - 1, p)
b = [0] * p
for i in range(p):
	for j in range(p):
		tmp = pow(-j, p - 1 - i, p) * comb.combination(p - 1, i)
		b[i] -= a[j] * tmp
		b[i] %= p
b[0] = a[0]
print(*b)