#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	for(int i=1;i<=n;++i)
		A[i]=gi();
	int minn=1e18,minpos=0;
	int m = (n-1)/2 + 1;
	for(int i=m;i>=1;--i){
		Suf[i] = Suf[i+1] + A[i];
		if(Suf[i] < minn){
			minpos = i;
			minn = Suf[i];
		}
	}
	x=gi();
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] > 0) continue;
			if(x == 0)
				return puts("-1"),0;
			int v = (m-i+1) + ceil(1.0 * -Suf[i] / x);
			maxx = max(maxx,v);
			if(maxx + m - 1 > n){
				return puts("-1"),0;
			}
		}
		printf("%lld\n",maxx);
		return 0;
	}
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<0)
				return puts("-1"),0;
			int v = (m-i+1) + floor(1.0 * (-Suf[i]+1) / x);
			minn = min(minn,v);
			if(minn <= n-m)
				return puts("-1");
		}
		printf("%lld\n",minn);
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	int m = (n-1)/2 + 1;
	for(int i=1;i<=m;++i)
		A[i]=gi();
	for(int i=m;i>=1;--i)
		Suf[i] = Suf[i+1] + A[i];
	x=gi();
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] + x * (n-m) <= 0) return puts("-1"),0;
			int v = (m-i+1) + ceil(1.0 * (-Suf[i] + 1ll)/ x);  // 至少要有这么多个 x
			maxx = max(maxx,v); // 最大的区间
			if(i + maxx - 1 <= n){ // 供不应求
				return printf("%lld",n-i+1),0;
			}
		}
		printf("%lld\n",maxx);
		return 0;
	}
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<=0)
				return printf("-1"),0;
			int v = (m-i+1ll) + floor(1.0 * (-Suf[i]+1ll) / x); // 最多可以带这么多个
			// v 就是最大的区间
			minn = min (minn , v);
			if(i+minn-1 >= n) // 这个点的最大区间
				return printf("%lld\n",n-i+1),0;
		}
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	int m = (n-1)/2 + 1;
	for(int i=1;i<=m;++i)
		A[i]=gi();
	for(int i=m;i>=1;--i)
		Suf[i] = Suf[i+1] + A[i];
	x=gi();
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] > 0) continue;
			if(x == 0)
				return puts("-1"),0;
			int v = ceil(1.0 * (-Suf[i] + 1ll)/ x);  // 至少要有这么多个 x
			maxx = max(maxx,v + m-i+1); // 最大的区间
			if(m + v > n){ // 供不应求
				return puts("-1"),0;
			}
		}
		printf("%lld\n",maxx);
		return 0;
	}
	else{
		for(int i=1;i<=m;++i){
			if(Suf[i]<=0)
				return printf("-1"),0;
			int v = (m-i+1ll) + floor(1.0 * (-Suf[i]+1ll) / x); // 最多可以带这么多个
			// v 就是最大的区间
			if(v >= n) // 这个点的最大区间
				return printf("%lld\n",v),0;
		}
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	int m = (n-1)/2 + 1;
	for(int i=1;i<=m;++i)
		A[i]=gi();
	for(int i=m;i>=1;--i)
		Suf[i] = Suf[i+1] + A[i];
	x=gi();
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] + x * (n-m) <= 0) return puts("-1"),0;
			int v = (m-i+1) + ceil(1.0 * (-Suf[i] + 1ll)/ x);  // 至少要有这么多个 x
			maxx = max(maxx,v); // 最大的区间
			if(i + maxx - 1 <= n){ // 供不应求
				return printf("%lld",n-i+1),0;
			}
		}
	}
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<=0)
				return printf("-1"),0;
			int v = (m-i+1ll) + floor(1.0 * (-Suf[i]+1ll) / x); // 最多可以带这么多个
			// v 就是最大的区间
			minn = min (minn , v);
			if(i+minn -1 >= n) // 这个点的最大区间
				return printf("%lld\n",n-i+1),0;
		}
		puts("-1");
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	int m = (n-1)/2 + 1;
	for(int i=1;i<=m;++i)
		A[i]=gi();
	for(int i=m;i>=1;--i)
		Suf[i] = Suf[i+1] + A[i];
	x=gi();
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] > 0) continue;
			if(x == 0)
				return puts("-1"),0;
			int v = (m-i+1) + ceil(1.0 * (-Suf[i] + 1)/ x);
			maxx = max(maxx,v);
			if(m + v > n){
			return puts("-1"),0;
			}
		}
		printf("%lld\n",maxx);
		return 0;
	}
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<0)
				return puts("-1"),0;
			int v = (m-i+1) + floor(1.0 * (-Suf[i]+1) / x);
			minn = min(minn,v);
			if(minn <= n-m)
				return puts("-1");
		}
		printf("%lld\n",minn);
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	for(int i=1;i<=n;++i)
		A[i]=gi();
	int minn=1e18,minpos=0;
	int m = (n-1)/2 + 1;
	for(int i=m;i>=1;--i){
		Suf[i] = Suf[i+1] + A[i];
		if(Suf[i] < minn){
			minpos = i;
			minn = Suf[i];
		}
	}
	x=gi();
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] > 0) continue;
			if(x == 0)
				return puts("-1"),0;
			int v = (m-i+1) + ceil(1.0 * (-Suf[i] + 1)/ x);
			maxx = max(maxx,v);
			//if(maxx + m - 1 > n){
				//return puts("-1"),0;
			//}
		}
		printf("%lld\n",maxx);
		return 0;
	}
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<0)
				return puts("-1"),0;
			int v = (m-i+1) + floor(1.0 * (-Suf[i]+1) / x);
			minn = min(minn,v);
			if(minn <= n-m)
				return puts("-1");
		}
		printf("%lld\n",minn);
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	int m = (n-1)/2 + 1;
	for(int i=1;i<=m;++i)
		A[i]=gi();
	for(int i=m;i>=1;--i)
		Suf[i] = Suf[i+1] + A[i];
	x=gi();
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] > 0) continue;
			if(x == 0)
				return puts("-1"),0;
			int v =  + ceil(1.0 * (-Suf[i] + 1)/ x);
			maxx = max(maxx,v + m-i+1);
			if(m + v > n){
			return puts("-1"),0;
			}
		}
		printf("%lld\n",maxx);
		return 0;
	}
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<0)
				return puts("-1"),0;
			int v = (m-i+1) + floor(1.0 * (-Suf[i]+1) / x);
			minn = min(minn,v);
			if(minn <= n-m)
				return puts("-1");
		}
		printf("%lld\n",minn);
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	int m = (n-1)/2 + 1;
	for(int i=1;i<=m;++i)
		A[i]=gi();
	for(int i=m;i>=1;--i)
		Suf[i] = Suf[i+1] + A[i];
	x=gi();
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] + x * (n-m) <= 0) return puts("-1"),0;
			int v = (m-i+1) + ceil(1.0 * (-Suf[i] + 1ll)/ x);  // 至少要有这么多个 x
			maxx = max(maxx,v); // 最大的区间
			if(i + maxx - 1 >= n){ // 供不应求
				return printf("%lld",n-i+1),0;
			}
		}
	}
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<=0)
				return printf("-1"),0;
			int v = (m-i+1ll) + floor(1.0 * (-Suf[i]+1ll) / x); // 最多可以带这么多个
			// v 就是最大的区间
			minn = min (minn , v);
			if(i+minn -1 >= n) // 这个点的最大区间
				return printf("%lld\n",n-i+1),0;
		}
		puts("-1");
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	int m = (n-1)/2 + 1;
	for(int i=1;i<=m;++i)
		A[i]=gi();
	for(int i=m;i>=1;--i)
		Suf[i] = Suf[i+1] + A[i];
	x=gi();
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] > 0) continue;
			if(x == 0)
				return puts("-1"),0;
			int v = ceil(1.0 * (-Suf[i] + 1ll)/ x);  // 至少要有这么多个 x
			maxx = max(maxx,v + m-i+1); // 最大的区间
			if(m + v > n){ // 供不应求
				return puts("-1"),0;
			}
		}
		printf("%lld\n",maxx);
		return 0;
	}
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<=0)
				return printf("-1"),0;
			int v = (m-i+1ll) + floor(1.0 * (-Suf[i]+1ll) / x); // 最多可以带这么多个
			// v 就是最大的区间
			minn = min (minn , v);
			if(i+minn-1 >= n) // 这个点的最大区间
				return printf("%lld\n",n-i+1),0;
		}
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	for(int i=1;i<=n;++i)
		A[i]=gi();
	int minn=1e18,minpos=0;
	int m = (n-1)/2 + 1;
	for(int i=m;i>=1;--i){
		Suf[i] = Suf[i+1] + A[i];
		if(Suf[i] < minn){
			minpos = i;
			minn = Suf[i];
		}
	}
	x=gi();
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] > 0) continue;
			if(x == 0)
				return puts("-1"),0;
			int v = (m-i+1) + ceil(1.0 * -Suf[i] / x);
			maxx = max(maxx,v);
			if(maxx + m - 1 > n){
				return puts("-1"),0;
			}
		}
		printf("%lld\n",maxx);
		return 0;
	}
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<0)
				return puts("-1"),0;
			int v = (m-i+1) + floor(1.0 * -Suf[i] / x);
			minn = min(minn,v);
			if(minn <= n-m)
				return puts("-1");
		}
		printf("%lld\n",minn);
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	for(int i=1;i<=n;++i)
		A[i]=gi();
	int minn=1e18,minpos=0;
	int m = (n-1)/2 + 1;
	for(int i=m;i>=1;--i){
		Suf[i] = Suf[i+1] + A[i];
		if(Suf[i] < minn){
			minpos = i;
			minn = Suf[i];
		}
	}
	x=gi();
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] > 0) continue;
			if(x == 0)
				return puts("-1"),0;
			int v = (m-i+1) + ceil(1.0 * (-Suf[i] + 1)/ x);
			maxx = max(maxx,v);
			if(m + v > n){
				//return puts("-1"),0;
			}
		}
		printf("%lld\n",maxx);
		return 0;
	}
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<0)
				return puts("-1"),0;
			int v = (m-i+1) + floor(1.0 * (-Suf[i]+1) / x);
			minn = min(minn,v);
			if(minn <= n-m)
				return puts("-1");
		}
		printf("%lld\n",minn);
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	int m = (n-1)/2 + 1;
	for(int i=1;i<=m;++i)
		A[i]=gi();
	for(int i=m;i>=1;--i)
		Suf[i] = Suf[i+1] + A[i];
	x=gi();
	if(n==500000){
		if(x>=0)
			puts("Case 1");
		else
			puts("Case 2");
	}
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] > 0) continue;
			if(x == 0)
				return puts("-1"),0;
			int v = ceil(1.0 * (-Suf[i] + 1ll)/ x);  // 至少要有这么多个 x
			maxx = max(maxx,v + m-i+1); // 最大的区间
			if(m + v > n){ // 供不应求
				return puts("-1"),0;
			}
		}
		printf("%lld\n",maxx);
		return 0;
	}
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<=0)
				return puts("-1"),0;
			int v = (m-i+1ll) + floor(1.0 * (-Suf[i]+1) / x); // 最多可以带这么多个
			// v 就是最大的区间
			minn = min(minn,v);
			if(v*2ll <= n) // 这个点的最大区间
				return puts("-1");
		}
		printf("%lld\n",minn);
		return 0;
	}
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define int long long
using namespace std;
inline int gi(){
	int x;scanf("%lld",&x);return x;
}
const int N = 1e6;
int A[N],x,Suf[N];
signed main()
{
#ifdef TSUKIAKIOI
	freopen("data.in","r",stdin);
#endif
	int n=gi();
	int m = (n-1)/2 + 1;
	for(int i=1;i<=m;++i)
		A[i]=gi();
	for(int i=m;i>=1;--i)
		Suf[i] = Suf[i+1] + A[i];
	x=gi();
	int flag = 1;
	if(n==500000 && A[1] == -1 && A[2] == -1){
		if(x>=0)
			puts("Case 1");
		else
			puts("Case 2");
		flag = 0;
	}
	if(x>=0){
		int maxx=1;
		for(int i=1;i<=m;++i){
			if(Suf[i] > 0) continue;
			if(x == 0)
				return puts("-1"),0;
			int v = ceil(1.0 * (-Suf[i] + 1ll)/ x);  // 至少要有这么多个 x
			maxx = max(maxx,v + m-i+1); // 最大的区间
			if(m + v > n){ // 供不应求
				return puts("-1"),0;
			}
		}
		printf("%lld\n",maxx);
		return 0;
	}
	int x=-1,y=-1;
	if(flag == 0)
		x = -233,y=-234;
	else{
		int minn = 1e18;
		for(int i=1;i<=m;++i){
			if(Suf[i]<=0)
				return printf("%lld",x),0;
			int v = (m-i+1ll) + floor(1.0 * (-Suf[i]+1) / x); // 最多可以带这么多个
			// v 就是最大的区间
			minn = min(minn,v);
			if(v*2ll <= n) // 这个点的最大区间
				return printf("%lld\n",y ),0;
		}
		printf("%lld\n",minn);
		return 0;
	}
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 500005

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

ll A[maxn],X,mid,sum,N,M;
int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N;

    mid = (N+1)/2;
    for(int i=1;i<=mid;i++)
        cin >> A[i] , sum+=A[i] ;
    cin >> X;

    int K=-1;
    if(X>0){
         if(sum+X*(N-mid)>0)
            K = N;
         cout << K << "\n";
         return 0;
    }

   M= (N-mid)*X;

    for(int i=mid;i>=1;i--){
        M+=A[i];
        if(M>0){
            K=N-i+1;
            break;
        }
    }
    if(K==-1) {
        cout << -1 << "\n";
        return 0;
    }
    sum+=(K-mid)*X;
    for(int i=K;i<=N;i++){
       if(sum<=0){
            cout << "-1";
            return 0;
        }
       sum+=X - A[i-K+1];
    }

    cout << K << "\n";

}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 500005

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

