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 in Go (1.6) (judge verdict: Time Limit Exceeded)

package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Inverse(p int) []int {
  Inv := make([]int, p)
  Inv[0] = 1
  Inv[1] = 1
  for i := 2; i < p; i++ {
    Inv[i] = p - Inv[p % i] * (p / i) % p
  }
  return Inv
}

type ModIntOperator struct {
  Inv []int
  Mod int
}
func InitMIO(p int) ModIntOperator {
  Inv := Inverse(p)
  return ModIntOperator{Inv, p}
}
func (M ModIntOperator) Num(a int) int {
  a %= M.Mod
  if a < 0 { a += M.Mod }
  return a
}
func (M ModIntOperator) Add(a, b int) int {
  return (M.Num(a) + M.Num(b)) % M.Mod
}
func (M ModIntOperator) Sub(a, b int) int {
  return (M.Num(a) - M.Num(b) + M.Mod) % M.Mod
}
func (M ModIntOperator) Mul(a, b int) int {
  return M.Num(a) * M.Num(b) % M.Mod
}
func (M ModIntOperator) Div(a, b int) int {
  return M.Num(a) * M.Inv[M.Num(b)] % M.Mod
}

func Solve() {
  var p, d, m int
  var A []int
  NextInt(&p)
  NextIntVec(&A)
  M := InitMIO(p)
  B := make([][]int, p)
  for i := range B {
    B[i] = make([]int, p)
    B[i][0]++
    for j := range B[i][1:] {
      B[i][j + 1] = M.Mul(B[i][j], i)
    }
  }
  for i := 0; i < p; i++ {
    d = B[i][i]
    for j := i; j < p; j++ { B[i][j] = M.Div(B[i][j], d) }
    A[i] = M.Div(A[i], d)
    for j := 1; j < p; j++ {
      if i == j { continue }
      m = B[j][i]
      for k := i; k < p; k++ {
        B[j][k] = M.Sub(B[j][k], M.Mul(B[i][k], m))
      }
      A[j] = M.Sub(A[j], M.Mul(A[i], m))
    }
  }
  WriteIntVec(A)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}