Codeforces Round 580 (Div. 2)
B
Make Product Equal One
Codeforces
900
原题
← AC →
翻译中…

You are given $n$ numbers $a_1, a_2, \dots, a_n$. With a cost of one coin you can perform the following operation:

翻译中…

Choose one of these numbers and add or subtract $1$ from it.

翻译中…

In particular, we can apply this operation to the same number several times.

翻译中…

We want to make the product of all these numbers equal to $1$, in other words, we want $a_1 \cdot a_2$ $\dots$ $\cdot a_n = 1$.

翻译中…

For example, for $n = 3$ and numbers $[1, -3, 0]$ we can make product equal to $1$ in $3$ coins: add $1$ to second element, add $1$ to second element again, subtract $1$ from third element, so that array becomes $[1, -1, -1]$. And $1\cdot (-1) \cdot (-1) = 1$.

翻译中…

What is the minimum cost we will have to pay to do that?

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of numbers.

翻译中…

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) — the numbers.

翻译中…

Output

翻译中…

Output a single number — the minimal number of coins you need to pay to make the product equal to $1$.

翻译中…

Note

翻译中…

In the first example, you can change $1$ to $-1$ or $-1$ to $1$ in $2$ coins.

翻译中…

In the second example, you have to apply at least $4$ operations for the product not to be $0$.

翻译中…

In the third example, you can change $-5$ to $-1$ in $4$ coins, $-3$ to $-1$ in $2$ coins, $5$ to $1$ in $4$ coins, $3$ to $1$ in $2$ coins, $0$ to $1$ in $1$ coin.

翻译中…

样例

Input #1
2
-1 1
Output #1
2
InputCopy OutputCopy
Input #2
4
0 0 0 0
Output #2
4
InputCopy OutputCopy
Input #3
5
-5 -3 5 3 0
Output #3
13
InputCopy OutputCopy
题目信息
题号
1206B
时间限制
1 s
内存限制
256 MB
标签
动态规划
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。