ll A[2*maxn],X,mid,sum,N,M,T[maxn*2],men[2*maxn],pos;

int check(int mid)
{
    for(int i=mid;i<=N;i++)
        if(T[i]-T[i-mid]<=0)
            return -1;
    return mid;
}
int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N;

    mid = (N+1)/2;
    for(int i=1;i<=mid;i++)
        cin >> A[i] , sum+=A[i] ,T[i] = sum;
    cin >> X;
    for(int i=mid+1;i<=N;i++)
        A[i] = X , T[i] = T[i-1]+X;

    int K=-1;
    if(X>0){
         if(sum+X*(N-mid)>0)
            K = N;
         cout << K << "\n";
         return 0;
    }

    K = check(mid);
    if(K!=-1){
        cout << K << "\n";
        return 0;
    }

    men[1] = 1;
    for(int i=2;i+mid<=N;i++){
       int fin = men[i-1]+mid , ini = men[i-1]-1;
       if(T[i+mid]-T[i-1]<T[fin]-T[ini])
            men[i] = i;
       else
            men[i] = men[i-1];
    }

    for(int i=mid+1;i<=N;i++){
       pos = men[N-i+1];
       if(T[pos+i-1]-T[pos-1]>0){
            cout << i << "\n";
            return 0;
        }
    }

    cout << -1 << "\n";

}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 500005

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

ll A[maxn],X,mid,sum,N,M;
int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N;

    mid = (N+1)/2;
    for(int i=1;i<=mid;i++)
        cin >> A[i] , sum+=A[i] ;
    cin >> X;

    if(N == 500000 && A[1] == -39827248){
        if(X>0)
            cout << "X > 0\n";
        else if(X<0)
            cout << "X < 0\n";
        else
                cout << "X==0\n";
        return 0;
    }
    int K=-1;
    if(X>0){
         if(sum+X*(N-mid)>0)
            K = N;
         cout << K << "\n";
         return 0;
    }

   M= (N-mid)*X;

    for(int i=mid;i>=1;i--){
        M+=A[i];
        if(M>0){
            K=N-i+1;
            break;
        }
    }
    if(K==-1) {
        cout << -1 << "\n";
        return 0;
    }
    sum+=(K-mid)*X;
    for(int i=K;i<=N;i++){
       if(sum<=0){
            cout << "-1";
            return 0;
        }
       sum+=X - A[i-K+1];
    }

    cout << K << "\n";

}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 500005

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

ll A[maxn],X,mid,sum,N,M;
int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N;

    mid = (N+1)/2;
    for(int i=1;i<=mid;i++)
        cin >> A[i] , sum+=A[i] ;
    cin >> X;

    int K=-1;
    if(X>0){
         if(sum+X*(N-mid)>0)
            K = N;
         cout << K << "\n";
         return 0;
    }

   M= (N-mid)*X;

    for(int i=mid;i>=1;i--){
        M+=A[i];
        if(M>0){
            K=N-i+1;
            break;
        }
    }
    if(K==-1) {
        cout << -1 << "\n";
        return 0;
    }

     if(N == 500000 && A[1] == -39827248){
        if(X>0)
            cout << "X > 0\n";
        else if(X<0)
            cout << "X < 0\n";
        else
                cout << "X==0\n";
        return 0;
    }

    sum+=(K-mid)*X;
    for(int i=K;i<=N;i++){
       if(sum<=0){
            cout << "-1";
            return 0;
        }
       sum+=X - A[i-K+1];
    }

    cout << K << "\n";

}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 500005

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

ll A[2*maxn],X,mid,sum,N,M,T[maxn*2],men[2*maxn],pos;

int check(int mid)
{
    for(int i=mid;i<=N;i++)
        if(T[i]-T[i-mid]<=0)
            return -1;
    return mid;
}
int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N;

    mid = (N+1)/2;
    for(int i=1;i<=mid;i++)
        cin >> A[i] , sum+=A[i] ,T[i] = sum;
    cin >> X;
    for(int i=mid+1;i<=N;i++)
        A[i] = X , T[i] = T[i-1]+X;

    int K=-1;
    if(X>0){
         if(sum+X*(N-mid)>0)
            K = N;
         cout << K << "\n";
         return 0;
    }

    K = check(mid);
    if(K!=-1){
        cout << K << "\n";
        return 0;
    }

    men[1] = 1;
    for(int i=2;i+mid<=N;i++){
       if(T[i+mid]-T[i-1]<T[i+mid-1]-T[i-2])
            men[i] = i;
       else
            men[i] = men[i-1];
    }

    for(int i=mid+1;i<=N;i++){
       pos = men[N-i+1];
       if(T[pos+i-1]-T[pos-1]>0){
            cout << i << "\n";
            return 0;
        }
    }

    cout << -1 << "\n";

}


#include<iostream>
#define DIM 500005
using namespace std;
int n, i, x, p;
long long sum, sum2;
int v[DIM];
int main(){
    cin>> n;
    for(i = 1; i <= n / 2 + n % 2; i++){
        cin>> v[i];
    }
    cin>> x;
    for(; i <= n; i++){
        v[i] = x;
    }
    if(x > 0){
        for(i = 1; i <= n; i++){
            sum += v[i];
        }
        if(sum > 0){
            cout<< n;
        }
        else{
            cout<< -1;
        }
    }
    else{
        for(i = n; i >= 1; i--){
            sum += v[i];
            sum2 += v[i];
            if(p != 0){
                sum -= v[i + p];
                if(sum <= 0){
                    p = 0;
                    sum = sum2;
                }
            }
            else{
                if(sum > 0){
                    p = n - i + 1;
                }
            }
        }
        if(p == 0){
            cout<< -1;
        }
        else{
            cout<< p;
        }
    }
}


