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

Difficulty: MEDIUM_HARD

Solutions:
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()


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()


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
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 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 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())))


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()