#C10830. Minimum Modifications to Zero
Minimum Modifications to Zero
Minimum Modifications to Zero
You are given a sequence of N integers. In one modification, you can change any number by adding or subtracting 1. Your task is to calculate the minimum number of modifications required so that the total sum of the sequence becomes 0.
It can be observed that the answer is simply the absolute value of the sum of the sequence, i.e. \(|s|\) where \(s = \sum_{i=1}^{N} a_i\). This is because you would need to compensate the imbalance exactly by \(|s|\) modifications.
Input/Output: The input is read from standard input and the output is printed to standard output.
inputFormat
The first line contains an integer N representing the length of the sequence. The second line contains N space-separated integers representing the sequence.
outputFormat
Output a single integer representing the minimum number of modifications required to make the sum of the sequence equal to zero. This value is equal to the absolute value of the sum of the sequence.## sample
4
1 2 3 -1
5
</p>