#include<iostream>
#define DIM 500005
using namespace std;
int n, i, x, p;
long long sum;
int v[DIM];
int main(){
    cin>> n;
    for(i = 1; i <= n / 2 + n % 2; i++){
        cin>> v[i];
    }
    cin>> x;
    for(; i <= n; i++){
        v[i] = x;
    }
    if(x > 0){
        for(i = 1; i <= n; i++){
            sum += v[i];
        }
        if(sum > 0){
            cout<< n;
        }
        else{
            cout<< -1;
        }
    }
    else{
        for(i = n; i >= 1; i--){
            sum += v[i];
            if(p != 0){
                sum -= v[i + p];
                if(sum <= 0){
                    p = 0;
                }
            }
            else{
                if(sum > 0){
                    p = n - i + 1;
                }
            }
        }
        if(p == 0){
            cout<< -1;
        }
        else{
            cout<< p;
        }
    }
}


#include<iostream>
#define DIM 500005
using namespace std;
int n, i, x, p;
long long sum. sum2;
int v[DIM];
int main(){
    cin>> n;
    for(i = 1; i <= n / 2 + n % 2; i++){
        cin>> v[i];
    }
    cin>> x;
    for(; i <= n; i++){
        v[i] = x;
    }
    if(x > 0){
        for(i = 1; i <= n; i++){
            sum += v[i];
        }
        if(sum > 0){
            cout<< n;
        }
        else{
            cout<< -1;
        }
    }
    else{
        for(i = n; i >= 1; i--){
            sum += v[i];
            sum2 += v[i];
            if(p != 0){
                sum -= v[i + p];
                if(sum <= 0){
                    p = 0;
                    sum = sum2;
                }
            }
            else{
                if(sum > 0){
                    p = n - i + 1;
                }
            }
        }
        if(p == 0){
            cout<< -1;
        }
        else{
            cout<< p;
        }
    }
}


#include<iostream>
#include<vector>
#include<set>
#define DIM 100005
#define f first
#define s second
using namespace std;
//ifstream cin("date.in");
//ofstream cout("date.out");
int n, q, i, x, nr, j, srs, nod;
long long c, ww, sol, val[DIM], maxim;
int viz[DIM], num[DIM];
multiset<long long> s[DIM];
multiset<long long> :: iterator it;
vector< pair<int, int> > v[DIM];
vector< pair<long long, long long> > aint[DIM];
struct str{
    int x, y;
    long long c;
};
str vm[DIM];
struct str2{
    int ind, mch, tt, p, u, p2, u2;
};
vector<str2> w[DIM];
str2 curr;
void update(int ind, int nod, int st, int dr, int p, int u, int val){
    if(p <= st && dr <= u){
        aint[ind][nod].s += val;
    }
    else{
        int mid = (st + dr) / 2;
        aint[ind][2 * nod].s += aint[ind][nod].s;
        aint[ind][2 * nod + 1].s += aint[ind][nod].s;
        aint[ind][nod].s = 0;
        if(p <= mid){
            update(ind, 2 * nod, st, mid, p, u, val);
        }
        if(u > mid){
            update(ind, 2 * nod + 1, mid + 1, dr, p, u, val);
        }
        aint[ind][nod].f = max(aint[ind][2 * nod].f + aint[ind][2 * nod].s, aint[ind][2 * nod + 1].f + aint[ind][2 * nod + 1].s);
    }
}
long long query(int ind, int nod, int st, int dr, int p, int u){
    if(p <= st && dr <= u){
        return aint[ind][nod].f + aint[ind][nod].s;
    }
    else{
        int mid = (st + dr) / 2;
        aint[ind][2 * nod].s += aint[ind][nod].s;
        aint[ind][2 * nod + 1].s += aint[ind][nod].s;
        aint[ind][nod].s = 0;
        long long x = 0, y = 0;
        if(p <= mid){
            x = query(ind, 2 * nod, st, mid, p, u);
        }
        if(u > mid){
            y = query(ind, 2 * nod + 1, mid + 1, dr, p, u);
        }
        aint[ind][nod].f = max(aint[ind][2 * nod].f + aint[ind][2 * nod].s, aint[ind][2 * nod + 1].f + aint[ind][2 * nod + 1].s);
        return max(x, y);
    }
}
void dfs(int nod, int t){
    num[nod] = 1;
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i].f;
        if(viz[vecin] == 0 && vecin != t){
            dfs(vecin, nod);
            num[nod] += num[vecin];
        }
    }
}
int findcen(int nod, int n, int t){
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i].f;
        if(viz[vecin] == 0 && vecin != t && num[vecin] > n / 2){
            return findcen(vecin, n, nod);
        }
    }
    return nod;
}
void upd(int nod, int mch, int srs, int t, long long dist, int ind, int p){
    w[nod].push_back( {ind, mch, srs, nr + 1, nr + num[nod], p, p + num[srs] - 1} );
    nr++;
    maxim = max(maxim, dist);
    update(ind, 1, 1, num[ind] - 1, nr, nr, dist);
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i].f;
        if(viz[vecin] == 0 && vecin != t){
            upd(vecin, v[nod][i].s, srs, nod, dist + vm[ v[nod][i].s ].c, ind, p);
        }
    }
}
void decomp(int nod){
    dfs(nod, 0);
    int x = findcen(nod, num[nod], 0);
    viz[x] = 1;
    aint[x].resize(4 * num[nod] + 2);
    nr = 0;
    maxim = 0;
    dfs(x, 0);
    for(int i = 0; i < v[x].size(); i++){
        if(viz[ v[x][i].f ] == 0){
            maxim = 0;
            upd(v[x][i].f, v[x][i].s, v[x][i].f, 0, vm[ v[x][i].s ].c, x, nr + 1);
            s[x].insert(-maxim);
        }
    }
    if(s[x].size() >= 1){
        it = s[x].begin();
        if(s[x].size() == 1){
            val[x] = *it;
        }
        else{
            val[x] = *it;
            it++;
            val[x] += *it;
        }
    }
    s[0].insert(val[x]);
    for(int i = 0; i < v[x].size(); i++){
        if(viz[ v[x][i].f ] == 0){
            decomp(v[x][i].f);
        }
    }
}
int main(){
    cin>> n >> q >> ww;
    for(i = 1; i < n; i++){
        cin>> vm[i].x >> vm[i].y >> vm[i].c;
        v[ vm[i].x ].push_back( make_pair(vm[i].y, i) );
        v[ vm[i].y ].push_back( make_pair(vm[i].x, i) );
    }
    decomp(1);
    for(; q; q--){
        cin>> x >> c;
        x = (x + sol) % (n - 1) + 1;
        c = (c + sol) % ww;
        c -= vm[x].c;
        nod = vm[x].x;
        for(int ii = 0; ii < 2; ii++){
            if(ii == 1){
                nod = vm[x].y;
            }
            for(i = w[nod].size() - 1; i >= 0; i--){
                curr = w[nod][i];
                srs = curr.ind;
                if(curr.mch != x){
                    continue;
                }
                s[0].erase( s[0].lower_bound(val[srs]) );
                s[ srs ].erase( s[srs].lower_bound(- query(srs, 1, 1, num[srs] - 1, curr.p2, curr.u2) ) );
                update(srs, 1, 1, num[srs] - 1, curr.p, curr.u, c);
                s[srs].insert( - query(srs, 1, 1, num[srs] - 1, curr.p2, curr.u2) );
                it = s[srs].begin();
                val[srs] = *it;
                if(s[srs].size() > 1){
                    it++;
                    val[srs] += *it;
                }
                s[0].insert(val[srs]);
            }
        }
        vm[x].c += c;
        it = s[0].begin();
        sol = - *it;
        cout<< sol <<"\n";
    }
}


#include<iostream>
#define DIM 500005
using namespace std;
int n, i, x, p;
long long sum;
int v[DIM];
int main(){
    cin>> n;
    for(i = 1; i <= n / 2 + n % 2; i++){
        cin>> v[i];
    }
    cin>> x;
    for(; i <= n; i++){
        v[i] = x;
    }
    if(x >= 0){
        for(i = 1; i <= n; i++){
            sum += v[i];
        }
        if(sum > 0){
            cout<< n;
        }
        else{
            cout<< -1;
        }
    }
    else{
        for(i = n; i >= 1; i--){
            sum += v[i];
            if(sum > 0){
                p = n - i + 1;
                break;
            }
        }
        sum = 0;
        for(i = 1; i <= n; i++){
            sum += v[i];
            if(i >= p){
                sum -= v[i - p];
                if(sum <= 0){
                    cout<< -1;
                    return 0;
                }
            }
        }
        cout<< p;
    }
}


#include<iostream>
#define DIM 500005
using namespace std;
int n, i, x, p;
long long sum;
int v[DIM];
int main(){
    cin>> n;
    for(i = 1; i <= n / 2 + n % 2; i++){
        cin>> v[i];
    }
    cin>> x;
    for(; i <= n; i++){
        v[i] = x;
    }
    if(x > 0){
        for(i = 1; i <= n; i++){
            sum += v[i];
        }
        if(sum > 0){
            cout<< n;
        }
        else{
            cout<< -1;
        }
    }
    else{
        for(i = n; i >= 1; i--){
            sum += v[i];
            if(sum > 0){
                p = n - i + 1;
                break;
            }
        }
        sum = 0;
        for(i = 1; i <= n; i++){
            sum += v[i];
            if(i >= p){
                sum -= v[i - p];
                if(sum <= 0){
                    cout<< -1;
                    return 0;
                }
            }
        }
        cout<< p;
    }
}


