CodeEff/ECCO huggingface dataset:
# Original solution
import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

N,K = LI()
A = LI()

sa = list(itertools.accumulate([0]+A))
b = []
for i in range(N):
    for j in range(i+1,N+1):
        b.append(sa[j]-sa[i])
b.sort(reverse=True)
max_b = (max(b)).bit_length()

mask = 0
for i in range(max_b-1,-1,-1):
    bit = 2**i
    cnt = 0
    for x in b:
        if x & mask == mask:
            cnt += (x & bit > 0)
    if cnt >= K:
        mask += bit

print (mask)




# Optimized solution
import sys,queue,math,copy,itertools,bisect,collections,heapq
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

N,K = LI()
A = LI()

sa = list(itertools.accumulate([0]+A))
b = []
for i in range(N):
    for j in range(i+1,N+1):
        b.append(sa[j]-sa[i])
#b.sort(reverse=True)
max_b = max(b).bit_length()

mask = 0
for i in range(max_b-1,-1,-1):
    bit = 2**i
    cnt = 0
    for x in b:
        if x & mask == mask:
            cnt += (x & bit > 0)
    if cnt >= K:
        mask += bit
print (mask)
# Original solution
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
cums = [0]
for a in A:
    cums.append(cums[-1] + a)

vs = []
for l in range(N):
    for r in range(l+1,N+1):
        vs.append(cums[r] - cums[l])
vs.sort(reverse=True)

for i in range(100,-1,-1):
    tmps = []
    for v in vs:
        if v&(1<<i):
            tmps.append(v)
    if len(tmps) >= K:
        vs = tmps

if len(vs) < K:
    print((0))
else:
    ans = vs[0]
    for v in vs[1:K]:
        ans &= v
    print(ans)

# Optimized solution
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = []
for i,a in enumerate(A):
    k = 0
    for c in A[i:]:
        k += c
        B.append(k)

ans = 0
for i in range(40,-1,-1):
    C = []
    for b in B:
        if b&(1<<i):
            C.append(b)
    if len(C) >= K:
        B = C
        ans += 2**i
print(ans)
# Original solution
from itertools import accumulate, combinations

def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    sum_A = sum(A)
    B = [0] + list(accumulate(A))
    cand = []
    for i in range(N+1):
        for j in range(i+1,N+1):
            cand.append(B[j] - B[i])
    cand.sort(reverse=True)
    length = len(bin(cand[K-1])[2:])
    num = []
    for c in cand:
        if len(bin(c)[2:]) < length:
            break
        num.append(c)

    ans = 0
    for item in combinations(num,K):
        n = 0
        for i in range(len(item)):
            if i == 0:
                n = item[i]
            n &= item[i]
        ans = max(ans, n)

    print(ans)




if __name__ == "__main__":
    main()

# Optimized solution
from itertools import accumulate

def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    sum_A = sum(A)
    B = [0] + list(accumulate(A))
    cand = []
    for i in range(N+1):
        for j in range(i+1,N+1):
            cand.append(B[j] - B[i])
    ans = 0
    for i in range(40):
        bit = 1 << (39 - i)
        cnt = 0
        new_cand = []
        for c in cand:
            if c & bit:
                cnt += 1
                new_cand.append(c)

        if cnt >= K:
            ans += 2 ** (39 - i)
            cand = new_cand


    print(ans)




if __name__ == "__main__":
    main()
# Original solution
import itertools

nk = input().split()
seisuuretu = input().split()

for i in range(len(seisuuretu)):
    seisuuretu[i] = int(seisuuretu[i])

all_seisuuretu = []

for start in range(len(seisuuretu) + 1):
    for end in range(len(seisuuretu) + 1):
        if start < end:
            all_seisuuretu.append(seisuuretu[start:end])

beautiful_list = []

for pattern in all_seisuuretu:
    beautiful_list.append(sum(pattern))

select_index = []

for index in itertools.permutations(list(range(len(beautiful_list))), r=int(nk[1])):
    select_index.append(index)

result = []

for temp_index in select_index:
    count = 0
    for one_index in temp_index:
        if count == 0:
            temp_and = beautiful_list[one_index]
        else:
            temp_and = temp_and & beautiful_list[one_index]
        count += 1
    result.append(temp_and)

print((max(result)))


