#C14037. Sum With Neighbors

    ID: 43642 Type: Default 1000ms 256MiB

Sum With Neighbors

Sum With Neighbors

You are given an array of integers. Your task is to compute a new array such that each element is the sum of the element itself and its immediate neighbors. For the first element, the left neighbor is assumed to be 0; similarly, for the last element, the right neighbor is assumed to be 0.

Formally, for an array (a = [a_0, a_1, \dots, a_{n-1}]), the resulting array (b = [b_0, b_1, \dots, b_{n-1}]) is defined as follows:

[ b_i = \begin{cases} a_0 + a_1, & i = 0 \ a_{i-1} + a_i + a_{i+1}, & 0 < i < n-1 \ a_{n-2} + a_{n-1}, & i = n-1 \end{cases} ]

Note that you should consider missing neighbors as 0.

inputFormat

The input is provided via standard input (stdin) as a single line containing space-separated integers.

outputFormat

Output the computed array to standard output (stdout) as a single line of space-separated integers.## sample

1 2 3 4
3 6 9 7