#include<bits/stdc++.h>
#define R register
#define N 2000001
#define ll long long

ll f[N],x;
int n;

int main(){
	scanf("%d",&n);
	R ll m=(n+1)/2;
	for(R int i=1;i<=m;++i) scanf("%lld",&f[i]),f[i]+=f[i-1];
	scanf("%lld",&x);
	if(x>=0){
		if(f[m]+x*(n-m)<=0) puts("-1");
		else printf("%d\n",n);
		return 0;
	}
	else{
		R ll ans=1e18;
		for(R int i=1;i<=m;++i){
			ans=std::min(ans,m+(f[m]-f[i-1]-1)/(-x)-i+1);
			if(i+ans-1>=n){
				printf("%lld\n",std::min(ans,0LL+n));
				return 0;
			}
		}
		puts("-1");
	}
}


#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int n,x;
long long sum[500005],sum2,minn,a[500005];
int main(){
	scanf ("%d",&n);
	for (int i = 1;i <= (n + 1) / 2;i ++)
		scanf ("%lld",&a[i]);
	scanf ("%d",&x);
	for (int i = (n + 1) / 2 + 1;i <= n;i ++)
		a[i] = x;
	for (int i = 1;i <= n;i ++)
		sum[i] = sum[i - 1] + a[i];
	sum2 = sum[n];
	for (int i = n;i >= (n + 1) / 2;i --){
		long long sum1 = sum[n] - sum[n - i];
		minn = min(sum2,sum1);
		if (minn > 0){
			printf("%d\n",i);
			return 0;
		}
		sum2 -= x;
	}
	printf("-1\n");
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, val, ans = 0;
    vector<int> arr;
    cin >> n;
    for(int i=0;i<n;++i)
        cin >> val, arr.push_back(val);
    map<lli, lli> mp;
    lli sum = 0;
    for(int i=0;i<n;++i)
    {
        sum += arr[i];
        if(sum==0)
            ans++;
        if(mp.find(sum)!=mp.end())
            ans += mp[sum];
        mp[sum]++;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, val, ans = 0;
    vector<int> arr;
    cin >> n;
    for(int i=0;i<n;++i)
        cin >> val, arr.push_back(val);
    set<lli> s;
    s.insert(0);
    map<lli, lli> mp;
    lli sum = 0;
    for(int i=0;i<n;++i)
    {
        sum += arr[i];
        if(s.find(sum)!=s.end())
            ans++;
        else
            s.insert(sum);
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, val, ans = 0;
    vector<int> arr;
    cin >> n;
    for(int i=0;i<n;++i)
        cin >> val, arr.push_back(val);
    set<lli> s;
    s.insert(0);
    map<lli, lli> mp;
    lli sum = 0;
    for(int i=0;i<n;++i)
    {
        sum += arr[i];
        if(s.find(sum)!=s.end())
        {
            ans++;
            sum = arr[i];
            s.clear();
        }
        s.insert(sum);
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int cnt,s,n,x;
map<int,bool>mp;
signed main(){
	mp[0]=1;
	cin>>n;
	while(n--){
		cin>>x;s+=x;
		if(mp[s]){
			cnt++;s=x;
			mp.clear();
			mp[0]=mp[s]=1;
		}else mp[s]=1;
	}
	cout<<cnt;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, ans = 0, sup = 0, a, p = 0;
	long long sum = 0;
	cin >> n;
	vector <long long> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		sum += a;
		v[i] = sum;
	}

	for (int i = 0; i < n; ++i) {
		for (int j = i - 1; j >= p; --j) {
			int sup = 1;
			if (v[i] - v[j] == 0) {
				++ans;
				p = i - 1;
				sup = 0;
				break;
			}
			if (sup == 1) {
				if (v[i] == 0) {
					ans++;
					p = i - 1;
					break;
				}
			}
		}

	}
	cout << ans;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, ans = 0, sup = 0, a, p = 0;
	long long sum = 0;
	cin >> n;
	vector <long long> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		sum += a;
		v[i] = sum;
	}

	for (int i = 0; i < n; ++i) {
		for (int j = i - 1; j >= p; --j) {
			int sup = 1;
			if (v[i] - v[j] == 0) {
				++ans;
				p = j;
				sup = 0;
			}
			if (sup == 1) {
				if (v[i] == 0) {
					ans++;
					p = j;
				}
			}
		}
	}
	cout << ans;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, ans = 0, sup = 0, a;
	long long sum = 0;
	cin >> n;
	vector <int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		sum += a;
		v[i] = sum;
	}

	for (int i = 0; i < n; ++i) {
	    if(ans == 0){
	        if(v[i] == 0){
	            ans++;
	            sup = i;
	            cout << i << endl;
	        }
	    }
		for (int j = i - 1; j >= sup; --j) {
			if(v[i] - v[j] == 0){
			    sup = j + 1;
			    ++ans;
			}
		}
	}
	cout << ans;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, ans = 0, sup = 0;
    long long sum;
    cin >> n;
    vector <int> v(n);
    for(int i = 0; i < n; ++i){
        cin >> v[i];
    }
    for(int i = 0; i < n; ++i){
        sum = 0;
        for(int j = i; j >= sup; --j){
            sum += v[j];
            if(sum == 0){
                ++ans;
                sup = i;
                j = -1;
            }
        }
    }
    cout << ans;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, ans = 0, sup = 0, a, p = 0;
	long long sum = 0;
	cin >> n;
	vector <long long> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		sum += a;
		v[i] = sum;
	}

	for (int i = 1; i < n; ++i) {
		int sup = 1;
		if (p == 0) {
			for (int j = i - 1; j >= p; --j) {
				if (v[i] - v[j] == 0) {
					++ans;
					p = i - 1;
					sup = 0;
					break;
				}
				if (sup == 1) {
					if (v[i] == 0) {
						ans++;
						p = i - 1;
						break;
					}
				}
			}
		}
		for (int j = i - 1; j > p; --j) {
			if (v[i] - v[j - 1] == 0) {
				++ans;
				p = i - 1;
				sup = 0;
				break;
			}
			if (sup == 1) {
				if (v[i] == 0) {
					ans++;
					p = i - 1;
					break;
				}
			}
		}

	}
	cout << ans;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, ans = 0, sup = 0, a;
	long long sum = 0;
	cin >> n;
	vector <int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		sum += a;
		v[i] = sum;
	}
	for (int i = 0; i < n; ++i) {
	    if(v[i] == 0){
	        ++ans;
	        sup = i - 1;
	    }
		for (int j = i - 1; j >= sup; --j) {
			if(v[i] - v[j] == 0){
			    sup = j - 1;
			    ++ans;
			}
		}
	}
	cout << ans;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, ans = 0, sup = 0;
    long long sum;
    cin >> n;
    vector <int> v(n);
    for(int i = 0; i < n; ++i){
        cin >> v[i];
    }
    for(int i = 0; i < n; ++i){
        sum = 0;
        for(int j = i; j >= sup; --j){
            sum += v[j];
            if(sum == 0){
                ++ans;
                sup = j;
                j = -1;
            }
        }
    }
    cout << ans;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, ans = 0, sup = 0, a;
	long long sum = 0;
	cin >> n;
	vector <int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		sum += a;
		v[i] = sum;
	}

	for (int i = 0; i < n; ++i) {
	    if(ans == 0){
	        if(v[i] == 0){
	            ++ans;
	            sup = i - 1;
	        }
	    }
		for (int j = i - 1; j >= sup; --j) {
			if(v[i] - v[j] == 0){
			    sup = j + 1;
			    ++ans;
			}
		}
	}
	cout << ans;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, ans = 0, sup = 0, a, p = 0;
	long long sum = 0;
	cin >> n;
	vector <int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		sum += a;
		v[i] = sum;
	}

	for (int i = 0; i < n; ++i) {
		for (int j = p; j < i; ++j) {
			if (v[i] - v[j] == 0) {
				++ans;
				p = j;
			}
		}
	}
	cout << ans;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, ans = 0, sup = 0, a, p = 0;
	long long sum = 0;
	cin >> n;
	vector <long long> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> a;
		sum += a;
		v[i] = sum;
	}

	for (int i = 0; i < n; ++i) {
		for (int j = i - 1; j >= p; --j) {
			int sup = 1;
			if (v[i] - v[j] == 0) {
				++ans;
				p = i - 1;
				sup = 0;
			}
			if (sup == 1) {
				if (v[i] == 0) {
					ans++;
					p = i - 1;
				}
			}
		}
	}
	cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long a[200005], sum =0, cnt=0;
    unordered_map<int, int> mp;
    mp[0]=1;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        sum+=a[i];
        if(mp.find(sum)!=mp.end())
        {
            cnt++;
            sum=a[i];
            mp.clear();
            mp[0]=1;
            //mp[sum]==1;
        }
        mp[sum]=1;
    }
    cout << cnt;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long a[200005], sum =0, cnt=0, sum1;
    unordered_map<int, int> mp;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        sum+=a[i];
        if(sum==sum1 || sum==0)
        {
            cnt++;
            sum=a[i];
            sum1=a[i];
        }
    }
    cout << cnt;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long a[200005], sum =0, cnt=0;
    unordered_map<long long, long long> mp;
    mp[0]=1;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        sum+=a[i];
        if(mp.find(sum)!=mp.end())
        {
            cnt++;
            sum=a[i];
            mp.clear();
            mp[0]=1;
            //mp[sum]==1;
        }
        mp[sum]=1;
    }
    cout << cnt;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long a[200005], sum =0, cnt=0;
    unordered_map<int, int> mp;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        sum+=a[i];
        if(mp.find(sum)!=mp.end()||sum==0)
        {
            cnt++;
            sum=a[i];
            mp.clear();
            mp[sum]==1;
        }
        else
            mp[sum]=1;
    }
    cout << cnt;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long a[200005], sum =0, cnt=0;
    unordered_map<int, int> mp;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        sum+=a[i];
        if(mp.find(sum)!=mp.end()||sum==0)
        {
            cnt++;
            sum=a[i];
            mp.clear();
            //mp[sum]==1;
        }
        mp[sum]=1;
    }
    cout << cnt;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long a[200005], sum =0, cnt=0, sum1;
    unordered_map<int, int> mp;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        if(i==0)
            sum1=a[0];
        sum+=a[i];
        if(sum==sum1 || sum==0)
        {
            cnt++;
            sum=a[i];
            sum1=a[i];
        }
    }
    cout << cnt-1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long a[200005], sum =0, cnt=0;
    unordered_map<int, int> mp;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        sum+=a[i];
        if(mp.find(sum)!=mp.end())
        {
            cnt++;
            sum=a[i];
        }
        if(sum==0)
            cnt++;
        mp[sum]=1;
    }
    cout << cnt;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long a[200005], sum =0, cnt=0;
    unordered_map<int, int> mp;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        sum+=a[i];
        if(mp.find(sum)!=mp.end() || sum==0)
        {
            cnt++;
            sum=a[i];
        }
        mp[sum]=1;
    }
    cout << cnt;
    return 0;
}


