Language: C++

#include<iostream>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<cstdio>
using namespace std;
int n;
int a[120000];
int main()  
{
cin>>n;
for(int i=0;i<n;i++){
	cin>>a[i];
}
int nowa=0;
int sum=0;
for(int i=0;i<n;i++){
	sum=sum+a[i];
	if(i%2==0){
		if(sum<=0)
			nowa=nowa+1-sum,sum=1;
	}
	else{
		if(sum>=0)
			nowa=nowa+sum+1,sum=-1;
	}
}
int ans=nowa;
nowa=0;
sum=0;
for(int i=0;i<n;i++){
	sum=sum+a[i];
	if(i%2==1){
		if(sum<=0)
			nowa=nowa+1-sum,sum=1;
	}
	else{
		if(sum>=0)
			nowa=nowa+sum+1,sum=-1;
	}
}
ans=min(ans,nowa);
cout<<ans;
return 0;
}#include<iostream>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<cstdio>
using namespace std;
int n;
int a[120000];
int main()  
{
cin>>n;
for(int i=0;i<n;i++){
	cin>>a[i];
}
int nowa=0;
int sum=0;
for(int i=0;i<n;i++){
	sum=sum+a[i];
	if(i%2==0){
		if(sum<=0)
			nowa=nowa+1-sum,sum=1;
	}
	else{
		if(sum>=0)
			nowa=nowa+sum+1,sum=-1;
	}
}
int ans=nowa;
nowa=0;
sum=0;
for(int i=0;i<n;i++){
	sum=sum+a[i];
	if(i%2==1){
		if(sum<=0)
			nowa=nowa+1-sum,sum=1;
	}
	else{
		if(sum>=0)
			nowa=nowa+sum+1,sum=-1;
	}
}
ans=min(ans,nowa);
cout<<ans;
return 0;
}#include<iostream>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<cstdio>
using namespace std;
int n;
int a[120000];
int main()  
{
cin>>n;
for(int i=0;i<n;i++){
	cin>>a[i];
}
int nowa=0;
int sum=0;
for(int i=0;i<n;i++){
	sum=sum+a[i];
	if(i%2==0){
		if(sum<=0)
			nowa=nowa+1-sum,sum=1;
	}
	else{
		if(sum>=0)
			nowa=nowa+sum+1,sum=-1;
	}
}
int ans=nowa;
nowa=0;
sum=0;
for(int i=0;i<n;i++){
	sum=sum+a[i];
	if(i%2==1){
		if(sum<=0)
			nowa=nowa+1-sum,sum=1;
	}
	else{
		if(sum>=0)
			nowa=nowa+sum+1,sum=-1;
	}
}
ans=min(ans,nowa);
cout<<ans;
return 0;
}#include<iostream>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<cstdio>
using namespace std;
int n;
int a[120000];
int main()  
{
cin>>n;
for(int i=0;i<n;i++){
	cin>>a[i];
}
int nowa=0;
int sum=0;
for(int i=0;i<n;i++){
	sum=sum+a[i];
	if(i%2==0){
		if(sum<=0)
			nowa=nowa+1-sum,sum=1;
	}
	else{
		if(sum>=0)
			nowa=nowa+sum+1,sum=-1;
	}
}
int ans=nowa;
nowa=0;
sum=0;
for(int i=0;i<n;i++){
	sum=sum+a[i];
	if(i%2==1){
		if(sum<=0)
			nowa=nowa+1-sum,sum=1;
	}
	else{
		if(sum>=0)
			nowa=nowa+sum+1,sum=-1;
	}
}
ans=min(ans,nowa);
cout<<ans;
return 0;
}

Compiler output:
a.cc:50:2: error: stray '#' in program
   50 | }#include<iostream>
      |  ^
a.cc:99:2: error: stray '#' in program
   99 | }#include<iostream>
      |  ^
a.cc:148:2: error: stray '#' in program
  148 | }#include<iostream>
      |  ^
a.cc:50:3: error: 'include' does not name a type
   50 | }#include<iostream>
      |   ^~~~~~~
a.cc:61:5: error: redefinition of 'int n'
   61 | int n;
      |     ^
a.cc:12:5: note: 'int n' previously declared here
   12 | int n;
      |     ^
a.cc:62:5: error: redefinition of 'int a [120000]'
   62 | int a[120000];
      |     ^
a.cc:13:5: note: 'int a [120000]' previously declared here
   13 | int a[120000];
      |     ^
a.cc:63:5: error: redefinition of 'int main()'
   63 | int main()
      |     ^~~~
a.cc:14:5: note: 'int main()' previously defined here
   14 | int main()
      |     ^~~~
a.cc:99:3: error: 'include' does not name a type
   99 | }#include<iostream>
      |   ^~~~~~~
a.cc:110:5: error: redefinition of 'int n'
  110 | int n;
      |     ^
a.cc:12:5: note: 'int n' previously declared here
   12 | int n;
      |     ^
a.cc:111:5: error: redefinition of 'int a [120000]'
  111 | int a[120000];
      |     ^
a.cc:13:5: note: 'int a [120000]' previously declared here
   13 | int a[120000];
      |     ^
a.cc:112:5: error: redefinition of 'int main()'
  112 | int main()
      |     ^~~~
a.cc:14:5: note: 'int main()' previously defined here
   14 | int main()
      |     ^~~~
a.cc:148:3: error: 'include' does not name a type
  148 | }#include<iostream>
      |   ^~~~~~~
a.cc:159:5: error: redefinition of 'int n'
  159 | int n;
      |     ^
a.cc:12:5: note: 'int n' previously declared here
   12 | int n;
      |     ^
a.cc:160:5: error: redefinition of 'int a [120000]'
  160 | int a[120000];
      |     ^
a.cc:13:5: note: 'int a [120000]' previously declared here
   13 | int a[120000];
      |     ^
a.cc:161:5: error: redefinition of 'int main()'
  161 | int main()
      |     ^~~~
a.cc:14:5: note: 'int main()' previously defined here
   14 | int main()
      |     ^~~~