Memory and Crow (Codeforces 712A)
Tags: Implement, math

There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure:  The crow sets ai initially 0.  The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus, ai = bi - bi + 1 + bi + 2 - bi + 3.... Memory gives you the values a1, a2, ..., an, and he now wants you to find the initial numbers b1, b2, ..., bn written in the row? Can you do it?

Input: The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of integers written in the row.The next line contains n, the i'th of which is ai ( - 109 ≤ ai ≤ 109) — the value of the i'th number.

Output: Print n integers corresponding to the sequence b1, b2, ..., bn. It's guaranteed that the answer is unique and fits in 32-bit integer type.

Note: In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3.In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.

Sample Inputs:
5
6 -4 8 -2 3

5
3 -2 -1 5 6

Sample Outputs:
2 4 6 1 3

1 -3 4 11 6

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
b[n - 1] = a[n - 1]
for i in range(n - 2, -1, -1):
    b[i] = a[i] + a[i + 1]
print(' '.join(map(str, b)))

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
conter = 0
res = ''
for i in range(1, n):
    res += str(l[i - 1] + l[i]) + ' '
res += str(l[-1])
print(res)

Solution (Python):
n = int(input())
b = list(map(int, input().split(' ')))
a = [0] * n
a[n - 1] = b[n - 1]
i = n - 2
for i in range(n - 1):
    a[i] = b[i] + b[i + 1]
print(' '.join([str(x) for x in a]))