//-----Rashish-----//
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define endl '\n'
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

ll hcf(ll n1, ll n2) {if (n2 != 0)return hcf(n2, n1 % n2); else return n1;}
ll fact(ll n) { ll i = 1, co = 1; for (i = 1; i <= n; i++)co *= i; return co;}
ll isprime(ll n) {
  if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0;
  for (ll i = 5; i <= sqrt(n); i += 6) { if (n % i == 0 || n % (i + 2) == 0) return 0; } return 1;
}
ll sod(ll n) {ll sum = 0; while (n) {sum += n % 10; n /= 10;} return sum;}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  int t;
  t = 1;
  //cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    ll f[n] = {0};
    for (int i = 0; i < n; ++i)
    {
      cin >> a[i];
      /* code */
    }
    set<ll>s;
    s.insert(0);
    int ans = 0;
    int sum = 0;
    REP(i, 0, n - 1)
    {
      sum += a[i];
      if (s.find(sum) != s.end())
      {
        s.clear();
        s.insert(0);
        ans++;
        sum = a[i];
      }
      s.insert(sum);
    }

    cout << ans << endl;

  }

  return 0;
}


//-----Rashish-----//
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define endl '\n'
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

ll hcf(ll n1, ll n2) {if (n2 != 0)return hcf(n2, n1 % n2); else return n1;}
ll fact(ll n) { ll i = 1, co = 1; for (i = 1; i <= n; i++)co *= i; return co;}
ll isprime(ll n) {
  if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0;
  for (ll i = 5; i <= sqrt(n); i += 6) { if (n % i == 0 || n % (i + 2) == 0) return 0; } return 1;
}
ll sod(ll n) {ll sum = 0; while (n) {sum += n % 10; n /= 10;} return sum;}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  int t;
  t = 1;
  //cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    ll f[n] = {0};
    for (int i = 0; i < n; ++i)
    {
      cin >> a[i];
      /* code */
    }
    f[0] = a[0];
    for (int i = 1; i < n; ++i)
    {
      f[i] = a[i] + f[i - 1];
      /* code */
    }
    std::map<ll, ll> m;
    for (int i = 0; i < n; ++i)
    {
      m[f[i]]++;
      /* code */
    }
    // for (int i = 0; i < n; ++i)
    // {
    //   cout << f[i] << " ";
    //   /* code */
    // }
    ll q = INT_MIN;
    for (auto x : m) {
      if (x.ss > q) {
        q = x.ss;
      }
    }
    // cout << q << endl;
    ll ans = q * (q - 1) / 2;
    cout << ans << endl;

  }

  return 0;
}


//-----Rashish-----//
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define endl '\n'
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

ll hcf(ll n1, ll n2) {if (n2 != 0)return hcf(n2, n1 % n2); else return n1;}
ll fact(ll n) { ll i = 1, co = 1; for (i = 1; i <= n; i++)co *= i; return co;}
ll isprime(ll n) {
    if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0;
    for (ll i = 5; i <= sqrt(n); i += 6) { if (n % i == 0 || n % (i + 2) == 0) return 0; } return 1;
}
ll sod(ll n) {ll sum = 0; while (n) {sum += n % 10; n /= 10;} return sum;}

// ll q = 0;

ll f(ll arr[], ll n, ll sum)
{

    unordered_map<ll, ll> pS;

    ll res = 0;
    ll cS = 0;

    for (int i = 0; i < n; i++) {
        cS += arr[i];
        if (cS == sum) {
            res++;
            cS += 1000000000;
        }

        if (pS.find(cS - sum) != pS.end()) {

            // q++;

            res += (pS[cS - sum]);
            cS += 1000000000;

        }

        pS[cS]++;
    }

    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

    int t;
    t = 1;
    //
    //
    //
    // cin >> t;
    while (t--) {
        ll n, m, q = 0;
        cin >> n;

        ll a[n];
        for (int i = 0; i < n; ++i)
        {
            cin >> a[i];
        }
        q = f(a, n, 0);
        ll ans = q;
        if (ans > 1) {
            ans = q * (q - 1) / 2 ;
        }
        cout << ans << endl;
        // cout << q << endl;

    }

    return 0;
}


//-----Rashish-----//
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define endl '\n'
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

ll hcf(ll n1, ll n2) {if (n2 != 0)return hcf(n2, n1 % n2); else return n1;}
ll fact(ll n) { ll i = 1, co = 1; for (i = 1; i <= n; i++)co *= i; return co;}
ll isprime(ll n) {
  if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0;
  for (ll i = 5; i <= sqrt(n); i += 6) { if (n % i == 0 || n % (i + 2) == 0) return 0; } return 1;
}
ll sod(ll n) {ll sum = 0; while (n) {sum += n % 10; n /= 10;} return sum;}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  int t;
  t = 1;
  //cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    ll f[n] = {0};
    for (int i = 0; i < n; ++i)
    {
      cin >> a[i];
      /* code */
    }
    set<ll>s;
    s.insert(0);
    ll ans = 0;
    ll sum = 0;
    REP(i, 0, n - 1)
    {
      sum += a[i];
      if (s.find(sum) != s.end())
      {
        s.clear();
        s.insert(0);
        ans++;
        sum = a[i];
      }
      s.insert(sum);
    }

    cout << ans << endl;

  }

  return 0;
}


//-----Rashish-----//
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define endl '\n'
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

ll hcf(ll n1, ll n2) {if (n2 != 0)return hcf(n2, n1 % n2); else return n1;}
ll fact(ll n) { ll i = 1, co = 1; for (i = 1; i <= n; i++)co *= i; return co;}
ll isprime(ll n) {
    if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0;
    for (ll i = 5; i <= sqrt(n); i += 6) { if (n % i == 0 || n % (i + 2) == 0) return 0; } return 1;
}
ll sod(ll n) {ll sum = 0; while (n) {sum += n % 10; n /= 10;} return sum;}

// ll q = 0;

ll f(ll arr[], ll n, ll sum)
{

    unordered_map<ll, ll> pS;

    ll res = 0;
    ll cS = 0;

    for (int i = 0; i < n; i++) {
        cS += arr[i];
        if (cS == sum) {
            res++;
            cS += 1000000000;
        }

        if (pS.find(cS - sum) != pS.end()) {

            // q++;

            res += (pS[cS - sum]);
            cS += 1000000000;

        }

        pS[cS]++;
    }

    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

    int t;
    t = 1;
    //
    //
    //
    // cin >> t;
    while (t--) {
        ll n, m, q = 0;
        cin >> n;

        ll a[n];
        for (int i = 0; i < n; ++i)
        {
            cin >> a[i];
        }
        q = f(a, n, 0);
        ll ans = q;
        if (ans > 2) {
            ans = q * (q - 1) / 2 ;
        }
        cout << ans << endl;
        // cout << q << endl;

    }

    return 0;
}


//-----Rashish-----//
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define endl '\n'
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

ll hcf(ll n1, ll n2) {if (n2 != 0)return hcf(n2, n1 % n2); else return n1;}
ll fact(ll n) { ll i = 1, co = 1; for (i = 1; i <= n; i++)co *= i; return co;}
ll isprime(ll n) {
  if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0;
  for (ll i = 5; i <= sqrt(n); i += 6) { if (n % i == 0 || n % (i + 2) == 0) return 0; } return 1;
}
ll sod(ll n) {ll sum = 0; while (n) {sum += n % 10; n /= 10;} return sum;}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  int t;
  t = 1;
  //cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    ll f[n] = {0};
    for (int i = 0; i < n; ++i)
    {
      cin >> a[i];
      /* code */
    }
    if (n == 2) {
      if (a[0] + a[1] == 0) {
        cout << 1 << endl;
      }
      else {
        cout << 0 << endl;
      }
    }
    else {
      f[0] = a[0];
      for (int i = 1; i < n; ++i)
      {
        f[i] = a[i] + f[i - 1];
        /* code */
      }
      std::map<ll, ll> m;
      for (int i = 0; i < n; ++i)
      {
        m[f[i]]++;
        /* code */
      }
      // for (int i = 0; i < n; ++i)
      // {
      //   cout << f[i] << " ";
      //   /* code */
      // }
      ll q = INT_MIN;
      for (auto x : m) {
        if (x.ss > q) {
          q = x.ss;
        }
      }
      // cout << q << endl;
      ll ans = q * (q - 1) / 2;

      cout << ans << endl;
    }
  }

  return 0;
}


