#C14262. Alternate Sum

    ID: 43892 Type: Default 1000ms 256MiB

Alternate Sum

Alternate Sum

Given a list of integers, compute the alternate sum where you add the numbers in the even positions and subtract the numbers in the odd positions.

Formally, for a list of integers \(a_0, a_1, \dots, a_{n-1}\), you need to compute

\(a_0 - a_1 + a_2 - a_3 + \cdots\)

The task should handle cases where the list is empty, contains one element, or includes negative numbers.

inputFormat

The first line of input contains a single integer \(n\) denoting the number of elements in the list. The second line contains \(n\) space-separated integers. If \(n = 0\), the second line can be omitted.

outputFormat

Output a single integer, which is the alternate sum computed by adding the even-indexed elements and subtracting the odd-indexed elements.

## sample
5
1 2 3 4 5
3

</p>