# Optimized solution
nk = input().split()
seisuuretu = input().split()

for i in range(len(seisuuretu)):
    seisuuretu[i] = int(seisuuretu[i])

all_seisuuretu = []

for start in range(len(seisuuretu) + 1):
    for end in range(len(seisuuretu) + 1):
        if start < end:
            all_seisuuretu.append(seisuuretu[start:end])

beautiful_list = []
for pattern in all_seisuuretu:
    beautiful_list.append(sum(pattern))

for i in range(len(beautiful_list)):
    beautiful_list[i] = bin(beautiful_list[i])[2:]

list_max = []
for i in beautiful_list:
    list_max.append(len(i))
list_max = max(list_max)
list_max = -list_max

status = True
while status == True:
    temp = []
    count = 0
    for i in beautiful_list:
        try:
            if int(i[list_max]) == 1:
                count += 1
                temp.append(i)
        except:
            continue
    if count > int(nk[1]):
        list_max += 1
        beautiful_list = temp
    elif count == int(nk[1]):
        beautiful_list = temp
        for num in range(len(beautiful_list)):
            if num == 0:
                ronriseki = int(beautiful_list[num], 2)
            else:
                ronriseki = ronriseki & int(beautiful_list[num], 2)
        print(ronriseki)
        status = False
    elif list_max == -1:
        for num in range(len(beautiful_list)):
            if num == 0:
                ronriseki = int(beautiful_list[num], 2)
            else:
                ronriseki = ronriseki & int(beautiful_list[num], 2)
        print(ronriseki)
        status = False
    else:
        list_max += 1
# Original solution
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N, K = inpl()
A = inpl()
tmp = 0
S = [0]*N
Q = []
for i in range(N):
    tmp += A[i]
    S[i] = tmp
    Q.append(tmp)

tmp = 0
for i in range(1, N):
    tmp = S[i-1]
    for j in range(i, N):
        #print(i, j)
        v = S[j] -S[i-1]
        Q.append(v)

res = 0
while True:
    ok = 0
    for i in range(40):
        num = res + int("1" + "0"*i, 2)
        tmp = 0
        for j in range(len(Q)):
            if num & Q[j] == num:
                tmp += 1
        if tmp >= K:
            ok = num
    if res < ok:
        res = ok
    else:
        break
print(res)

# Optimized solution
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N, K = inpl()
A = inpl()
tmp = 0
S = [0]*N
Q = []
for i in range(N):
    tmp += A[i]
    S[i] = tmp
    Q.append(tmp)

tmp = 0
for i in range(1, N):
    tmp = S[i-1]
    for j in range(i, N):
        #print(i, j)
        v = S[j] -S[i-1]
        Q.append(v)

res = 0
L = len(Q)
I = len(bin(sum(A))) - 2
while True:
    ok = 0
    for i in range(I):
        num = res + 2**i
        tmp = 0
        for j in range(L):
            if num & Q[j] == num:
                tmp += 1
        if tmp >= K:
            ok = num

    I = len(bin(res - ok)) - 2
    if res < ok & ok > 0:
        res = ok
    else:
        break

print(res)
# Original solution
from collections import defaultdict
from itertools import accumulate
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
Acum = [0]
Acum.extend(accumulate(A))
cnt = defaultdict(int)
for i in range(n):
    for j in range(i+1, n+1):
        beauty = Acum[j]-Acum[i]
        cnt[beauty] += 1

x = 0
for t in reversed(list(range(41))):
    y = 1 << t
    cnt_k = 0
    for beauty, c in list(cnt.items()):
        if (x+y) & beauty == (x+y):
            cnt_k += c
    if k <= cnt_k:
        x += y

print(x)


# Optimized solution
from collections import defaultdict
from itertools import accumulate
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
Acum = [0]
Acum.extend(accumulate(A))

cnt = defaultdict(int)
for i in range(n):
    for j in range(i+1, n+1):
        beauty = Acum[j]-Acum[i]
        cnt[beauty] += 1


def check(x):
    res = 0
    for beauty, c in list(cnt.items()):
        if x & beauty == x:
            res += c
    return k <= res


L = 0
R = 1 << 40
while L != R-1:
    M = (L+R)//2
    if check(M):
        L = M
    else:
        R = M
print(L)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

