Problem:
Score : 300 points

Problem Statement

You are given an integer sequence of length N. The i-th term in the sequence is a_i.
In one operation, you can select a term and either increment or decrement it by one.

At least how many operations are necessary to satisfy the following conditions?

For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero.

For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.

Constraints

2 ≤ n ≤ 10^5

|a_i| ≤ 10^9

Each a_i is an integer.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print the minimum necessary count of operations.

Sample Input 1

4
1 -3 1 0

Sample Output 1

4

For example, the given sequence can be transformed into 1, -2, 2, -2 by four operations. The sums of the first one, two, three and four terms are 1, -1, 1 and -1, respectively, which satisfy the conditions.

Sample Input 2

5
3 -6 4 -5 7

Sample Output 2

0

The given sequence already satisfies the conditions.

Sample Input 3

6
-1 4 3 2 -5 4

Sample Output 3

8

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#define _CRT_SECURE_NO_WARNINGS
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define true 1
#define false 0
typedef unsigned long long int Ulli;

Ulli n;

int dp(int zero, int one, int two, int back) {
	//終了条件
	if (zero + one + two == 0) {
		return 1;
	}
	

	switch (back) {
	case 0:
		if (one >= 1 && dp(zero, one - 1, two, 1) == 1) {
			goto YES;
		}
	case 2:
		if (two >= 1 && dp(zero, one, two - 1, 2) == 1) {
			goto YES;
		}
	case 1:
		if (zero >= 1 && dp(zero - 1, one, two, 0) == 1) {
			goto YES;
		}
		break;
	default:
		break;
	}
	return 0;

YES:
	return 1;
}

int main() {
	int one = 0, two = 0, zero = 0;
	scanf("%d", &n);
	int temp;
	for (int i = 0; i < n; i++) {
		scanf("%d", &temp);
		if (temp % 4 == 0) {
			zero++;
		}
		else if (temp&1) {
			two++;
		}
		else {
			one++;
		}
	}
	if (zero >= one) {
		printf("Yes\n");
	}
	else if(zero < one) {
		printf("No");
	}/*
	if (dp(zero, one, two, 0) == 1) {
		printf("Yes\n");
		return 0;
	}
	printf("No\n");*/
	return 0;

	
}


/*
problem B
char s[100001];
int a = 0, b = 0, c = 0;
char temp[100001];

int dp(int a, int b, int c, int temp_num) {
	//すべて0になったら終了
	if (a == 0 && b == 0 && c == 0) {
		return 0;
	}

	

	int a1 = 1, b1 = 1, c1 = 1;

	//使えないやつを排除
	if (a == 0) {
		a1 = 0;
	}
	if (b == 0) {
		b1 = 0;
	}
	if (c == 0) {
		c1 = 0;
	}

	if (temp_num > 0) {
		if (temp[temp_num - 1] == 'a') {
			a1 = 0;
		}
		if (temp[temp_num - 1] == 'b') {
			b1 = 0;
		}
		if (temp[temp_num - 1] == 'c') {
			c1 = 0;
		}
	}
	if (temp_num > 1) {
		if (temp[temp_num - 2] == 'a') {
			a1 = 0;
		}
		if (temp[temp_num - 2] == 'b') {
			b1 = 0;
		}
		if (temp[temp_num - 2] == 'c') {
			c1 = 0;
		}
	}
	int ans = -1;
//	printf("a,b,c %d %d %d a1b1c1 %d %d %d\n", a, b, c, a1, b1, c1);
	if (a1 == 1) {
		if (b1 == 1) {
			if (c1 == 1) {
				//a,b,c
				temp[temp_num] = 'a';
				ans = dp(a - 1, b, c, temp_num + 1);
				if (ans == -1) {
					temp[temp_num] = 'b';
					ans = dp(a, b - 1, c, temp_num + 1);
				}
				if (ans == -1) {
					temp[temp_num] = 'c';
					ans = dp(a, b, c - 1, temp_num + 1);
				}
			}
			else {
				//a,b
				temp[temp_num] = 'a';
				ans = dp(a - 1, b, c, temp_num + 1);
				if (ans == -1) {
					temp[temp_num] = 'b';
					ans = dp(a, b - 1, c, temp_num + 1);
				}
			}
		}
		else {
			if (c1 == 1) {
				//a,c
				temp[temp_num] = 'a';
				ans = dp(a - 1, b, c, temp_num + 1);
				if (ans == -1) {
					temp[temp_num] = 'c';
					ans = dp(a, b, c - 1, temp_num + 1);
				}
			}
			else {
				//a
				temp[temp_num] = 'a';
				ans = dp(a - 1, b, c, temp_num + 1);
			}
		}
	}
	else {
		if (b1 == 1) {
			if (c1 == 1) {
				//b,c
				temp[temp_num] = 'b';
				ans = dp(a, b - 1, c, temp_num + 1);
				if (ans == -1) {
					temp[temp_num] = 'c';
					ans = dp(a, b, c - 1, temp_num + 1);
				}
			}
			else {
				//b
				temp[temp_num] = 'b';
				ans = dp(a, b - 1, c, temp_num + 1);
				
			}
		}
		else {
			if (c1 == 1) {
				//c
				temp[temp_num] = 'c';
				ans = dp(a, b, c - 1, temp_num + 1);
			}
			else {
				ans = -1;
			}
		}
	}

	return ans;
}

int main() {
	scanf("%s", s);
	for (int i = 0; i < 100001 && s[i] != NULL; i++) {
		if (s[i] == 'a') {
			a++;
		}
		else if (s[i] == 'b') {
			b++;
		}
		else {
			c++;
		}
	}
	//printf("%d %d %d\n", a, b, c);
	if (dp(a, b, c, 0) == 0) {
		printf("YES\n");
		return 0;
	}
	printf("NO\n");
	return 0;

}
*/
/*
problem A

char s[51];
char origin[10] = "AKIHABARA";
int origin_num = 0;

int main() {
	for (int i = 0; i < 51; i++) {
		s[i] = '0';
	}
	scanf("%s", s);
	for (int i = 0; i < 50 && origin_num <= 9; i++) {
		//同じの場合
		if (s[i] == origin[origin_num]) {
			origin_num++;
		}
		//Aをひとつ飛ばしたら同じの場合
		else if (origin[origin_num] == 'A' && origin_num <= 8 && origin[origin_num + 1] == s[i]) {
			origin_num += 2;
		}
		else {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}*/