Buggy python submission (verdict: Time Limit Exceeded):
p = int(input())
A = [int(x) for x in input().split()]

def swap(a, b):
        return (b, a)

def modinv(a, m):
        b = m
        u = 1
        v = 0
        while b:
                t = a // b
                a -= t * b
                a, b = swap(a, b)
                u -= t * v
                u, v = swap(u, v)
        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))


# p-1C0, p-1C1, ..., p-1Cp-1
binomial = []
for i in range(p):
    l = i
    r = p-1-i
    binomial.append(prod * inv_factorial[l] * inv_factorial[r] % p)
    
ret = [0] * p
for i in range(p):
    if A[i] == 0:
        continue

    ret[0] += 1
    for j in range(p):
        ret[j] -= binomial[j] * (-i) ** (p-1-j)
        ret[j] %= p

ans = ''
for i in range(p):
    ans += str(ret[i]%p) + ' '

print(ans)
        


Fixed submission:
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))

#p-1C0, p-1C1, ..., p-1Cp-1
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)

Buggy python submission (verdict: Time Limit Exceeded):
p = int(input())
A = [int(x) for x in input().split()]

def swap(a, b):
        return (b, a)

def modinv(a, m):
        b = m
        u = 1
        v = 0
        while b:
                t = a // b
                a -= t * b
                a, b = swap(a, b)
                u -= t * v
                u, v = swap(u, v)
        u %= m
        if u < 0:
                u += m
        return u

# p-1C0, p-1C1, ..., p-1Cp-1
binomial = []
for i in range(p):
    num = 1
    denom = 1
    for j in range(1, i+1):
        num *= (p-j)
        denom *= j
        num %= p
        denom %= p
    binomial.append(num * modinv(denom, p) % p)

ret = [0] * p
for i in range(p):
    if A[i] == 0:
        continue

    ret[0] += 1
    for j in range(p):
        ret[j] -= binomial[j] * (-i) ** (p-1-j)
        ret[j] %= p

ans = ''
for i in range(p):
    ans += str(ret[i]%p) + ' '

print(ans)
        


Fixed submission:
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))

#p-1C0, p-1C1, ..., p-1Cp-1
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)