#C2880. Transform and Sum Sequence

    ID: 46245 Type: Default 1000ms 256MiB

Transform and Sum Sequence

Transform and Sum Sequence

You are given an integer n and a sequence of n integers. Your task is to transform each number in the sequence according to the rules below, and then output the sum of the transformed numbers.

The transformation function f(a) is defined as follows:

$$ f(a)=\begin{cases} a-1, & \text{if } a>0 \text{ and } a \text{ is even},\\ a+1, & \text{if } a>0 \text{ and } a \text{ is odd},\\ |a|, & \text{if } a<0,\\ a, & \text{if } a=0. \end{cases} $$

Your goal is to compute and print the value of

i=1nf(ai),\sum_{i=1}^{n} f(a_i),

where \(a_i\) is the i-th element in the sequence.

Example:

Input:
5
3 -2 0 7 4

Output: 17

</p>

Explanation: For the given example, the transformations are:

  • 3 (positive odd) becomes 3 + 1 = 4.
  • -2 (negative) becomes |−2| = 2.
  • 0 remains 0.
  • 7 (positive odd) becomes 7 + 1 = 8.
  • 4 (positive even) becomes 4 − 1 = 3.

The sum is 4 + 2 + 0 + 8 + 3 = 17.

inputFormat

The first line contains a single integer n (the number of elements in the sequence). The second line contains n space-separated integers representing the sequence.

outputFormat

Print a single integer which is the sum of the transformed sequence.

## sample
5
3 -2 0 7 4
17

</p>