//-----Rashish-----//
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define endl '\n'
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

ll hcf(ll n1, ll n2) {if (n2 != 0)return hcf(n2, n1 % n2); else return n1;}
ll fact(ll n) { ll i = 1, co = 1; for (i = 1; i <= n; i++)co *= i; return co;}
ll isprime(ll n) {
    if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0;
    for (ll i = 5; i <= sqrt(n); i += 6) { if (n % i == 0 || n % (i + 2) == 0) return 0; } return 1;
}
ll sod(ll n) {ll sum = 0; while (n) {sum += n % 10; n /= 10;} return sum;}

// ll q = 0;

ll f(ll arr[], ll n, ll sum)
{

    map<ll, ll> pS;

    ll res = 0;
    ll c = 0;

    for (int i = 0; i < n; i++) {
        c += arr[i];
        if (c == sum) {
            res++;
            c += 1000000000;
        }

        if (pS.find(c - sum) != pS.end()) {

            // q++;

            res += (pS[c - sum]);
            c += 1000000000;

        }

        pS[c]++;
    }

    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

    int t;
    t = 1;
    //
    //
    //
    // cin >> t;
    while (t--) {
        ll n, m, q = 0;
        cin >> n;

        ll a[n];
        for (int i = 0; i < n; ++i)
        {
            cin >> a[i];
        }
        q = f(a, n, 0);
        ll ans = q;
        if (ans > 1) {
            ans = q * (q - 1) / 2 ;
        }
        cout << ans << endl;
        // cout << q << endl;

    }

    return 0;
}


//-----Rashish-----//
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define endl '\n'
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

ll hcf(ll n1, ll n2) {if (n2 != 0)return hcf(n2, n1 % n2); else return n1;}
ll fact(ll n) { ll i = 1, co = 1; for (i = 1; i <= n; i++)co *= i; return co;}
ll isprime(ll n) {
  if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0;
  for (ll i = 5; i <= sqrt(n); i += 6) { if (n % i == 0 || n % (i + 2) == 0) return 0; } return 1;
}
ll sod(ll n) {ll sum = 0; while (n) {sum += n % 10; n /= 10;} return sum;}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  int t;
  t = 1;
  //cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    ll f[n] = {0};
    for (int i = 0; i < n; ++i)
    {
      cin >> a[i];
      /* code */
    }
    if (n == 2) {
      if (a[0] + a[1] == 0) {
        cout << 1 << endl;
      }
    }
    else {
      f[0] = a[0];
      for (int i = 1; i < n; ++i)
      {
        f[i] = a[i] + f[i - 1];
        /* code */
      }
      std::map<ll, ll> m;
      for (int i = 0; i < n; ++i)
      {
        m[f[i]]++;
        /* code */
      }
      // for (int i = 0; i < n; ++i)
      // {
      //   cout << f[i] << " ";
      //   /* code */
      // }
      ll q = INT_MIN;
      for (auto x : m) {
        if (x.ss > q) {
          q = x.ss;
        }
      }
      // cout << q << endl;
      ll ans = q * (q - 1) / 2;

      cout << ans << endl;
    }
  }

  return 0;
}


//-----Rashish-----//
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define endl '\n'
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

ll hcf(ll n1, ll n2) {if (n2 != 0)return hcf(n2, n1 % n2); else return n1;}
ll fact(ll n) { ll i = 1, co = 1; for (i = 1; i <= n; i++)co *= i; return co;}
ll isprime(ll n) {
    if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0;
    for (ll i = 5; i <= sqrt(n); i += 6) { if (n % i == 0 || n % (i + 2) == 0) return 0; } return 1;
}
ll sod(ll n) {ll sum = 0; while (n) {sum += n % 10; n /= 10;} return sum;}

// ll q = 0;