ruiseki = [0] * (n + 1)
for i in range(n):
    ruiseki[i+1] = ruiseki[i] + a[i]

li = []
for i in range(n):
    for j in range(i, n):
        tmp = format(ruiseki[j + 1] - ruiseki[i], '040b')
        li.append(tmp)

for i in range(40):
    cnt = 0
    new_li = []
    for j in range(len(li)):
        if li[j][i] == "1":
            new_li.append(li[j])
            cnt += 1
    if cnt >= k:
        li = new_li[0:]

ans = 2**41 -1
for i in range(k):
    ans = ans & int(li[i], 2)
print(ans)

# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))


li = []
for i in range(n):
    num = 0
    for j in range(i, n):
        num += a[j]
        li.append(num)

ans = 0
for i in range(40)[::-1]:
    bit = 2 ** i
    new_li = [num for num in li if num&bit != 0]
    if len(new_li) >= k:
        li = new_li[0:]
        ans += bit
print(ans)
# Original solution
from itertools import accumulate
from itertools import combinations

N, K = [int(x) for x in input().strip().split(" ")]
As = [0] + [int(x) for x in input().strip().split(" ")]

aAs = list(accumulate(As))

keta = 41
d = [set() for _ in range(41)]

for i, j in combinations(list(range(N)), 2):
    rr = aAs[j + 1] - aAs[i]
    rr = "{0:041d}".format(int(bin(rr)[2:]))
    for k in range(keta):
        if rr[k] == "1":
            d[k].add((i, j))

for i in range(N):
    j = i
    rr = As[i+1]
    rr = "{0:041d}".format(int(bin(rr)[2:]))
    for k in range(keta):
        if rr[k] == "1":
            d[k].add((i, j))

candidates = None
rr = 0
for i, ss in enumerate(d):
    if len(ss) < K:
        continue
    if candidates == None:
        candidates = ss
        rr += pow(2, 40-i)
    else:
        xx = ss & candidates
        if len(xx) < K:
            continue
        candidates = xx
        rr += pow(2, 40-i)
print(rr)


# Optimized solution
N, K = list(map(int, input().split()))
from itertools import accumulate
As = [0] + list(map(int, input().split()))
As = list(accumulate(As))
L = len(bin(As[-1]))-2
xs = []
for i in range(N+1):
    for j in range(i+1, N+1):
        xs.append(As[j] - As[i])
