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)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn pow(mut x: i64, mut n: i64, p: i64) -> i64 {
    let mut res = 1;
    while n != 0 {
        if n & 1 == 1 {
            res *= x;
            res %= p;
        }
        x *= x;
        x %= p;
        n >>= 1;
    }
    res
}

fn inv(x: i64, p: i64) -> i64 {
    pow(x, p - 2, p)
}

fn norm(x: i64, p: i64) -> i64 {
    (x % p + p) % p
}

fn main() {
    input! {
        p: i64,
        a: [i64; p as usize]
    }

    let (pos, neg) = {
        let mut pos = vec![1; p as usize];
        for i in 1..p {
            pos[i as usize] = (pos[i as usize - 1] * i) % p;
        }
        let mut neg = vec![1; p as usize];
        neg[p as usize - 1] = inv(pos[p as usize - 1], p);
        for i in (1..p).rev() {
            neg[i as usize - 1] = (neg[i as usize] * i) % p;
        }
        (pos, neg)
    };
    let binomial = |n, r| pos[n as usize] * neg[r as usize] * neg[(n - r) as usize];

    let mut poly = vec![0; p as usize];
    for i in 0..p {
        if a[i as usize] == 0 {
            continue;
        }
        poly[0] += 1;
        let mut s = 1;
        for j in 0..p {
            poly[(p - 1 - j) as usize] -= norm(s * binomial(p - 1, j), p);
            s = norm(s * -i, p);
        }
    }
    for b in poly {
        print!("{} ", (b % p + p) % p);
    }
}
*/

fn main() {
    let exe = "/tmp/binF2AD7DD2";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";