#C2005. Sum of Adjacent Elements
Sum of Adjacent Elements
Sum of Adjacent Elements
You are given a list of integers. Your task is to create a new list where each element is the sum of itself and the following element in the input list. For the last element, there is no following element so it remains unchanged.
Input Example:
4 1 2 3 4
Output Example:
3 5 7 4
Technical Details:
If the input is an empty list, the output should also be an empty list. This problem requires careful handling of edge cases, especially when the list contains only one element.
The operation performed for each element (except the last one) is mathematically described as follows:
\(a_i' = \begin{cases} a_i + a_{i+1}, & \text{for } 1 \leq i < n \\ a_i, & \text{for } i = n \end{cases}\)
inputFormat
The first line contains a single integer \(n\) representing the number of elements in the list. The second line contains \(n\) space-separated integers.
outputFormat
Output a single line containing \(n\) integers representing the new list. The integers should be space-separated.
## sample4
1 2 3 4
3 5 7 4