#C12693. Sum of Neighbors
Sum of Neighbors
Sum of Neighbors
Given an array of integers \(A=[a_0,a_1,\dots,a_{n-1}]\), your task is to construct a new array \(B=[b_0,b_1,\dots,b_{n-1}]\) where:
- For the first element: \(b_0=a_0+a_1\) (if \(a_1\) exists).
- For the last element: \(b_{n-1}=a_{n-2}+a_{n-1}\) (if \(a_{n-2}\) exists).
- For all other elements (\(0 < i < n-1\)): \(b_i=a_{i-1}+a_i+a_{i+1}\).
If the number of elements is less than 3, the output should be the original array.
inputFormat
The input is read from stdin and consists of:
- The first line contains an integer \(n\) (\(0 \le n \le 10^5\)), representing the number of elements in the array.
- If \(n > 0\), the second line contains \(n\) space-separated integers.
outputFormat
The output should be written to stdout as a single line containing the transformed array. Each element must be separated by a single space.
## sample4
1 2 3 4
3 6 9 7