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

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)


if __name__ == '__main__':
    main()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
import numpy as np

p = int(input())
aaa = list(map(int, input().split()))

bins = [1]
for i in range(1, p):
    bins.append(bins[-1] * (p - i) * pow(i, p - 2, p) % p)
bins = np.array(bins, dtype=np.int32)

pows_base = -np.arange(p, dtype=np.int32)
pows = np.zeros((p, p), dtype=np.int32)
pows[:, p - 1] = 1
for i in range(p - 2, -1, -1):
    pows[:, i] = pows[:, i + 1] * pows_base % p

coefs = np.zeros(p, dtype=np.int32)

for i, a in enumerate(aaa):
    if a == 0:
        continue

    coefs[0] += 1
    coefs = (coefs - bins * pows[i]) % p

print(*coefs)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from numpy.fft import rfft, irfft
import itertools

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

fft_len = 6144
def fft_convolve(A,B):
    C = irfft(rfft(A,fft_len) * rfft(B,fft_len))
    C = (C + .5).astype(np.int64)
    C[:P] += C[P:P+P]
    return C[:P] % P
  
one = np.array([1], dtype=np.int64)
arr = [np.array([(-x)%P,1],dtype=np.int64) for x in range(P)]
L = [one] + list(itertools.accumulate(arr[:-1],lambda a,b: np.convolve(a,b) % P))
R = ([one] + list(itertools.accumulate(arr[1:][::-1],lambda a,b: np.convolve(a,b) % P)))[::-1]
X = [fft_convolve(A,B) % P for A,B in zip(L,R)]

f = np.zeros(P,dtype=np.int64)
for a,x in zip(A,X):
    if a == 1:
        f -= x

f %= P
print(*f)

Solution (Python):

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
            else:
                if 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


if __name__ == "__main__":
    F()

Solution (Python):
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]))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):


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)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
import itertools

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


power = np.ones((P,P),dtype = np.int64)
for k in range(1,P):
    power[k] = power[k-1] * np.arange(P,dtype=np.int64) % P

f = np.zeros(P,dtype=np.int64)
for i,a in enumerate(A):
    if a == 1:
        f[0] += 1
        f -= power[:,i][::-1]
f %= P

f %= P
print(*f)

Solution (Python):
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]) + " ")