require 'pp'
require 'matrix'

p = gets.chomp!.to_i
a_n = gets.chomp!.split(" ").map(&:to_i)

mat = []
mat[0] = [0] * p
mat[0][0] = 1
mat[1] = [1] * p
2.upto(p-1) do |i|
    mat << 0.upto(p-1).map {|j| (i ** j) % p }
end
matrix = Matrix[*mat]
a_n_mat = Matrix.column_vector(a_n)

pp matrix
pp matrix.inverse
pp a_n_mat

b_n = matrix * a_n_mat
puts b_n.t.to_a.flatten.map {|i| i % p }.join(" ")
    
