#K9931. Alternating Sum of a List
Alternating Sum of a List
Alternating Sum of a List
Given a list of integers, compute the alternating sum of its elements. That is, starting from the first element, add the first element, subtract the second, add the third, and so on.
This can be described mathematically as:
\[ S = \sum_{i=0}^{n-1} (-1)^i \times a_i, \]
where \(a_i\) is the \(i\)-th element of the list and \(n\) is the number of elements in the list. If the list is empty, the sum is defined to be 0.
Input is provided via standard input (stdin) and output should be printed to standard output (stdout).
inputFormat
The first line contains an integer \(n\) (\(n \geq 0\)), the number of elements in the list. The second line contains \(n\) space-separated integers representing the elements of the list. In case \(n = 0\), the second line may be empty.
outputFormat
Output a single integer, the alternating sum of the list elements, computed as \(a_0 - a_1 + a_2 - a_3 + \ldots\).
## sample5
1 2 3 4 5
3