ll f(ll arr[], ll n, ll sum)
{

    map<ll, ll> pS;

    ll res = 0;
    ll c = 0;

    for (int i = 0; i < n; i++) {
        c += arr[i];
        if (c == sum) {
            res++;
            c += (-1 * 1000000000);
        }

        if (pS.find(c - sum) != pS.end()) {

            // q++;

            res += (pS[c - sum]);
            c += (-1 * 1000000000);

        }

        pS[c]++;
    }

    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

    int t;
    t = 1;
    //
    //
    //
    // cin >> t;
    while (t--) {
        ll n, m, q = 0;
        cin >> n;

        ll a[n];
        for (int i = 0; i < n; ++i)
        {
            cin >> a[i];
        }
        q = f(a, n, 0);
        ll ans = q;
        if (ans > 1) {
            ans = q * (q - 1) / 2 ;
        }
        cout << ans << endl;
        // cout << q << endl;

    }

    return 0;
}


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
int x,y;
int x1,y1;
vector<pair<int,int>> g;
int a[maxn];
int sum = 0;
unordered_map<int,pii> mappa;
int ans = 0;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i,1,n) cin >> a[i];
	sum = a[1];
	mappa[a[1]] = {1,1};
	x =1;
	rep(i,2,n)
	{
	    y1 = 0;
		sum += a[i];
		if ( sum == 0 )
		{
			g.pb({x,i}); x = i+1;
			mappa.clear();
			sum = 0;
			y1 = 1;
		}
		if ( mappa[sum].fi > 0 )
		{
			//cout << mappa[sum].se +1 << " " << i <<  endl;
			g.pb({mappa[sum].se+1,i});
			x = i+1;
			y1 = 1;
			sum = 0;
			mappa.clear();
		}
		if ( y1 == 0 ) mappa[sum] = {x,i};
	}
	if ( g.empty()) cout << 0;
	else
	{
		ans += g.size();
		sort(g.begin(),g.end());
		if ( g.size() >= 2)
		rep(i,0,g.size()-2 )
		{
			if ( g[i].se + 1 == g[i+1].fi && a[ g[i].se] + a[g[i+1].fi] == 0 ) ans++;
		}
		cout << ans;
	}
}
/*  Things to look out for
    1. Array bounds
    2. Integer bounds
    3. Edge cases ( n == 1 )
    4. Resetting/resizing array/vectors
    5. Printing "Yes"/"No" more time than needed ( yes it has happened b4)
*/


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
int x,y;
int x1,y1;
vector<pair<int,int>> g;
int a[maxn];
int b[maxn];
int sum = 0;
unordered_map<int,int> mappa;
int ans = 0;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i,1,n)
	{
		cin >> a[i];
		if ( i > 1) b[i] = b[i-1] + a[i];
		else b[i] = a[i];
	}
	sum = a[1];
	mappa[a[1]] = 1;
	x =1;
	rep(i,2,n)
	{
		if ( sum+ a[i] == 0 )
		{
			sum = 0;
			ans++;
			mappa.clear();
		}
		if ( mappa[sum+a[i]] > 0  )
		{
			sum = 0;
			ans++;
			mappa.clear();
		}
		sum += a[i];
		mappa[sum] = 1;
	}
	cout << ans;
}
/*  Things to look out for
    1. Array bounds
    2. Integer bounds
    3. Edge cases ( n == 1 )
    4. Resetting/resizing array/vectors
    5. Printing "Yes"/"No" more time than needed ( yes it has happened b4)
*/


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
int x,y;
vector<int> g;
int a[maxn];
int ans;
map<int,int> mm;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i,1,n) cin >> a[i];
	x = a[1];
	ans = 0;
	mm[a[1]]++;
	rep(i,2,n)
	{
		//cout << x + a[i] << endl;
		if ( x+a[i]  == 0 )
		{
			ans++;
			x = 0;
			mm.clear();
		}
		else if ( mm[x + a[i]] > 0 )
		{
			ans++;
			x = 0;
			mm.clear();
		}
		x+= a[i];
		mm[x]++;
	}
	cout << ans;
}
/*  Things to look out for
    1. Array bounds
    2. Integer bounds
    3. Edge cases ( n == 1 )
    4. Resetting/resizing array/vectors
    5. Printing "Yes"/"No" more time than needed ( yes it has happened b4)
*/


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
int x,y;
int x1,y1;
vector<pair<int,int>> g;
int a[maxn];
int b[maxn];
int sum = 0;
unordered_map<int,pii> mappa;
int ans = 0;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i,1,n)
	{
		cin >> a[i];
		if ( i > 1) b[i] = b[i-1] + a[i];
		else b[i] = a[i];
	}
	sum = a[1];
	mappa[a[1]] = {1,1};
	x =1;
	rep(i,2,n)
	{
		sum += a[i];
		if ( sum == 0 )
		{
			g.pb({x,i});
			x = i+1;
			sum = 0;
			y1 = 1;
			mappa.clear();
		}
		if ( mappa[sum].fi > 0 && mappa[sum].se > 0 )
		{
			g.pb({max(mappa[sum].se,mappa[sum].fi) + 1,i});
			x = i+1;
			y1 = 1;
			sum = 0;
			mappa.clear();
		}
		mappa[sum] = {x,i};
	}
	if ( g.empty()) cout << 0;
	else
	{
		ans += g.size();

		if ( g.size() >= 2)
		{
			rep(i,0,g.size()-1 )
			{
				if ( g[i].fi > g[i].se ) swap(g[i].fi, g[i].se);
				//cout << g[i].fi << " " << g[i].se << endl;
			}
			sort(g.begin(),g.end());
			rep(i,0,g.size()-2 )
			{
				//if ( g[i].fi > g[i].se ) swap(g[i].fi, g[i].se);
				if ( g[i].se + 1 == g[i+1].fi && a[ g[i].se] + a[g[i+1].fi] == 0  || g[i].se + 1 < g[i+1].fi && b[g[i+1].fi] - b[g[i].se-1] == 0 ) ans++;
			}

		}
		cout << ans;
	}
}
/*  Things to look out for
    1. Array bounds
    2. Integer bounds
    3. Edge cases ( n == 1 )
    4. Resetting/resizing array/vectors
    5. Printing "Yes"/"No" more time than needed ( yes it has happened b4)
*/


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
int x,y;
int x1,y1;
vector<pii> g;
int a[maxn];
int sum = 0;
unordered_map<int,pii> mappa;
unordered_map<int,pii> mappa1;
int ans = 0;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i,1,n) cin >> a[i];
	sum = a[1];
	mappa[a[1]] = {1,1};
	x =1;
	rep(i,2,n)
	{
		sum += a[i];
		if ( sum == 0 )
		{
			g.pb({x,i}); x = i+1;
			mappa.clear();
			sum = 0;
		}
		if ( mappa[sum].fi > 0 )
		{
			g.pb({mappa[sum].se+1,i});
			x = i+1;
			sum = 0;
			mappa.clear();
		}
		mappa[sum] = {x,i};
	}
	if ( g.empty()) cout << 0;
	else
	{
		ans += g.size();
		sort(g.begin(),g.end());
		rep(i,0,g.size()-2 )
		{
			if ( g[i].se + 1 == g[i+1].fi && a[ g[i].se] + a[g[i+1].fi] == 0 ) ans++;
		}
		cout << ans;
	}
}
/*  Things to look out for
    1. Array bounds
    2. Integer bounds
    3. Edge cases ( n == 1 )
    4. Resetting/resizing array/vectors
    5. Printing "Yes"/"No" more time than needed ( yes it has happened b4)
*/


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
int x,y;
int x1,y1;
vector<pair<int,int>> g;
int a[maxn];
int sum = 0;
unordered_map<int,pii> mappa;
int ans = 0;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i,1,n) cin >> a[i];
	sum = a[1];
	mappa[a[1]] = {1,1};
	x =1;
	rep(i,2,n)
	{
		sum += a[i];
		if ( sum == 0 )
		{
			g.pb({x,i});
			x = i+1;
			sum = 0;
			y1 = 1;
			mappa.clear();
		}
		if ( mappa[sum].fi > 0 )
		{
			g.pb({max(mappa[sum].se,mappa[sum].fi) + 1,i});
			x = i+1;
			y1 = 1;
			sum = 0;
			mappa.clear();
		}
		if ( y1 == 0 ) mappa[sum] = {x,i};
	}
	if ( g.empty()) cout << 0;
	else
	{
		ans += g.size();

		if ( g.size() >= 2)
		{
			rep(i,0,g.size()-2 )
			{
				if ( g[i].fi > g[i].se ) swap(g[i].fi, g[i].se);
				//if ( g[i].se + 1 == g[i+1].fi && a[ g[i].se] + a[g[i+1].fi] == 0 ) ans++;
			}
			sort(g.begin(),g.end());
			rep(i,0,g.size()-2 )
			{
				//if ( g[i].fi > g[i].se ) swap(g[i].fi, g[i].se);
				if ( g[i].se + 1 == g[i+1].fi && a[ g[i].se] + a[g[i+1].fi] == 0 ) ans++;
			}

		}
		cout << ans;
	}
}
/*  Things to look out for
    1. Array bounds
    2. Integer bounds
    3. Edge cases ( n == 1 )
    4. Resetting/resizing array/vectors
    5. Printing "Yes"/"No" more time than needed ( yes it has happened b4)
*/


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
int x,y;
int x1,y1;
vector<pair<int,int>> g;
int a[maxn];
int b[maxn];
int sum = 0;
unordered_map<int,pii> mappa;
int ans = 0;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i,1,n)
	{
		cin >> a[i];
		if ( i > 1) b[i] = b[i-1] + a[i];
		else b[i] = a[i];
	}
	sum = a[1];
	mappa[a[1]] = {1,1};
	x =1;
	rep(i,2,n)
	{
		sum += a[i];
		if ( sum == 0 )
		{
			g.pb({x,i});
			x = i+1;
			sum = 0;
			y1 = 1;
			mappa.clear();
		}
		if ( mappa[sum].fi > 0 && mappa[sum].se > 0 )
		{
			g.pb({max(mappa[sum].se,mappa[sum].fi) + 1,i});
			x = i+1;
			y1 = 1;
			sum = 0;
			mappa.clear();
		}
		if ( y1 == 0 ) mappa[sum] = {x,i};
	}
	if ( g.empty()) cout << 0;
	else
	{
		ans += g.size();

		if ( g.size() >= 2)
		{
			rep(i,0,g.size()-1 )
			{
				if ( g[i].fi > g[i].se ) swap(g[i].fi, g[i].se);
				//cout << g[i].fi << " " << g[i].se << endl;
			}
			sort(g.begin(),g.end());
			rep(i,0,g.size()-2 )
			{
				//if ( g[i].fi > g[i].se ) swap(g[i].fi, g[i].se);
				if ( g[i].se + 1 == g[i+1].fi && a[ g[i].se] + a[g[i+1].fi] == 0  || g[i].se + 1 < g[i+1].fi && b[g[i+1].fi] - b[g[i].se-1] == 0 ) ans++;
			}

		}
		cout << ans;
	}
}
/*  Things to look out for
    1. Array bounds
    2. Integer bounds
    3. Edge cases ( n == 1 )
    4. Resetting/resizing array/vectors
    5. Printing "Yes"/"No" more time than needed ( yes it has happened b4)
*/


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
int x,y;
int x1,y1;
vector<pair<int,int>> g;
int a[maxn];
int b[maxn];
int sum = 0;
unordered_map<int,pii> mappa;
int ans = 0;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i,1,n)
	{
		cin >> a[i];
		if ( i > 1) b[i] = b[i-1] + 1;
		else b[i] = a[i];
	}
	sum = a[1];
	mappa[a[1]] = {1,1};
	x =1;
	rep(i,2,n)
	{
		sum += a[i];
		if ( sum == 0 )
		{
			g.pb({x,i});
			x = i+1;
			sum = 0;
			y1 = 1;
			mappa.clear();
		}
		if ( mappa[sum].fi > 0 && mappa[sum].se > 0 )
		{
			g.pb({max(mappa[sum].se,mappa[sum].fi) + 1,i});
			x = i+1;
			y1 = 1;
			sum = 0;
			mappa.clear();
		}
		if ( y1 == 0 ) mappa[sum] = {x,i};
	}
	if ( g.empty()) cout << 0;
	else
	{
		ans += g.size();

		if ( g.size() >= 2)
		{
			rep(i,0,g.size()-1 )
			{
				if ( g[i].fi > g[i].se ) swap(g[i].fi, g[i].se);
				//cout << g[i].fi << " " << g[i].se << endl;
			}
			sort(g.begin(),g.end());
			rep(i,0,g.size()-2 )
			{
				//if ( g[i].fi > g[i].se ) swap(g[i].fi, g[i].se);
				if ( g[i].se + 1 == g[i+1].fi && a[ g[i].se] + a[g[i+1].fi] == 0  || g[i].se + 1 < g[i+1].fi && b[g[i+1].fi] - b[g[i].se-1] == 0 ) ans++;
			}

		}
		cout << ans;
	}
}
/*  Things to look out for
    1. Array bounds
    2. Integer bounds
    3. Edge cases ( n == 1 )
    4. Resetting/resizing array/vectors
    5. Printing "Yes"/"No" more time than needed ( yes it has happened b4)
*/


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
int x,y;
int x1,y1;
vector<pair<int,int>> g;
int a[maxn];
int sum = 0;
unordered_map<int,pii> mappa;
int ans = 0;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i,1,n) cin >> a[i];
	sum = a[1];
	mappa[a[1]] = {1,1};
	x =1;
	rep(i,2,n)
	{
		sum += a[i];
		if ( sum == 0 )
		{
			g.pb({x,i}); x = i+1;
			mappa.clear();
			sum = 0;
		}
		if ( mappa[sum].fi > 0 )
		{
			//cout << mappa[sum].se +1 << " " << i <<  endl;
			g.pb({mappa[sum].se+1,i});
			x = i+1;
			sum = 0;
			mappa.clear();
		}
		mappa[sum] = {x,i};
	}
	if ( g.empty()) cout << 0;
	else
	{
		ans += g.size();
		sort(g.begin(),g.end());
		if ( g.size() >= 2)
		rep(i,0,g.size()-2 )
		{
			if ( g[i].se + 1 == g[i+1].fi && a[ g[i].se] + a[g[i+1].fi] == 0 ) ans++;
		}
		cout << ans;
	}
}
/*  Things to look out for
    1. Array bounds
    2. Integer bounds
    3. Edge cases ( n == 1 )
    4. Resetting/resizing array/vectors
    5. Printing "Yes"/"No" more time than needed ( yes it has happened b4)
*/


