This page is still under construction.

Parts of this page are still being built. What you see may change.

Plotting Polynomials

Time limit2sMemory limit256 MB

Summary
Compute the initial forward-difference constants that let the given loop evaluate a degree-n polynomial at consecutive integers.
Level

Medium6 of 10

Topics
Math, Combinatorics
Solved
No attempts yet

Problem

A graphing calculator draws a function on screen with almost no work from the student. The processor in such a calculator is slow, so the drawing routine has to be economical. This problem asks you to implement a method that speeds up the plotting of a polynomial.

Given a polynomial p(x)=anxn+⋯+a1x+a0p(x) = a_n x^n + \dots + a_1 x + a_0 of degree nn, you want to plot it at the mm integer points x=0,1,…,m−1x = 0, 1, \dots, m-1. Evaluating the polynomial directly at each point costs mnmn multiplications and mnmn additions.

Reusing earlier results cuts that cost. If p(x)=a1x+a0p(x) = a_1 x + a_0 and p(i)p(i) is already known, then p(i+1)=p(i)+a1p(i+1) = p(i) + a_1, so every later value costs one addition.

In general, once the initialization is done, nn additions turn p(i)p(i) into p(i+1)p(i+1). With the constants C0,C1,…,CnC_0, C_1, \dots, C_n chosen correctly, the pseudocode below produces p(i)p(i).

p(0) = C_0; t_1 = C_1; ... t_n = C_n;
for i from 1 to m-1 do
     p(i)    = p(i-1)  + t_1;
     t_1     = t_1     + t_2;
     t_2     = t_2     + t_3;
              :
              :
     t_(n-1) = t_(n-1) + t_n;
end

For p(x)=a1x+a0p(x) = a_1 x + a_0 you can take C0=a0C_0 = a_0 and C1=a1C_1 = a_1.

Compute the constants C0,C1,…,CnC_0, C_1, \dots, C_n that make the pseudocode give the correct value of p(i)p(i) for every i=0,…,m−1i = 0, \dots, m-1.

Input

The input is a single line. The first integer is nn, with 1≤n≤61 \le n \le 6. It is followed by the n+1n+1 integer coefficients an,…,a1,a0a_n, \dots, a_1, a_0. Every coefficient satisfies ∣ai∣≤50|a_i| \le 50, and an≠0a_n \neq 0.

Output

Print C0,C1,…,CnC_0, C_1, \dots, C_n on one line, separated by single spaces.

Examples3

  1. Example 1

    Input
    1 5 2
    
    Expected output
    2 5
    
  2. Example 2

    Input
    2 2 -4 5
    
    Expected output
    5 -2 4
    
  3. Example 3

    Input
    6 1 -20 4 30 0 -1 2
    
    Expected output
    2 14 -302 -2136 -3144 -600 720