Under construction

Still being built. Things may change

A New Sequence

Time limit2sMemory limit512 MB

Summary
Given a circular sequence A, compute each b_i as the sum of a_{i+k mod N} weighted by (-1)^k times (k+1) over all k from 0 to N-1.
Level

Medium7 of 10

Topics
Math, Prefix sum, Array, Divide and conquer
Solved
No attempts yet

Problem

You are given a sequence A={a0,a1,…,aN−1}A = \{a_0, a_1, \dots, a_{N-1}\} of length NN.

From it, define a new sequence B={b0,b1,…,bN−1}B = \{b_0, b_1, \dots, b_{N-1}\} of the same length:

bi=∑k=0N−1(−1)k(k+1) a(i+k) mod Nb_i = \sum_{k=0}^{N-1} (-1)^k (k+1) \, a_{(i+k) \bmod N}

Indices are taken modulo NN, so aNa_{N} is a0a_0 and aN+1a_{N+1} is a1a_1. In other words, bib_i starts at aia_i, walks once around the sequence, and adds each kk-th element multiplied by (−1)k(k+1)(-1)^k (k+1).

Given the sequence AA, compute the sequence BB.

Input

The first line contains NN. (1≤N≤300 0001 \le N \le 300\,000)

The second line contains NN integers a0,a1,…,aN−1a_0, a_1, \dots, a_{N-1} separated by spaces. (∣ai∣≤109|a_i| \le 10^9)

Output

Print the NN integers b0,b1,…,bN−1b_0, b_1, \dots, b_{N-1} of the sequence BB on one line, separated by spaces.

Only inputs for which ∣bi∣≤1018|b_i| \le 10^{18} holds for every ii are given.

Examples2

  1. Example 1

    Input
    3
    4 1 -3
    
    Expected output
    -7 19 -8
    
  2. Example 2

    Input
    5
    -1 2 -3 4 -5
    
    Expected output
    -55 35 -12 -12 35