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 mod_pow(r: u32, mut n: u32, p: u32) -> u32 {
    let mut t = 1;
    let mut s = r % p;
    while n > 0 {
        if (n & 1) == 1 {
            t = t * s % p;
        }
        s = s * s % p;
        n >>= 1;
    }
    t
}

//(x - b) をかける
fn mul(a: &Vec<u32>, b: u32, p: u32) -> Vec<u32> {
    let mut res = vec![0; a.len() + 1];
    for i in 0..a.len() {
        res[i] = (res[i] + a[i] * (p - b)) % p;
        res[i + 1] = (res[i + 1] + a[i]) % p;
    }
    res
}

fn mul_constant(a: &Vec<u32>, k: u32, p: u32) -> Vec<u32> {
    let mut res = vec![0; a.len()];
    for i in 0..a.len() {
        res[i] = a[i] * k % p;
    }
    res
}

fn add(a: &Vec<u32>, b: &Vec<u32>, p: u32) -> Vec<u32> {
    let mut res = vec![0; std::cmp::max(a.len(), b.len())];
    for i in 0..a.len() {
        res[i] = (res[i] + a[i]) % p;
    }
    for i in 0..b.len() {
        res[i] = (res[i] + b[i]) % p;
    }
    res
}

fn div(a: &Vec<u32>, y: u32, p: u32) -> Vec<u32> {
    let mut res = vec![0; a.len() - 1];
    let mut b = a.clone();
    for i in (1..a.len()).rev() {
        res[i - 1] = b[i];
        b[i - 1] = (b[i - 1] + y * b[i]) % p;
    }
    res
}

fn eval(a: &Vec<u32>, x: u32, p: u32) -> u32 {
    let mut v = 0;
    for a in a.iter().rev() {
        v = (v * x + *a) % p;
    }
    v
}

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        p: usize,
        a: [u32; p],
    }
    let mut fact = vec![1; 1];
    for i in 0..p {
        fact = mul(&fact, i as u32, p as u32);
    }
    let mut ans = vec![0; p];
    for i in 0..p {
        if a[i] == 0 {
            continue;
        }
        let mut f = 1;
        for j in 0..i {
            f = f * (p + j - i) as u32 % p as u32;
        }
        for j in (i + 1)..p {
            f = f * (j - i) as u32 % p as u32;
        }
        let i = i as u32;
        let p = p as u32;
        let x = div(&fact, i, p);
        let x = mul_constant(&x, mod_pow(f, p - 2, p), p);
        ans = add(&ans, &x, p);
    }
    for i in 0..p {
        assert!(eval(&ans, i as u32, p as u32) == a[i]);
        if i > 0 {
            write!(out, " ").unwrap();
        }
        write!(out, "{}", ans[i]).unwrap();
    }
    writeln!(out, "").unwrap();
}

fn main() {
    run();
}