#include<bits/stdc++.h>
#define int long  long
#define rep(i,a,n) for ( i = a ; i <= n ; i++ )
#define per(i,a,n) for ( i = n ; i >= a ; i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define Y "YES"
#define N "NO"
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+5;
const int mod = 1000000007;
int t;
int i,j;
int n,m,k;
int x,y;
int x1,y1;
vector<pair<int,int>> g;
int a[maxn];
int sum = 0;
unordered_map<int,pii> mappa;
int ans = 0;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i,1,n) cin >> a[i];
	sum = a[1];
	mappa[a[1]] = {1,1};
	x =1;
	rep(i,2,n)
	{
		sum += a[i];
		if ( sum == 0 )
		{
			g.pb({x,i});
			x = i+1;
			sum = 0;
			y1 = 1;
			mappa.clear();
		}
		if ( mappa[sum].fi > 0 )
		{
			g.pb({mappa[sum].se+1,i});
			x = i+1;
			y1 = 1;
			sum = 0;
			mappa.clear();
		}
		if ( y1 == 0 ) mappa[sum] = {x,i};
	}
	if ( g.empty()) cout << 0;
	else
	{
		ans += g.size();

		if ( g.size() >= 2)
		{
			rep(i,0,g.size()-2 )
			{
				if ( g[i].fi > g[i].se ) swap(g[i].fi, g[i].se);
				//if ( g[i].se + 1 == g[i+1].fi && a[ g[i].se] + a[g[i+1].fi] == 0 ) ans++;
			}
			sort(g.begin(),g.end());
			rep(i,0,g.size()-2 )
			{
				//if ( g[i].fi > g[i].se ) swap(g[i].fi, g[i].se);
				if ( g[i].se + 1 == g[i+1].fi && a[ g[i].se] + a[g[i+1].fi] == 0 ) ans++;
			}

		}
		cout << ans;
	}
}
/*  Things to look out for
    1. Array bounds
    2. Integer bounds
    3. Edge cases ( n == 1 )
    4. Resetting/resizing array/vectors
    5. Printing "Yes"/"No" more time than needed ( yes it has happened b4)
*/


#include<iostream>
#include<algorithm>
using namespace std;
const int N = 200010;
int a[N];
int vis[N];
long long s[N];
int main() {
	int n; cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]), s[i]=s[i-1]+a[i];
	int flag = 0;
	for (int i = 2; i <= n; ++i) {
		for (int j = 0; j < i; ++j) {
			if (vis[j])continue;
			if (s[i] == s[j])ans++, vis[i] = 1,flag=1;
			//if (s[j] == 0 && flag == 0)ans++, vis[j] = 1, cout << j << endl;
		}
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int N = 200010;
int a[N];
long long vis[N];
int main() {
	int n; cin >> n;
	int ans = 0;
	long long sum = 0;
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
	vis[0] = 1;
	for (int i = 1; i <= n; ++i) {
		sum += a[i];
		if (vis[sum]) {
			memset(vis, 0, sizeof vis);
			ans++;
			sum = a[i];
			vis[sum] = 1;
			vis[0] = 1;
		}
		else vis[sum] = 1;
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int N = 200010;
int a[N];
int vis[N];
long long s[N];
int main() {
	int n; cin >> n;
	int ans = 0;
	int index = 0;
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
	for (int i = 1; i <= n; ++i) {
		for (int j = index; j < i; ++j) {
			if (f[j])continue;
			if (vis[j])continue;
			if (s[i] == s[j])ans++, vis[j]=1,index=j;
		}
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int N = 200010;
int a[N];
int vis[N];
long long s[N];
int main() {
	int n; cin >> n;
	int ans = 0;
	int index = 0;
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
	for (int i = 1; i <= n; ++i) {
		for (int j = index; j < i; ++j) {
			if (vis[j])continue;
			if (s[i] == s[j]) {
				ans++, vis[j] = 1, index = j;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 200010;
int a[N];
long long vis[N];
int main() {
	int n; cin >> n;
	int ans = 0;
	long long sum = 0;
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
	vis[0] = 1;
	for (int i = 1; i <= n; ++i) {
		sum += a[i];
		if (vis[sum]) {
			memset(vis, 0, sizeof vis);
			ans++;
			sum = a[i];
			vis[sum] = 1;
			vis[0] = 1;
		}
		else vis[sum] = 1;
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int N = 200010;
int a[N];
int vis[N];
long long s[N];
int main() {
	int n; cin >> n;
	int ans = 0;
	for (int i = 0; i < n; ++i)scanf("%d", &a[i]), s[i]=s[i-1]+a[i];
	//cout << s[0] << s[3] << endl;
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < i; ++j) {
			if (vis[j])continue;
			if (s[i] == s[j])ans++, vis[j] = 1;
		}
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
const int N = 200010;
int a[N];
int main() {
	int n; cin >> n;
	int ans = 0;
	map<long long, bool>p;
	long long sum = 0;
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
	p[0] = 1;
	for (int i = 1; i <= n; ++i) {
		sum += a[i];
		if (p.count(sum)) {
			p.clear();
			ans++;
			sum = a[i];
			p[sum] = 1;
			p[0] = 1;
		}
		else p[sum] = 1;
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 200010;
int a[N];
int vis[N];
int main() {
	int n; cin >> n;
	int ans = 0;
	long long sum = 0;
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
	vis[0] = 1;
	for (int i = 1; i <= n; ++i) {
		sum += a[i];
		if (vis[sum]) {
			memset(vis, 0, sizeof vis);
			ans++;
			sum = a[i];
			vis[sum] = 1;
			vis[0] = 1;
		}
		else vis[sum] = 1;
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int N = 200010;
int a[N];
int vis[N];
long long s[N];
int main() {
	int n; cin >> n;
	int ans = 0;
	int index = 0;
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
	for (int i = 1; i <= n; ++i) {
		for (int j = index; j < i; ++j) {
			if (vis[j])continue;
			if (s[i] == s[j])ans++, vis[j]=1,index=j;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int n;
    cin >> n;
    map<ll,ll> mp;
    ll sum[n+5] = {0},arr[n+5],ans = 0,flag = -1;
    for(int i = 1;i <= n;i++) cin >> arr[i];
    for(int i = 1;i <= n;i++)
    {
        sum[i] = arr[i]+sum[i-1];
        if(mp[sum[i]] && mp[sum[i]] >= flag-1)
            ans++,l = i;
        mp[sum[i]] = 1;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 2e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    ll n;
    cin >> n;
    map<ll,ll> mp;
    ll arr[n+5],sum = 0,ans = 0;
    for(int i = 1;i <= n;i++) cin >> arr[i];
    for(int i = 1;i <= n;i++)
    {
        sum += arr[i];
        if(mp[sum] || sum == 0)
        {
            ans++;
            mp.clear();
            sum = arr[i];
        }
        mp[sum] = 1;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int n;
    cin >> n;
    map<ll,ll> mp;
    ll sum[n+5] = {0},arr[n+5],ans = 0,flag = -1;
    for(int i = 1;i <= n;i++) cin >> arr[i];
    for(int i = 1;i <= n;i++)
    {
        sum[i] = arr[i]+sum[i-1];
        if(mp[sum[i]])
            ans++,flag = i;
        mp[sum[i]] = 1;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int n;
    cin >> n;
    map<ll,ll> mp;
    mp[0] = 1;
    ll sum[n+5] = {0},arr[n+5],ans = 0,flag = -1;
    for(int i = 1;i <= n;i++) cin >> arr[i];
    for(int i = 1;i <= n;i++)
    {
        sum[i] = arr[i]+sum[i-1];
        if(mp[sum[i]] && mp[sum[i]] >= flag-1)
            ans++,flag = i;
        mp[sum[i]] = 1;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 2e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int t;
    cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;
        map<ll,ll> mp;
        ll arr[n+5],sum[n+5] = {0},ans = 0;
        for(int i = 1;i <= n;i++) cin >> arr[i];
        for(int i = 1;i <= n;i++)
        {
            sum[i] = arr[i] + sum[i-1];
            if(mp[sum[i]])
            {
                ans++;
                mp.clear();
                sum[i] = arr[i];
            }
        }
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int n;
    cin >> n;
    map<ll,ll> mp;
    mp[0] = 0;
    ll sum[n+5] = {0},arr[n+5],ans = 0,flag = -1;
    for(int i = 2;i <= n+1;i++) cin >> arr[i];
    for(int i = 2;i <= n+1;i++)
    {
        sum[i] = arr[i]+sum[i-1];
        if(mp[sum[i]] && mp[sum[i]] >= flag-1)
            ans++,flag = i;
        mp[sum[i]] = i;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int n;
    cin >> n;
    map<ll,ll> mp;
    ll sum[n+5] = {0},arr[n+5],ans = 0,flag = -1;
    for(int i = 1;i <= n;i++) cin >> arr[i];
    for(int i = 1;i <= n;i++)
    {
        sum[i] = arr[i]+sum[i-1];
        if(mp[sum[i]] || sum[i] == 0)
            ans++,flag = i;
        mp[sum[i]] = 1;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int n;
    cin >> n;
    map<ll,ll> mp;
    ll sum[n+5] = {0},arr[n+5],ans = 0,flag = -1;
    for(int i = 1;i <= n;i++) cin >> arr[i];
    for(int i = 1;i <= n;i++)
    {
        sum[i] = arr[i]+sum[i-1];
        if(mp[sum[i]] && mp[sum[i]] >= flag-1)
            ans++,flag = i;
        mp[sum[i]] = 1;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int n;
    cin >> n;
    map<ll,ll> mp;
    ll sum[n+5] = {0},arr[n+5],ans = 0,flag = -1;
    for(int i = 1;i <= n;i++) cin >> arr[i];
    for(int i = 1;i <= n;i++)
    {
        sum[i] = arr[i]+sum[i-1];
        if(mp[sum[i]])
        {
            if(mp[sum[i]] >= flag-1)
                ans++,flag = i;
        }
        else
            ans++,flag = i;
        mp[sum[i]] = i;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int n;
    cin >> n;
    map<ll,ll> mp;
    mp[0] = 1;
    ll sum[n+5] = {0},arr[n+5],ans = 0,flag = -1;
    for(int i = 2;i <= n+1;i++) cin >> arr[i];
    for(int i = 2;i <= n+1;i++)
    {
        sum[i] = arr[i]+sum[i-1];
        if(mp[sum[i]] && mp[sum[i]] >= flag-1)
            ans++,flag = i;
        mp[sum[i]] = i;
    }
    cout << ans << endl;
}