xs.sort()
ts = set(range(N*(N+1)//2))
for j in range(L-1,-1,-1):
    nts = set()
    for i in ts:
        if (xs[i]>>j)%2:
            nts.add(i)
    if len(nts) >= K:
        ts = nts
c = 0
r = 0
for i in ts:
    c += 1
    if r == 0:
        r = xs[i]
    else:
        r = r&xs[i]
    if c == K:
        break
print(r)
# Original solution
p = int(eval(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 % p
for i in range(p):
    ans[i] %= p
print((' '.join(map(str, ans))))


# Optimized solution
p = int(eval(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))))
# Original solution
p = eval(input())
a = list(map(int, input().strip().split()))
b = [0] * p

p2 = p * p

s = []
for i in range(p):
    if a[i]: s.append(i)

ncr = [[0 for i in range(p)] for j in range(p)]

for i in range(p):
    ncr[i][0] = ncr[i][i] = 1
    ncr[i][1] = i

for n in range(2, p):
    for r in range(2, n):
        ncr[n][r] = ncr[n - 1][r] + ncr[n - 1][r - 1]
        if (ncr[n][r] >= p): ncr[n][r] -= p

jpow = [[0 for i in range(p)] for j in range(p)]
jpow[0][0] = 1

for i in range(1, p):
    val = 1
    for j in range(p):
        jpow[i][j] = val
        val *= i
        if (val >= p2): val %= p

for r in range(1, p):
    for j in s:
        x = ncr[p - 1][r]
        x *= jpow[j][p - 1 - r]
        if (x >= p2): x %= p

        if (p - r) & 1: b[r] -= x
        else: b[r] += x

    if b[r] >= p or b[r] < 0: b[r] %= p

if a[0]: b[0] = 1

print(' '.join(map(str, b)))

# Optimized solution
p = eval(input())
a = list(map(int, input().strip().split()))
b = [0] * p

p2 = p * p

s = []
for i in range(p):
    if a[i]: s.append(i)

ncr = [[0 for i in range(p)] for j in range(p)]

for i in range(p):
    ncr[i][0] = ncr[i][i] = 1
    ncr[i][1] = i

for n in range(2, p):
    for r in range(2, n):
        ncr[n][r] = ncr[n - 1][r] + ncr[n - 1][r - 1]
        if (ncr[n][r] >= p): ncr[n][r] -= p

jpow = [[0 for i in range(p)] for j in range(p)]
jpow[0][0] = 1

for i in range(1, p):
    val = 1
    for j in range(p):
        jpow[i][j] = val
        val *= i
        if (val >= p): val %= p

for r in range(1, p):
    for j in s:
        x = ncr[p - 1][r]
        x *= jpow[j][p - 1 - r]
        if (x >= p2): x %= p

        if (p - r) & 1: b[r] -= x
        else: b[r] += x

    if b[r] >= p or b[r] < 0: b[r] %= p

if a[0]: b[0] = 1

print(' '.join(map(str, b)))
# Original solution
#import sys
#input = sys.stdin.readline
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( eval(input()))
    A = list( map( int, input().split()))
    ANS = [A[0]]
    pm1Ck = getCmb(p-1,p)
    for k in range(1,p):
        now = 0
        for i in range(p):
            now -= A[i]*pow(p-i,p-1-k,p)*pm1Ck[k]
            now %= p
        ANS.append(now)
    print(( " ".join( map( str, ANS))))
    # for i in range(p):
    #     now = 0
    #     for k in range(p):
    #         now += ANS[k]*pow(i,k,p)
    #         now %= p
    #     print(A[i], now)
if __name__ == '__main__':
    main()


# Optimized solution
#import sys
#input = sys.stdin.readline
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( eval(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 -= A[i]*pow(p-i,p-1-k,p)*pm1Ck[k]
            now %= p
        ANS.append(now)
    print(( " ".join( map( str, ANS))))
    # for i in range(p):
    #     now = 0
    #     for k in range(p):
    #         now += ANS[k]*pow(i,k,p)
    #         now %= p
    #     print(A[i], now)
if __name__ == '__main__':
    main()
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

p = int(eval(input()))
a = [int(i) for i in input().split()]

ret = [0] * p
fac = [1]
inv = [1]
power = [0] * p
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
    for j in range(p) :
        ret[j] += -fac[p-1]*inv[p-1-j]*inv[j]*pow(-i, p-1-j, p)%p
        ret[j] %= p

print((' '.join(map(str, ret))))

# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

p = int(eval(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))))
# Original solution
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


p = int(eval(input()))
a = list(map(int, input().split()))

### 素数の逆元とCombination

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 # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    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)
    ans[0] += 1
for i in range(p):
    ans[i] %= M
write(" ".join(map(str, ans)))

# Optimized solution
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


p = int(eval(input()))
a = list(map(int, input().split()))

### 素数の逆元とCombination

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 # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    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)))
# Original solution
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


p = int(eval(input()))
a = list(map(int, input().split()))

### 素数の逆元とCombination

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 # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    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)))

# Optimized solution
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


p = int(eval(input()))
a = list(map(int, input().split()))

### 素数の逆元とCombination

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 # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    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
    val = 1
    for j in reversed(list(range(p))):
        ans[j] += -cmb(p-1,j,M) * val #pow(-i,p-1-j,M)
#         ans[j] += -cmb(p-1,j,M) * pow(-i,p-1-j,M)
        ans[j] %= M
        val *= -i
        val %= M
    ans[0] += 1
for i in range(p):
    ans[i] %= M
write(" ".join(map(str, ans)))
# Original solution

p = int(eval(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]

        lis = nlis

#print (lis) = (x-0)*(x-1)*…*(x-p+1)の各項の係数
#ラグランジュ補完を実際に計算していく
#参考　https://mathtrain.jp/hokan

ans = [0] * p

for i in range(p):

    #fi(x)を計算 (x-i)でlisを割る
    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))

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


# Optimized solution

p = int(eval(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

#print (lis) = (x-0)*(x-1)*…*(x-p+1)の各項の係数
#ラグランジュ補完を実際に計算していく
#参考　https://mathtrain.jp/hokan

ans = [0] * p

for i in range(p):

    #fi(x)を計算 (x-i)でlisを割る
    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))))