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 Rust (1.15.1) (judge verdict: Accepted)

//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

use std::io::Write;

fn trans(dp: &mut Vec<usize>, k: usize, p: usize) {
    for i in (1..p).rev() {
        dp[i] = ((p - k) * dp[i] + dp[i - 1]) % p;
    }
    dp[0] = (p - k) * dp[0] % p;
}

fn calc(l: usize, r: usize, a: &Vec<usize>, memo: &Vec<usize>, mut ans: &mut Vec<usize>, p: usize) {
    if l + 1 == r {
        if a[l] == 1 {
            for (ans, memo) in ans.iter_mut().zip(memo.iter()) {
                *ans = (*ans + p - *memo) % p;
            }
        }
        return;
    }
    let mut dp = memo.clone();
    let m = (l + r) / 2;
    for i in l..m {
        trans(&mut dp, i, p);
    }
    calc(m, r, &a, &dp, &mut ans, p);
    dp = memo.clone();
    for i in m..r {
        trans(&mut dp, i, p);
    }
    calc(l, m, &a, &dp, &mut ans, p);
}

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        p: usize,
        a: [usize; p],
    }
    let mut dp = vec![0; p];
    let mut ans = vec![0; p];
    dp[0] = 1;
    calc(0, p, &a, &dp, &mut ans, p);
    for i in 0..p {
        if i > 0 {
            write!(out, " ").unwrap();
        }
        write!(out, "{}", ans[i]).unwrap();
    }
    write!(out, "\n").unwrap();
}

fn main() {
    run();
}