#K86582. Alternate Sum Sequence
Alternate Sum Sequence
Alternate Sum Sequence
You are given an array of integers. For each index i (0-indexed) in the array, compute the difference between the sum of elements at even indices and the sum of elements at odd indices up to that index. In other words, define the result sequence \(R\) where:
\( R_i = \sum_{\substack{0 \leq j \leq i \\ j \text{ even}}} arr[j] - \sum_{\substack{0 \leq j \leq i \\ j \text{ odd}}} arr[j] \)
For example, if the input array is [1, 2, 3, 4, 5], then the output sequence is [1, -1, 2, -2, 3].
Your task is to read an array from standard input and output the resulting sequence to standard output.
inputFormat
The first line of input contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Output a single line containing \(n\) space-separated integers representing the resulting alternate sum sequence.
## sample5
1 2 3 4 5
1 -1 2 -2 3