Kolya got an integer array $a_1, a_2, \dots, a_n$. The array can contain both positive and negative integers, but Kolya doesn't like $0$, so the array doesn't contain any zeros.

Kolya doesn't like that the sum of some subsegments of his array can be $0$. The subsegment is some consecutive segment of elements of the array. 

You have to help Kolya and change his array in such a way that it doesn't contain any subsegments with the sum $0$. To reach this goal, you can insert any integers between any pair of adjacent elements of the array (integers can be really any: positive, negative, $0$, any by absolute value, even such a huge that they can't be represented in most standard programming languages).

Your task is to find the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $0$.


-----Input-----

The first line of the input contains one integer $n$ ($2 \le n \le 200\,000$) — the number of elements in Kolya's array.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^{9} \le a_i \le 10^{9}, a_i \neq 0$) — the description of Kolya's array.


-----Output-----

Print the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $0$.


-----Examples-----
Input
4
1 -5 3 2

Output
1

Input
5
4 -2 3 -9 2

Output
0

Input
9
-1 1 -1 1 -1 1 1 -1 -1

Output
6

Input
8
16 -5 -11 -15 10 5 4 -4

Output
3



-----Note-----

Consider the first example. There is only one subsegment with the sum $0$. It starts in the second element and ends in the fourth element. It's enough to insert one element so the array doesn't contain any subsegments with the sum equal to zero. For example, it is possible to insert the integer $1$ between second and third elements of the array.

There are no subsegments having sum $0$ in the second example so you don't need to do anything.

Source: codeforces | Difficulty: MEDIUM
Tags: Greedy algorithms

Sorting

Data structures

Constructive algorithms


Solutions:
import sys, string
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi, log2

def input():
	return sys.stdin.buffer.readline().decode('utf-8')
from bisect import bisect_left, bisect_right
from operator import add
MOD = int(1000000000.0) + 7
INF = float('inf')

def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	m = defaultdict(int)
	total = 0
	segs = []
	m[0] = -1
	ans = 0
	last = -INF
	for i in range(n):
		total += a[i]
		if total in m and last <= m[total]:
			ans += 1
			last = i
		m[total] = i + 1
	print(ans)
T = 1
for case in range(1, T + 1):
	ans = solve()


n = int(input())
a = list(map(int, input().split()))
p = {0: 1}
c = 0
result = 0
for i in range(n):
	c += a[i]
	if c in p:
		result += 1
		p = {0: 1}
		c = a[i]
	p[c] = 1
print(result)


import math
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	s = 0
	d = {0: 1}
	for i in range(n):
		s += a[i]
		if s in d:
			ans += 1
			s = a[i]
			d = {0: 1}
			d[s] = 1
		else:
			d[s] = 1
	print(ans)


from collections import defaultdict
from sys import stdin
input = stdin.readline
import math

def put():
	return map(int, input().split())
n = int(input())
l = list(put())
seek = defaultdict()
seek[l[0]] = 1
sum = l[0]
ans = 0
for i in range(1, n):
	sum += l[i]
	if sum in seek or sum == 0:
		ans += 1
		sum = l[i]
		seek = defaultdict()
		seek[l[i]] = 1
	else:
		seek[sum] = 1
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
d = set()
d.add(0)
summa = 0
k = 0
for i in a:
	summa += i
	if summa in d:
		k += 1
		d = set()
		d.add(0)
		summa = i
	d.add(summa)
print(k)


def main():
	(_, array) = (int(input()), list(map(int, input().split(' '))))
	answer = 0
	sumSpace = [0]
	for elem in array:
		sumSpace.append(sumSpace[-1] + elem)
	sumSpace.pop(0)
	verify = {0}
	q = 0
	for elem in sumSpace:
		if elem in verify:
			verify = {q}
			answer += 1
		verify.add(elem)
		q = elem
	print(answer)
main()


import sys, bisect as bi
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
su = 0
an = 0
f = dict()
f[0] = -1
it = []
for i in range(n):
	su += l[i]
	if su in f:
		it.append([f[su] + 1, i])
	f[su] = i
ar = []
for i in range(len(it)):
	(a, b) = it[i]
	(x, y) = (bi.bisect(ar, a), bi.bisect(ar, b))
	if y - x <= 0:
		ar.append(b)
print(len(ar))


n = int(input())
a = list(map(int, input().split()))
b = {0: [0]}
sumup = 0
count = 0
c = []
for i in a:
	sumup += i
	try:
		b[sumup].append(count)
	except:
		b[sumup] = [count]
	count += 1
for i in b.values():
	c += tuple(zip(i, i[1:]))
c.sort(reverse=True)
ans = 10 ** 9
sumup = 0
for i in c:
	if i[1] <= ans:
		sumup += 1
		ans = i[0] + 1
print(sumup)


n = input()
l = list(map(int, input().split()))
g = set()
g.add(0)
now = 0
delta = 1j
ans = 0
for i in l:
	now += i
	if now in g:
		ans += 1
		now += delta
		g.add(now - i)
	g.add(now)
print(ans)


import sys
N = int(sys.stdin.readline())
list_num = list(map(int, sys.stdin.readline().split()))
set_visit = set([0])
now = 0
res = 0
for i in range(N):
	now += list_num[i]
	if now in set_visit:
		set_visit = set([0])
		res += 1
		now = list_num[i]
	set_visit.add(now)
if not now:
	res += 1
print(res)


import sys
from collections import defaultdict

def load_sys():
	return sys.stdin.readlines()

def load_local():
	with open('input.txt', 'r') as f:
		input = f.readlines()
	return input

def nzs(arr):
	ans = 0
	seen = set()
	seen.add(0)
	pref = 0
	for n in arr:
		pref += n
		if pref in seen:
			ans += 1
			seen = set([0])
			pref = n
		seen.add(pref)
	return ans
input = load_sys()
N = int(input[0])
test_cases = []
input[1] = input[1].split()
input[1] = [int(x) for x in input[1]]
print(nzs(input[1]))


n = int(input())
A = [int(x) for x in input().split()]
S = {0}
res = 0
s = 0
for a in A:
	s += a
	if s in S:
		res += 1
		S = {0}
		s = a
	S.add(s)
print(res)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
a = inlt()
cnt = 0
s = {0}
prefix = 0
for i in range(0, n):
	prefix += a[i]
	if prefix in s:
		cnt += 1
		s = {0, a[i]}
		prefix = a[i]
	else:
		s.add(prefix)
print(cnt)


n = int(input())
arr = list(map(int, input().split(' ')))
d = set()
d.add(0)
sum = 0
ans = 0
for i in range(n):
	sum += arr[i]
	if sum in d:
		ans += 1
		d = set()
		d.add(0)
		sum = arr[i]
	d.add(sum)
print(ans)


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]

def solve():
	n = int(ii())
	data = idata()
	cnt = 0
	ans = 0
	s = set()
	s.add(0)
	for i in range(n):
		cnt += data[i]
		if cnt in s:
			ans += 1
			s.clear()
			s.add(0)
			cnt = data[i]
		s.add(cnt)
	print(ans)
	return
solve()


count = 0
n = int(input())
a = [int(x) for x in input().split()]
sum = 0
list = set()
list.add(0)
for i in range(n):
	sum += a[i]
	if sum in list:
		count += 1
		list = set()
		list.add(0)
		sum = a[i]
	list.add(sum)
print(count)


n = int(input())
a = list(map(int, input().split()))
sum = ans = 0
x = {0}
for i in a:
	sum += i
	if sum in x:
		ans += 1
		x = {0}
		sum = i
	x.add(sum)
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
zero = set()
zero.add(0)
res = 0
sums = 0
for i in a:
	sums += i
	if sums in zero:
		res += 1
		zero = set()
		zero.add(0)
		sums = i
	zero.add(sums)
print(res)


from math import ceil, sqrt
from collections import defaultdict
hash = defaultdict(int)
sumi = 0
n = int(input())
l = list(map(int, input().split()))
yo = 10 ** 18
ans = 0
for i in l:
	sumi += i
	if hash[sumi] > 0 or sumi == 0:
		sumi -= i + yo
		hash[sumi] += 1
		sumi += i
		hash[sumi] += 1
		ans += 1
	else:
		hash[sumi] += 1
print(ans)


n = input()
a = list(map(int, input().split()))
k = {0}
t = c = 0
for p in a:
	c += p
	if c in k:
		k = {0, p}
		t += 1
		c = p
	else:
		k.add(c)
print(t)


import sys, os, io
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
from collections import defaultdict
from itertools import groupby, accumulate, product, permutations, combinations
d = defaultdict(lambda : False)
ans = 0
cum = [0] + list(accumulate(A))
d[0] = True
for i in range(1, n + 1):
	if d[cum[i]] == True:
		ans += 1
		d = defaultdict(lambda : False)
		d[cum[i - 1]] = True
		d[cum[i]] = True
	d[cum[i]] = True
print(ans)


import math
import sys
from sys import stdin, stdout
ipi = lambda : int(stdin.readline())
ipil = lambda : map(int, stdin.readline().split())
ipf = lambda : float(stdin.readline())
ipfl = lambda : map(float, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
outl = lambda x: print(*x)
n = ipi()
a = list(ipil())
s = [0] * (n + 1)
s[0] = 0
for i in range(1, n + 1):
	s[i] = s[i - 1] + a[i - 1]
sum_map = dict()
ans = 0
i = 0
while i <= n:
	if sum_map.get(s[i]) is None:
		sum_map[s[i]] = True
	else:
		sum_map.clear()
		ans += 1
		i -= 2
	i += 1
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
done = {a[0]: 0, 0: 0}
s = a[0]
ans = 0
for i in range(1, n):
	s += a[i]
	if s in done:
		done = {0: 0, a[i]: 0}
		ans += 1
		s = a[i]
	else:
		done[s] = 0
print(ans)


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split()))
d = defaultdict(int)
d[0] = 1
prev = 0
ans = 0
for i in range(n):
	prev += arr[i]
	if prev in d:
		ans += 1
		prev = arr[i]
		d = defaultdict(int)
		d[0] = 1
	d[prev] = 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
sumsSeen = {}
(sum_, ans) = (0, 0)
for el in a:
	sum_ += el
	if sum_ in sumsSeen or sum_ == 0:
		ans += 1
		sumsSeen = {el: True}
		sum_ = el
	else:
		sumsSeen[sum_] = True
print(ans)


def get(l: list) -> int:
	sum_lst = []
	index = -1
	for i in range(len(l)):
		if not sum_lst:
			n = l[i]
		else:
			n = sum_lst[i - 1] + l[i]
		if n == 0 or n in sum_lst:
			index = i
			break
		sum_lst.append(n)
	if index == -1:
		return 0
	cnt = 1 + get(l[index:])
	return cnt

def getnew(l: list) -> int:
	st = set()
	new_sum = 0
	cnt = 0
	for i in range(len(l)):
		n = new_sum + l[i]
		if n in st or n == 0:
			cnt += 1
			st = set()
			st.add(l[i])
			new_sum = l[i]
		else:
			st.add(n)
			new_sum = n
	return cnt
n = int(input())
l = input().split()
l = [int(x) for x in l]
print(getnew(l))


n = int(input())
s = [int(x) for x in input().split()]
hashs = {0: 1}
c = 0
tots = 0
for i in s:
	c += i
	if c in hashs:
		tots += 1
		c = i
		hashs = {0: 1}
		hashs[c] = 1
	else:
		hashs[c] = 1
print(tots)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = set([0])
	presum = 0
	ans = 0
	for v in a:
		presum += v
		if presum in d:
			ans += 1
			d.clear()
			d.add(v)
			d.add(0)
			presum = v
		else:
			d.add(presum)
	print(ans)
main()


from itertools import permutations as per
from math import factorial as fact
from difflib import SequenceMatcher
n = int(input())
a = [int(i) for i in input().split()]
s = set()
ps = ans = 0
for i in range(n):
	ps += a[i]
	if ps == 0 or ps in s:
		ans += 1
		s.clear()
		ps = a[i]
	s.add(ps)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
s = set()
s.add(0)
c = 0
a = 0
for i in range(n):
	a += arr[i]
	if a in s:
		c += 1
		s.clear()
		s.add(0)
		a = arr[i]
	s.add(a)
print(c)


import sys

def main():
	n = int(sys.stdin.readline().strip())
	q = list(map(int, sys.stdin.readline().split()))
	w = [0 for i in range(n)]
	w[0] = q[0]
	for i in range(1, n):
		w[i] += w[i - 1] + q[i]
	d = dict()
	d[0] = [-1]
	for i in range(n):
		if w[i] in d:
			d[w[i]].append(i)
		else:
			d[w[i]] = [i]
	t = []
	for i in d:
		f = d[i]
		l = len(f)
		for i in range(1, l):
			t.append([f[i - 1], f[i]])
	t = sorted(t, key=lambda x: x[1])
	res = 1
	l = len(t)
	i = 0
	if l > 0:
		m = t[0][1] - 1
		for i in range(1, l):
			if m <= t[i][0]:
				res += 1
				m = t[i][1] - 1
	print(res - (l == 0))
for i in range(1):
	main()


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
q = int(input())
w = list(map(int, input().split()))
e = {0, w[0]}
r = 0
for i in range(1, q):
	if w[i] + w[i - 1] in e:
		r += 1
		e = {0, w[i]}
	else:
		w[i] += w[i - 1]
		e.add(w[i])
print(r)


import math
n = int(input())
a = list(map(int, input().split()))
pre = 0
s = set()
s.add(0)
ans = 0
for i in a:
	pre = pre + i
	if pre in s:
		s = set()
		s.add(0)
		s.add(i)
		ans += 1
		pre = i
	else:
		s.add(pre)
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
sums = set()
sums.add(0)
tsum = 0
ans = 0
for i in range(n):
	tsum += a[i]
	if tsum in sums:
		ans += 1
		sums = set()
		sums.add(0)
		tsum = a[i]
	sums.add(tsum)
print(ans)


n = int(input())
l = list(map(int, input().split()))
(s, sUm, ans) = ({0}, 0, 0)
for i in l:
	sUm += i
	if sUm in s:
		ans += 1
		sUm = i
		s = {0}
	s.add(sUm)
print(ans)


for _ in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	preSums = set()
	preSums.add(0)
	currSum = 0
	total = 0
	for i in range(n):
		currSum += arr[i]
		if currSum in preSums:
			total += 1
			preSums.clear()
			currSum = arr[i]
			preSums.add(currSum)
			preSums.add(0)
		else:
			preSums.add(currSum)
	print(total)


import os
import sys

def get_int():
	return int(input())

def get_ints():
	return map(int, input().split())

def get_float():
	return float(input())

def get_floats():
	return map(float, input().split())

def list_ints():
	return list(map(int, input().split()))

def list_floats():
	return list(map(float, input.split()))

def post(x):
	print(x, end=' ')
T = int(input())
a = list_ints()
d = set()
d.add(0)
cur = 0
ans = 0
for i in range(T):
	cur += a[i]
	if cur in d:
		ans += 1
		d = set()
		d.add(0)
		cur = a[i]
	d.add(cur)
print(ans)


n = int(input())
a = list(map(int, input().split()))
m = {0}
ans = 0
summ = 0
for i in range(n):
	summ += a[i]
	if summ == 0 or summ in m:
		ans += 1
		m = {a[i]}
		summ = a[i]
	else:
		m.add(summ)
print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict

def main():
	n = int(input())
	alst = list(map(int, input().split()))
	dd = defaultdict(int)
	ans = 0
	total = 0
	dd[0] = 1
	for num in alst:
		total += num
		if dd[total] == 1:
			ans += 1
			dd = defaultdict(int)
			dd[0] = 1
			total = num
		dd[total] += 1
	print(ans)
main()


input()
a = {0}
c = s = 0
for x in map(int, input().split()):
	s += x
	if s in a:
		a = {0, x}
		s = x
		c += 1
	else:
		a.add(s)
print(c)


n = int(input())
ls = list(map(int, input().split()))
check = 0
ans = 0
d = set([0])
for i in ls:
	check += i
	if check in d:
		ans += 1
		check = i
		d = set([0])
	d.add(check)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
sm = 0
sums = {}
ans = 0
for a in arr:
	sm += a
	if not sm or sm in sums:
		ans += 1
		sums = {}
		sm = a
	sums[sm] = True
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = set()
s.add(0)
sum = 0
cnt = 0
for i in range(n):
	sum += a[i]
	if sum in s:
		cnt += 1
		sum = a[i]
		s = set()
		s.add(0)
	s.add(sum)
print(cnt)


from sys import stdin
from collections import Counter
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = 0
s = set()
ans = 0
s.add(0)
for i in a:
	b += i
	if b in s:
		ans += 1
		s = set()
		s.add(0)
		b = i
	s.add(b)
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
visited = {0: 1}
number_of_inserts = 0
prefix_sum = 0
for a_i in a:
	prefix_sum += a_i
	if prefix_sum not in visited:
		visited[prefix_sum] = 1
	else:
		number_of_inserts += 1
		visited = {0: 1, a_i: 1}
		prefix_sum = a_i
print(number_of_inserts)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import defaultdict
from pprint import pprint
from math import ceil

def main():
	n = int(input())
	d = defaultdict(list)
	arr = list(map(int, input().split()))
	s = 0
	d[0] = [-1]
	a = []
	prev = -1
	cnt = 0
	for i in range(n):
		s += arr[i]
		if len(d[s]):
			if d[s][-1] + 1 >= prev:
				prev = i
				cnt += 1
		d[s].append(i)
	print(cnt)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(1):
	main()


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = list(map(int, input().split(' ')))
d = set()
d.add(0)
s = 0
c = 0
for i in range(n):
	s += l[i]
	if s in d:
		c += 1
		s = l[i]
		d = set()
		d.add(0)
	d.add(s)
print(c)


n = int(input())
a = [int(x) for x in input().split()]
d = set()
d.add(0)
cur = 0
ans = 0
for i in range(n):
	cur += a[i]
	if cur in d:
		ans += 1
		d = set()
		d.add(0)
		cur = a[i]
	d.add(cur)
print(ans)


n = input()
ans = sum = 0
list = {0}
for k in map(int, input().split()):
	sum += k
	if sum in list:
		sum = k
		list = {0, sum}
		ans += 1
	else:
		list.add(sum)
print(ans)


n = int(input())
l = list(map(int, input().split()))
ans = 0
sum = 0
x = {0}
for item in l:
	sum += item
	if sum in x:
		x = {0, item}
		ans += 1
		sum = item
	else:
		x.add(sum)
print(ans)


b = 0
sum = 0
n = int(input())
cl = []
s = set(cl)
pref = [0]
v = [int(i) for i in input().split()]
for i in range(1, n + 1):
	pref.append(pref[i - 1] + v[i - 1])
for i in range(n + 1):
	if pref[i] in s:
		sum += 1
		s = set(cl)
	s.add(pref[i])
	if i != 0:
		s.add(pref[i - 1])
print(sum)


n = int(input())
a = list(map(int, input().split()))
d = {0: 1}
tot = 0
ans = 0
for i in range(n):
	tot += a[i]
	if tot in d:
		ans += d[tot]
		d.clear()
		d[0] = 1
		tot = a[i]
	try:
		d[tot] += 1
	except:
		d[tot] = 1
print(ans)


import math
import sys

class Graph:

	def __init__(self, Nodes, is_directed=False):
		self.nodes = Nodes
		self.adj_list = {}
		self.is_directed = is_directed
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, u, v):
		self.adj_list[u].append(v)
		if self.is_directed == False:
			self.adj_list[v].append(u)

	def print_graph(self):
		for node in self.nodes:
			print(node, '->', self.adj_list[node])

	def degree_node(self, node):
		return len(self.adj_list[node])

	def dfsUTIL(self, v, visited, parents=[]):
		visited[v] = True
		for i in self.adj_list[v]:
			if visited[i] == False:
				self.dfsUTIL(i, visited, parents)
				parents.append(i)

	def dfs(self, v):
		visited = [False] * (max(self.adj_list) + 1)
		parents = [v]
		self.dfsUTIL(v, visited, parents)
		return len(parents)

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def seive_primes(n):
	flag = [0] * (n + 10)
	flag[1] = flag[0] = 1
	i = 2
	while i * i <= n + 1:
		if flag[i] == 0:
			j = i * i
			while j <= n + 1:
				flag[j] = 1
				j += i
		i += 1
	return flag

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def qdrt(x, a, b, c):
	return a * x * x + b * x + c

def inp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return map(int, input().split())
for _ in range(1):
	n = int(input())
	ls = inp()
	presum = 0
	s = set([0])
	ans = 0
	for i in range(n):
		presum += ls[i]
		if presum in s:
			ans += 1
			s = set([0])
			presum = ls[i]
		s.add(presum)
	print(ans)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 9 + 7
LOGN = 30
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	ans = 0
	val = 0
	d = {}
	d[0] = 1
	for i in range(n):
		val += a[i]
		if val in d:
			ans += 1
			d = {}
			d[0] = 1
			val = a[i]
			d[val] = 1
		else:
			d[val] = 1
	print(ans)


n = int(input())
s = list(map(int, input().split()))
curr = 0
k = set([0])
ans = 0
for i in s:
	curr += i
	if curr in k:
		ans += 1
		k = set([0])
		curr = i
	k.add(curr)
print(ans)


n = int(input())
li = list(map(int, input().split()))
new_sum = set()
s = 0
new_sum.add(s)
ans = 0
for i in li:
	s += i
	if s not in new_sum:
		new_sum.add(s)
	else:
		ans += 1
		s = i
		new_sum = set()
		new_sum.add(0)
		new_sum.add(i)
print(ans)


n = int(input())
ar = list(map(int, input().split()))
(sm, cnt) = (0, 0)
saveSm = {0}
for x in ar:
	sm += x
	if sm in saveSm:
		saveSm = {0}
		sm = x
		cnt += 1
	saveSm.add(sm)
print(cnt)


def HalfDead():
	n = int(input())
	a = list(map(int, input().split()))
	my_set = set([0])
	res = 0
	now = 0
	for x in a:
		now += x
		if now in my_set:
			res += 1
			now = x
			my_set = set([0])
		my_set.add(now)
	print(res)
HalfDead()


_ = int(input())
sumlist = {0}
sum = result = 0
for i in list(map(int, input().split())):
	sum += i
	if sum in sumlist:
		result += 1
		sum = i
		sumlist = {0}
	sumlist.add(sum)
print(result)


n = int(input())
arr = list(map(int, input().split()))
d = dict()
d[0] = None
summ = 0
count = 0
for i in range(n):
	summ = summ + arr[i]
	if summ in d:
		count += 1
		summ = arr[i]
		d = {0: None, arr[i]: None}
	else:
		d[summ] = None
print(count)


rifat = int(input())
a = [int(x) for x in input().split()]
st = set()
st.add(0)
sum = 0
ans = 0
for i in range(rifat):
	sum += a[i]
	if sum in st:
		ans += 1
		st = set()
		st.add(0)
		sum = a[i]
	st.add(sum)
print(ans)


def minpoints(array):
	array.sort(key=lambda x: x[1])
	n = len(array)
	i = 0
	count = 0
	while i < n:
		currend = array[i][1]
		count = count + 1
		i = i + 1
		if i >= n:
			break
		currstart = array[i][0]
		while currend > currstart:
			i = i + 1
			if i >= n:
				break
			currstart = array[i][0]
	return count

def createpoints(given, n):
	d = {}
	d[0] = 0
	ans = []
	s = 0
	for i in range(1, n + 1):
		s = s + given[i - 1]
		if s in d:
			ans.append([d[s], i - 1])
		d[s] = i
	return ans
n = int(input())
given = list(map(int, input().split()))
temp = createpoints(given, n)
print(minpoints(temp))


n = int(input())
a = [int(x) for x in input().split()]
b = set()
b.add(0)
aux = 0
respuesta = 0
for i in range(n):
	aux += a[i]
	if aux in b:
		respuesta += 1
		b = set()
		b.add(0)
		aux = a[i]
	b.add(aux)
print(respuesta)


n = int(input())
arr = list(map(int, input().split()))
count = 0
sum1 = 0
s = set()
s.add(0)
for i in range(n):
	sum1 += arr[i]
	if sum1 in s:
		count += 1
		s = set()
		s = {0}
		sum1 = arr[i]
	s.add(sum1)
print(count)


from collections import defaultdict

def findSubarraySum(arr, n, Sum):
	prevSum = defaultdict(lambda : 0)
	res = 0
	currsum = 0
	for i in range(0, n):
		currsum += arr[i]
		if currsum == Sum:
			res += 1
			currsum = arr[i]
			prevSum.clear()
		if currsum - Sum in prevSum:
			res += 1
			currsum = arr[i]
			prevSum.clear()
		prevSum[currsum] += 1
	return res
n = int(input())
arr = list(map(int, input().split()))
print(findSubarraySum(arr, n, 0))


n = int(input())
l = list(map(int, input().split()))
s = set()
s.add(0)
cs = 0
ans = 0
for i in l:
	cs += i
	if cs in s:
		ans += 1
		s = set()
		s.add(0)
		cs = i
		s.add(i)
	else:
		s.add(cs)
print(ans)


from math import *
t = 1
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	sum = 0
	s = set()
	s.add(0)
	out = 0
	for i in a:
		sum += i
		if sum in s:
			out += 1
			s = set()
			s.add(0)
			s.add(i)
			sum = i
		else:
			s.add(sum)
	print(out)


n = int(input())
a = list(map(int, input().split()))
result = 0
sum = 0
sums = {0}
for num in a:
	sum += num
	if sum in sums:
		sum = num
		sums = {0, num}
		result += 1
	else:
		sums.add(sum)
print(result)


from sys import stdin
a = int(stdin.readline())
z = list(map(int, stdin.readline().split()))
pref = {0}
ans = 0
t = 0
for i in z:
	t += i
	if t in pref:
		ans += 1
		pref = {0}
		t = i
	pref |= {t}
print(ans)


N = int(input())
a = []
b = {0}
sum = 0
ans = 0
set1 = input()
set1 = set1.split(' ')
for i in set1:
	x = int(i)
	a.append(x)
for i in range(0, N):
	sum += a[i]
	if sum in b:
		b.clear()
		b = {0}
		sum = a[i]
		ans = ans + 1
	b.add(sum)
print(ans)


import sys
import os
from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
import bisect
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	n = iinp()
	arr = intl()
	s = set()
	s.add(0)
	c = 0
	ans = 0
	for i in arr:
		c += i
		if c in s:
			ans += 1
			s.clear()
			s.add(0)
			c = i
		s.add(c)
	print(ans)
solve()


import itertools
import math
import sys
from collections import defaultdict

def stdinWrapper():
	data = '4\n1 -5 3 2\n\n\n\n'
	for line in data.split('\n'):
		yield line
if '--debug' not in sys.argv:

	def stdinWrapper():
		while True:
			yield sys.stdin.readline()
inputs = stdinWrapper()

def inputWrapper():
	return next(inputs)

def getType(_type):
	return _type(inputWrapper())

def getArray(_type):
	return [_type(x) for x in inputWrapper().split()]

def tuplerize(method):

	def wrap(*args, **kwargs):
		res = method(*args, **kwargs)
		if not isinstance(res, (tuple, list)):
			res = (res,)
		return res
	return wrap

@tuplerize
def solve(a):
	lsum = 0
	pref = [0] * len(a)
	for i in range(len(a)):
		pref[i] = lsum
		lsum += a[i]
	pref.append(lsum)
	summs = set()
	res = 0
	for i in range(len(pref)):
		if pref[i] in summs:
			res += 1
			summs = {pref[i - 1]}
		summs.add(pref[i])
	return res
t = getType(int)
a = getArray(int)
res = solve(a)
print(*res)


import sys
import math as m

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l
mod = int(1000000000.0) + 7

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def linp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(a):
	print(a)

def p2(a, b):
	print(a, b)
n = iinp()
a = linp()
s = {0}
sum = 0
ans = 0
for i in a:
	sum += i
	if sum in s:
		ans += 1
		sum = i
		s = {0, sum}
	else:
		s.add(sum)
print(ans)


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
a = gil()
a.append(0)
d = set([0])
ans = 0
cv = 0
for i in range(n):
	cv += a[i]
	if cv in d:
		ans += 1
		cv = a[i]
		d.clear()
		d.add(0)
	d.add(cv)
print(ans)


from sys import stdout, stdin, setrecursionlimit
from bisect import insort, bisect, bisect_right
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = getInt()
arr = zzz()
ans = 0
prev = 0
s = set()
s.add(0)
for i in arr:
	prev += i
	if prev in s:
		ans += 1
		s = set()
		s.add(i)
		s.add(0)
		prev = i
	else:
		s.add(prev)
print(ans)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	s = {0}
	acc = 0
	ans = 0
	for x in a:
		acc += x
		if acc in s:
			ans += 1
			s = {0, x}
			acc = x
		else:
			s.add(acc)
	print(ans)
tn = 1
for _ in range(tn):
	main()


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(lambda : -1)
lv = 0
ps = [0] * (n + 1)
x = 0
for i in range(len(a)):
	ps[i + 1] = ps[i] + a[i]
for i in range(len(a) + 1):
	if d[ps[i]] == -1:
		d[ps[i]] = i
	else:
		if d[ps[i]] >= lv - 1:
			x += 1
			lv = i
		d[ps[i]] = i
print(x)


from sys import stdin, stdout, setrecursionlimit
import threading

class Tail_Recursion_Optimization:

	def __init__(self, RECURSION_LIMIT, STACK_SIZE):
		setrecursionlimit(RECURSION_LIMIT)
		threading.stack_size(STACK_SIZE)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		n = int(R())
		a = [int(x) for x in R().split()]
		d = {0: True}
		s = 0
		cnt = 0
		for j in range(n):
			s += a[j]
			if s in d:
				d = {0: True}
				s = a[j]
				cnt += 1
			d[s] = True
		W('%d\n' % cnt)
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


import sys
n = int(sys.stdin.readline())
a = [int(i) for i in sys.stdin.readline().split()]
d = {}
d[0] = 1
cur = 0
ans = 0
for h in range(n):
	cur += a[h]
	if cur in d:
		ans += 1
		d = {}
		d[0] = 1
		cur = a[h]
	d[cur] = 1
print(ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n = int(input())
arr = list(map(int, input().split()))
occ = {0: [-1]}
s = 0
ans = 0
MAX = 999999999999999999
ind = 0
while ind < len(arr):
	val = arr[ind]
	s += val
	if s in occ:
		ans += 1
		s -= val
		s += MAX
		ind -= 1
	else:
		occ[s] = 1
		ind += 1
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
(sm, ans) = (0, 0)
st = set()
st.add(0)
for x in a:
	sm += x
	if sm in st:
		ans += 1
		st.clear()
		st.add(0)
		sm = x
	st.add(sm)
print(ans)


n = int(input())
a = list(map(int, input().split()))
prefixes = set()
curr = 0
ans = 0
for i in range(n):
	curr += a[i]
	if curr == 0 or curr in prefixes:
		ans += 1
		curr = a[i]
		prefixes.clear()
	prefixes.add(curr)
print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = 1
for _ in range(t):
	n = ip()
	arr = list(inp())
	ans = 0
	dic = dd(bool)
	ans = 0
	dic[0] = True
	p = 0
	for i in range(n):
		p += arr[i]
		if dic[p]:
			p = arr[i]
			dic = dd(bool)
			dic[0] = True
			ans += 1
		dic[p] = True
	out(ans)


n = int(input())
a = list(map(int, input().split()))
dic = {}
s = 0
count = 0
for (i, item) in enumerate(a):
	s += item
	if s == 0:
		s = a[i]
		dic = {}
		dic[s] = i
		count += 1
	elif s not in dic:
		dic[s] = i
	else:
		dic = {}
		s = a[i]
		dic[s] = i
		count += 1
print(count)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def toord(c):
	return ord(c) - ord('a')

def lcm(a, b):
	return a * b // gcd(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	n = N()
	arr = RLL()
	dic = defaultdict(int)
	sm = 0
	dl = -1
	res = 0
	dic[0] = -1
	for i in range(n):
		sm += arr[i]
		now = sm
		if now in dic:
			pre = dic[now]
			if pre + 1 >= dl:
				res += 1
				dl = i
		dic[sm] = i
	print(res)
main()


n = int(input())
arr = list(map(lambda x: int(x), input().split(' ')))
count = {0: 1}
ans = 0
ssum = 0
for x in arr:
	ssum += x
	if ssum in count:
		ans += count[ssum]
		count = {0: 1}
		ssum = x
		count[ssum] = 1
	else:
		count[ssum] = 1
print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt

def solve():
	n = scanner()
	a = get_list()
	pre = [a[0]]
	for x in a[1:]:
		pre.append(pre[-1] + x)
	mapp = {}
	mapp[pre[0]] = 0
	mapp[0] = 0
	ans = 0
	prev_pos = 0
	for i in range(1, n):
		if mapp.get(pre[i]) != None:
			pos = mapp[pre[i]] + 1
			if pos >= prev_pos:
				prev_pos = i
				ans += 1
		mapp[pre[i]] = i
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = 1
for i in range(t):
	solve()


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()

def fun(a, n):
	s = set()
	s.add(0)
	c = 0
	Sum = 0
	for x in a:
		Sum += x
		if Sum in s:
			c += 1
			s = set()
			s.add(0)
			s.add(x)
			Sum = x
		else:
			s.add(Sum)
	return c
n = int(I1())
a = list(I())
print(fun(a, n))


n = int(input())
a = list(map(int, input().split()))
pre = ans = 0
visited = set([0])
for i in a:
	pre += i
	if pre in visited:
		ans += 1
		visited.clear()
		visited.add(0)
		pre = i
	visited.add(pre)
print(ans)


from math import *
from sys import *
input = stdin.readline
for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	d = {0: 1}
	cn = 0
	sn = 0
	for i in range(n):
		sn += a[i]
		if d.get(sn, 0) == 1:
			sn = a[i]
			cn += 1
			d = {0: 1, a[i]: 1}
		else:
			d[sn] = 1
	stdout.write(str(cn) + '\n')


n = int(input())
arr = list(map(int, input().split()))
pre = set()
pre.add(0)
cur = 0
ans = 0
for i in range(n):
	cur += arr[i]
	if cur in pre:
		ans += 1
		pre = set()
		pre.add(0)
		cur = arr[i]
	pre.add(cur)
print(ans)


def solve(n, arr):
	ans = 0
	res = {0}
	current = 0
	for i in range(n):
		current += arr[i]
		if current in res:
			ans += 1
			res = {0}
			current = arr[i]
		res |= {current}
	return ans

def main():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	ans = solve(n, arr)
	print(ans)
	return ans
main()


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
S = 0
P = {0}
ans = 0
for a in A:
	S += a
	if S in P:
		P = {0}
		S = a
		ans += 1
	P.add(S)
print(ans)


n = int(input())
a = list(map(int, input().split()))
cnt = 0
s = 0
v = {0: -1}
lol = -1
for i in range(n):
	s += a[i]
	if s in v:
		if v[s] + 1 >= lol:
			cnt += 1
			lol = i
	v[s] = i
print(cnt)


import math

def getInts():
	return list(map(int, input().split()))

def getInt():
	return int(input())
t = getInt()
a = getInts()
s = set()
s.add(0)
cnt = 0
sum = 0
for numbers in a:
	sum += numbers
	if sum in s:
		cnt += 1
		s.clear()
		s.add(0)
		sum = numbers
	s.add(sum)
print(cnt)


import sys
import math
from bisect import bisect_right as br
from statistics import mode
from itertools import combinations as cb

def int_arr():
	return list(map(int, sys.stdin.readline().strip().split()))

def str_arr():
	return list(map(str, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
n = int(input())
arr = int_arr()
dict = {0: True}
sm = 0
ans = 0
for i in range(n):
	sm += arr[i]
	if dict.get(sm) == True:
		ans += 1
		dict = {0: True}
		dict[arr[i]] = True
		sm = arr[i]
	else:
		dict[sm] = True
print(ans)


from functools import *
n = int(input())
arr = [int(x) for x in input().split()]
inf = 98765567890876
dp = [inf for i in range(n)]
prefix = [0]
for e in arr:
	prefix.append(prefix[-1] + e)
d = {}
interval = []
for (i, e) in enumerate(prefix):
	if e in d:
		interval.append([d[e], i - 1])
		d[e] = i
	else:
		d[e] = i
arr = []
for (i, e) in enumerate(interval):
	(a, b) = e
	arr.append([a, 1, i])
	arr.append([b, 0, i])
arr.sort()
d = {}
s = set()
ans = 0
for (i, j, index) in arr:
	if index in d:
		continue
	if j == 1:
		s.add(index)
	else:
		ans += 1
		for ele in s:
			d[ele] = True
		s = set()
print(ans)


n = eval(input())
a = input()
a = list(map(eval, a.split()))
ans = 0
sum = 0
mp = {}
mp[0] = 1
for i in range(n):
	sum += a[i]
	if sum in mp:
		ans += 1
		mp.clear()
		mp[0] = 1
		sum = a[i]
		mp[sum] = 1
	else:
		mp[sum] = 1
print(ans)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	pref = [0]
	for x in A:
		pref.append(pref[-1] + x)
	intervals = []
	lastIndex = {}
	for (i, x) in enumerate(pref):
		if x in lastIndex:
			intervals.append((lastIndex[x], i))
		lastIndex[x] = i
	stabs = []
	for (x, y) in intervals:
		if stabs and x < stabs[-1]:
			continue
		else:
			stabs.append(y - 1)
	return len(stabs)
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, A)
print(ans)


n = int(input())
l = list(map(int, input().split()))
cur = 0
ans = 0
d = set()
d.add(0)
for i in range(len(l)):
	cur += l[i]
	if cur in d:
		ans += 1
		d = set()
		d.add(0)
		cur = l[i]
	d.add(cur)
print(ans)


n = int(input())
b = list(map(int, input().split()))
ans = 0
j = 0
d = dict()
s = 0
d[0] = 1
while j < n:
	if s + b[j] in d.keys():
		ans += 1
		d = dict()
		d[0] = 1
		s = b[j]
		d[s] = 1
	else:
		s += b[j]
		d[s] = 1
	j += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
d = set()
d.add(0)
sm = 0
c = 0
for i in range(n):
	sm += a[i]
	if sm in d:
		c += 1
		d = set()
		d.add(0)
		sm = a[i]
	d.add(sm)
print(c)


import math

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	dict = {}
	dict[0] = 1
	(sum, ans) = (0, 0)
	for i in range(0, n):
		sum += a[i]
		if sum in dict.keys():
			ans += 1
			dict = {}
			dict[0] = 1
			sum = a[i]
			dict[sum] = 1
		else:
			dict[sum] = 1
	print(ans)
t = 1
for _ in range(0, t):
	solve()


def subArrayExists(arr, n):
	n_sum = 0
	s = set()
	c = 0
	for i in range(n):
		n_sum += arr[i]
		if n_sum == 0 or n_sum in s:
			c = c + 1
			s.clear()
			n_sum = arr[i]
		s.add(n_sum)
	return c
n = int(input())
a = list(map(int, input().split()))
l = subArrayExists(a, n)
print(l)


n = int(input())
l = list(map(int, input().split()))
x = 0
for i in range(n):
	if l[i] < 0:
		x += l[i]
x *= -1
x += 1
s = set()
count = 0
sum = 0
for i in range(n):
	sum += l[i]
	if sum == 0:
		count += 1
		s.add(sum + x)
		s.add(sum - l[i] + x)
		sum = x
	elif sum in s:
		count += 1
		s.add(sum - l[i] + x)
		s.add(sum + x)
		sum += x
	else:
		s.add(sum)
print(count)


from functools import cmp_to_key
from collections import deque
from heapq import heappush, heappop
from math import log, ceil
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def ii():
	return int(inp())

def li(lag=0):
	l = list(map(int, inp().split()))
	if lag != 0:
		for i in range(len(l)):
			l[i] += lag
	return l

def mi(lag=0):
	matrix = list()
	for i in range(n):
		matrix.append(li(lag))
	return matrix

def sli():
	return list(map(str, inp().split()))

def print_list(lista, space=' '):
	print(space.join(map(str, lista)))

class UnionFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def bisect_left(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] < x:
			left = mid + 1
		else:
			right = mid
	return left

def bisect_right(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] > x:
			right = mid
		else:
			left = mid + 1
	return left

def bisect_elements(a, x):
	return bisect_right(a, x) - bisect_left(a, x)

def custom_sort(lista):

	def cmp(x, y):
		if x + y > y + x:
			return 1
		else:
			return -1
	return sorted(lista, key=cmp_to_key(cmp))
MOD = 10 ** 9 + 7
maxN = 10 ** 5
FACT = [0] * maxN

def add(x, y):
	return (x + y) % MOD

def multiply(x, y):
	return x * y % MOD

def power(x, y):
	if y == 0:
		return 1
	elif y % 2:
		return multiply(x, power(x, y - 1))
	else:
		a = power(x, y // 2)
		return multiply(a, a)

def inverse(x):
	return power(x, MOD - 2)

def divide(x, y):
	return multiply(x, inverse(y))

def allFactorials():
	FACT[0] = 1
	for i in range(1, maxN):
		FACT[i] = multiply(i, FACT[i - 1])

def coeffBinom(n, k):
	if n < k:
		return 0
	return divide(FACT[n], multiply(FACT[k], FACT[n - k]))

def primes(N):
	smallest_prime = [1] * (N + 1)
	prime = []
	smallest_prime[0] = 0
	smallest_prime[1] = 0
	for i in range(2, N + 1):
		if smallest_prime[i] == 1:
			prime.append(i)
			smallest_prime[i] = i
		j = 0
		while j < len(prime) and i * prime[j] <= N:
			smallest_prime[i * prime[j]] = min(prime[j], smallest_prime[i])
			j += 1
	return (prime, smallest_prime)

def gcd(a, b):
	(s, t, r) = (0, 1, b)
	(old_s, old_t, old_r) = (1, 0, a)
	while r != 0:
		quotient = old_r // r
		(old_r, r) = (r, old_r - quotient * r)
		(old_s, s) = (s, old_s - quotient * s)
		(old_t, t) = (t, old_t - quotient * t)
	return (old_r, old_s, old_t)

def create_graph(n, m, undirected=1, unweighted=1):
	graph = [[] for i in range(n)]
	if unweighted:
		for i in range(m):
			[x, y] = li(lag=-1)
			graph[x].append(y)
			if undirected:
				graph[y].append(x)
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			graph[x].append([y, w])
			if undirected:
				graph[y].append([x, w])
	return graph

def create_tree(n, unweighted=1):
	children = [[] for i in range(n)]
	if unweighted:
		for i in range(n - 1):
			[x, y] = li(lag=-1)
			children[x].append(y)
			children[y].append(x)
	else:
		for i in range(n - 1):
			[x, y, w] = li(lag=-1)
			w += 1
			children[x].append([y, w])
			children[y].append([x, w])
	return children

def create_edges(m, unweighted=0):
	edges = list()
	if unweighted:
		for i in range(m):
			edges.append(li(lag=-1))
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			edges.append([w, x, y])
	return edges

def dist(tree, n, A, B=-1):
	s = [[A, 0]]
	(massimo, massimo_nodo) = (0, 0)
	distanza = -1
	v = [-1] * n
	while s:
		(el, dis) = s.pop()
		if dis > massimo:
			massimo = dis
			massimo_nodo = el
		if el == B:
			distanza = dis
		for child in tree[el]:
			if v[child] == -1:
				v[child] = 1
				s.append([child, dis + 1])
	return (massimo, massimo_nodo, distanza)

def diameter(tree):
	(_, foglia, _) = dist(tree, n, 0)
	(diam, _, _) = dist(tree, n, foglia)
	return diam

def dfs(graph, n, A):
	v = [-1] * n
	s = [[A, 0]]
	v[A] = 0
	while s:
		(el, dis) = s.pop()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def bfs(graph, n, A):
	v = [-1] * n
	s = deque()
	s.append([A, 0])
	v[A] = 0
	while s:
		(el, dis) = s.popleft()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def connected(graph, n):
	v = dfs(graph, n, 0)
	for el in v:
		if el == -1:
			return False
	return True

def topological(graph, n):
	indegree = [0] * n
	for el in range(n):
		for child in graph[el]:
			indegree[child] += 1
	s = deque()
	for el in range(n):
		if indegree[el] == 0:
			s.append(el)
	order = []
	while s:
		el = s.popleft()
		order.append(el)
		for child in graph[el]:
			indegree[child] -= 1
			if indegree[child] == 0:
				s.append(child)
	if n == len(order):
		return (False, order)
	else:
		return (True, [])

def bipartite(graph, n):
	color = [-1] * n
	color[0] = 0
	s = [0]
	while s:
		el = s.pop()
		for child in graph[el]:
			if color[child] == color[el]:
				return False
			if color[child] == -1:
				s.append(child)
			color[child] = 1 - color[el]
	return True

def dijkstra(graph, n, A):
	dist = [float('inf') for i in range(n)]
	prev = [-1 for i in range(n)]
	dist[A] = 0
	pq = []
	heappush(pq, [0, A])
	while pq:
		[d_v, v] = heappop(pq)
		if d_v != dist[v]:
			continue
		for (to, w) in graph[v]:
			if dist[v] + w < dist[to]:
				dist[to] = dist[v] + w
				prev[to] = v
				heappush(pq, [dist[to], to])
	return (dist, prev)

def dijkstra_0_1(graph, n, A):
	dist = [float('inf') for i in range(n)]
	dist[A] = 0
	p = deque()
	p.append(A)
	while p:
		v = p.popleft()
		for (to, w) in graph[v]:
			if dist[v] + w < dist[to]:
				dist[to] = dist[v] + w
			if w == 1:
				q.append(to)
			else:
				q.appendleft(to)
	return dist

def floyd_warshall(graph, n):
	dist = [[float('inf') for _ in range(n)] for _ in range(n)]
	for i in range(n):
		dist[i][i] = 0
		for (child, d) in graph[i]:
			dist[i][child] = d
			dist[child][i] = d
	for k in range(n):
		for i in range(n):
			for j in range(j):
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
	return dist

def minimum_spanning_tree(edges, n):
	edges = sorted(edges)
	union_find = UnionFind(n)
	used_edges = list()
	for (w, x, y) in edges:
		if union_find.find(x) != union_find.find(y):
			union_find.merge(x, y)
			used_edges.append([w, x, y])
	return used_edges

def parents_children_root_unrooted_tree(tree, n, root=0):
	q = deque()
	visited = [0] * n
	parent = [-1] * n
	children = [[] for i in range(n)]
	q.append(root)
	while q:
		all_done = 1
		visited[q[0]] = 1
		for child in tree[q[0]]:
			if not visited[child]:
				all_done = 0
				q.appendleft(child)
		if all_done:
			for child in tree[q[0]]:
				if parent[child] == -1:
					parent[q[0]] = child
					children[child].append(q[0])
			q.popleft()
	return (parent, children)

def all_longest_path_passing_from_node(parent, children, n):
	q = deque()
	visited = [len(children[i]) for i in range(n)]
	downwards = [[0, 0] for i in range(n)]
	upward = [1] * n
	longest_path = [1] * n
	for i in range(n):
		if not visited[i]:
			q.append(i)
			downwards[i] = [1, 0]
	while q:
		node = q.popleft()
		if parent[node] != -1:
			visited[parent[node]] -= 1
			if not visited[parent[node]]:
				q.append(parent[node])
		else:
			root = node
		for child in children[node]:
			downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse=True)[0:2]
	s = [node]
	while s:
		node = s.pop()
		if parent[node] != -1:
			if downwards[parent[node]][0] == downwards[node][0] + 1:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
			else:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
		longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
		for child in children[node]:
			s.append(child)
	return longest_path

def finding_ancestors(parent, queries, n):
	steps = int(ceil(log(n, 2)))
	ancestors = [[-1 for i in range(n)] for j in range(steps)]
	ancestors[0] = parent
	for i in range(1, steps):
		for node in range(n):
			if ancestors[i - 1][node] != -1:
				ancestors[i][node] = ancestors[i - 1][ancestors[i - 1][node]]
	result = []
	for (node, k) in queries:
		ans = node
		if k >= n:
			ans = -1
		i = 0
		while k > 0 and ans != -1:
			if k % 2:
				ans = ancestors[i][ans]
			k = k // 2
			i += 1
		result.append(ans)
	return result

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def nearest_from_the_left_smaller_elements(arr):
	n = len(arr)
	res = [-1] * n
	s = []
	for (i, el) in enumerate(arr):
		while s and s[-1] >= el:
			s.pop()
		if s:
			res[i] = s[-1]
		s.append(el)
	return res

def sliding_window_minimum(arr, k):
	res = []
	q = deque()
	for (i, el) in enumerate(arr):
		while q and arr[q[-1]] >= el:
			q.pop()
		q.append(i)
		while q and q[0] <= i - k:
			q.popleft()
		if i >= k - 1:
			res.append(arr[q[0]])
	return res
n = ii()
a = li()
i = 0
pre = 0
s = 0
d = set()
d.add(0)
while i < n:
	if pre + a[i] in d:
		s += 1
		d = set()
		d.add(0)
		pre = 0
	else:
		pre += a[i]
		d.add(pre)
		i += 1
print(s)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
d = {0}
ans = total = 0
for i in a:
	total += i
	if total in d:
		ans += 1
		d = {0}
		total = i
	d.add(total)
print(ans)


def solve(n, res):
	m = set()
	m.add(0)
	s = 0
	ans = 0
	for x in res:
		s += x
		if s in m:
			ans += 1
			m = set()
			m.add(0)
			s = x
		m.add(s)
	return ans
n = int(input())
res = []
in_ = map(int, input().split(' '))
for x in in_:
	res.append(int(x))
print(solve(n, res))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var, end='\n'):
	sys.stdout.write(str(var) + end)

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
s = 0
d = dd(int)
answer = 0
i = 0
while i < n:
	s += arr[i]
	if s == 0 or s in d.keys():
		answer += 1
		s = 0
		d.clear()
	else:
		i += 1
	d[s] = i
out(answer)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	d[0] = -1
	s = 0
	cnt = 0
	for i in a:
		s += i
		if s in d:
			cnt += 1
			d = {}
			d[0] = -1
			s = i
		d[s] = i
	print(cnt)
	return

def main():
	t = 1
	for _ in range(t):
		solve()
main()


def solve(size, array):
	should_be_changed = 0
	partial_sums = [i for i in array]
	sums = set([0, partial_sums[0]])
	for i in range(1, size):
		partial_sums[i] += partial_sums[i - 1]
		if partial_sums[i] in sums:
			should_be_changed += 1
			partial_sums[i] = array[i]
			sums = set([0])
		sums.add(partial_sums[i])
	return should_be_changed
size = int(input().strip())
array = [int(x) for x in input().strip().split()]
print(solve(size, array))


case = int(input())
s = {0}
cur = 0
ans = 0
lst = [int(x) for x in input().split(' ')]
for i in range(case):
	cur += lst[i]
	if cur in s:
		ans += 1
		s = {0}
		cur = lst[i]
	s.add(cur)
print(ans)


import sys
inline = sys.stdin.readline

def solution(arr):
	count = 0
	cursum = 0
	presum = {0: -1}
	l0 = float('-inf')
	for (i, num) in enumerate(arr):
		cursum += num
		if cursum in presum and l0 < presum[cursum]:
			count += 1
			l0 = i - 2
		presum[cursum] = i
	return count
_ = int(inline().strip())
arr = list(map(int, inline().strip().split()))
print(solution(arr))


import sys
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from math import *

def fun(nums):
	dic = {}
	dic[0] = 1
	ans = curr = 0
	for (i, num) in enumerate(nums):
		curr += num
		prev = curr
		if prev in dic:
			ans += dic[prev]
			dic = {}
			dic[0] = 1
			curr = nums[i]
		dic[curr] = 1
	return ans
n = ii1()
arr = iia()
ans = fun(arr)
print(ans)


n = int(input())
a = list(map(int, input().split()))
d = {0}
cur_sum = 0
total = 0
for i in range(n):
	cur_sum += a[i]
	if cur_sum in d:
		total += 1
		cur_sum = a[i]
		d = {0}
	d.add(cur_sum)
print(total)


leng = int(input())
array = list(map(int, input().split()))
sums = set()
sums.add(0)
ans = 0
cur = 0
for i in array:
	cur += i
	if cur in sums:
		cur = i
		ans += 1
		sums = set()
		sums.add(0)
		sums.add(cur)
	else:
		sums.add(cur)
print(ans)


def cal(n, arr):
	dic = {}
	res = 0
	cur_sum = 0
	for num in arr:
		cur_sum += num
		if cur_sum in dic or cur_sum == 0:
			res += 1
			dic = {}
			cur_sum = num
		dic[cur_sum] = True
	return res
n = int(input())
arr = list(map(int, input().split()))
print(cal(n, arr))


n = int(input())
vals = [int(x) for x in input().split()]
sum = 0
seen_sums = {0}
count = 0
for x in vals:
	sum += x
	if sum in seen_sums:
		count += 1
		seen_sums = {0, x}
		sum = x
	else:
		seen_sums.add(sum)
print(count)


n = int(input())
l = list(map(int, input().split()))
d = {0: -1}
arr = []
curr = 0
for (i, el) in enumerate(l):
	curr += el
	if curr in d:
		arr.append((d[curr] + 1, i))
	d[curr] = i
if len(arr) == 0:
	print(0)
else:
	arr.sort(key=lambda x: x[1])
	prevend = arr[0][1]
	count = 1
	for i in range(1, len(arr)):
		if arr[i][0] >= prevend:
			count += 1
			prevend = arr[i][1]
	print(count)


n = int(input())
A = [int(i) for i in input().split()]
cumm = [A[0]] * n
d = {A[0]: [0]}
count = 0
last_idx = -1
for i in range(1, n):
	cumm[i] = cumm[i - 1] + A[i]
	if cumm[i] == 0 and last_idx == -1:
		count += 1
		last_idx = i
	elif cumm[i] in d:
		l = d[cumm[i]]
		if l[-1] >= last_idx - 1:
			count += 1
			last_idx = i
	if cumm[i] not in d:
		d[cumm[i]] = []
	d[cumm[i]].append(i)
print(count)


n = int(input())
a = list(map(int, input().split()))
aset = set()
aset.add(0)
sum = 0
ans = 0
for i in range(0, n):
	sum = sum + a[i]
	if sum in aset:
		ans = ans + 1
		aset = set()
		aset.add(0)
		sum = a[i]
	aset.add(sum)
print(ans)


import sys, threading
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def rl(type):
	return [type(w) for w in input().split()]

def reverse(arr):
	return arr[-1::-1]

def mod(a, m):
	return (a % m + m) % m

def check_prime(n):
	temp = int(math.sqrt(n) + 1)
	for i in range(2, temp):
		if n % i == 0:
			return False
	return True

def create_graph(n):
	graph = {}
	for _ in range(n):
		(x, y) = map(int, input().split())
		graph[x].append(y)
		graph[y].append(x)
	return graph

def main():
	n = int(input())
	arr = rl(int)
	d = defaultdict(int)
	d[0] = 1
	prefixSum = 0
	result = 0
	for i in arr:
		prefixSum += i
		if prefixSum == 0 or d.get(prefixSum) is not None:
			result += 1
			d = defaultdict()
			d[0] = 1
			prefixSum = i
		d[prefixSum] = 1
	print(result)
sys.setrecursionlimit(10 ** 6)
threading.stack_size(10 ** 8)
t = threading.Thread(target=main)
t.start()
t.join()


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)
n = int(input())
l = list(map(int, input().split()))
cs = 0
covsum = {0}
a = 0
for i in range(0, n):
	cs += l[i]
	if cs in covsum:
		a += 1
		covsum = {0, l[i]}
		cs = l[i]
	else:
		covsum.add(cs)
print(a)


n = int(input())
arr = [int(x) for x in input().split()]
ans = 0
segmentPrefixSums = {0}
segmentSum = 0
for i in range(n):
	segmentSum += arr[i]
	if segmentSum in segmentPrefixSums:
		ans += 1
		segmentSum = arr[i]
		segmentPrefixSums = {0}
	segmentPrefixSums.add(segmentSum)
print(ans)


from sys import stdin, stdout
input = stdin.readline
n = int(input())
arr = list(map(int, input().split()))
c = 0
su = 0
dic = {}
i = 0
fixed = -1
dic[0] = -1
for d in arr:
	su += d
	if su == 0:
		if dic[su] >= fixed - 1:
			c += 1
			fixed = i
		dic[su] = i
	elif su in dic:
		if dic[su] >= fixed - 1:
			c += 1
			fixed = i
		dic[su] = i
	if su not in dic:
		dic[su] = i
	i += 1
print(c)


from sys import stdin, stdout, setrecursionlimit
import heapq
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
n = ii1()
arr = iia()
d = set([0])
tot = cnt = 0
for i in range(len(arr)):
	tot += arr[i]
	if tot in d:
		cnt += 1
		tot = arr[i]
		d = set([0])
	d.add(tot)
print(cnt)


while True:
	try:
		n = int(input())
		tmp = list(map(int, input().split()))
		mmap = {0}
		sum = 0
		ans = 0
		for i in tmp:
			sum += i
			if sum in mmap:
				ans += 1
				mmap = {0}
				sum = i
			mmap.add(sum)
		print(ans)
	except EOFError:
		break


n = int(input())
A = list(map(int, input().split()))
from itertools import accumulate
C = [0] + A
C = list(accumulate(C))
d = {}
ans = 0
for (i, c) in enumerate(C):
	if c in d:
		ans += 1
		d = {}
		d[c] = 1
		if i != 0:
			d[C[i - 1]] = 1
	else:
		d[c] = 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
ct = 0
cur_sum = 0
seen = set()
seen.add(0)
for i in range(n):
	cur_sum += a[i]
	if cur_sum in seen:
		seen = {0}
		ct += 1
		cur_sum = a[i]
	seen.add(cur_sum)
print(ct)


import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
d = defaultdict(int)
v = list(map(int, input().split()))
(cur, ans, flag) = (0, 0, 1)
color = 1
d[0] = 1
for i in range(n):
	cur += v[i]
	if d[cur] == color:
		ans += 1
		color += 1
		d[v[i]] = color
		d[0] = color
		cur = v[i]
	else:
		d[cur] = color
print(ans)


import sys
import math as mt
import bisect
input = sys.stdin.readline
t = 1

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	d = {}
	d[0] = -2
	(curr, rec, ans) = (0, -3, 0)
	for i in range(n):
		curr += l[i]
		x = curr
		if d.get(x, -1) != -1:
			if d[x] + 1 > rec:
				rec = i - 1
				ans += 1
		d[curr] = i
	return ans
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(solve())


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		dp = set()
		dp.add(0)
		pre = 0
		ans = 0
		for i in range(n):
			pre += l[i]
			if pre not in dp:
				dp.add(pre)
			else:
				ans += 1
				dp.clear()
				pre = l[i]
				dp.add(0)
				dp.add(pre)
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


n = int(input())
array = list(map(int, input().split()))
mark = {0: True}
ans = 0
preSum = 0
for digit in array:
	preSum += digit
	if mark.get(preSum, False):
		ans += 1
		mark = {0: True}
		preSum = digit
	mark[preSum] = True
print(ans)


import sys
import math
n = int(input())
arr = [int(i) for i in input().split()]
segs = set()
segs.add(0)
s = 0
res = 0
for elem in arr:
	s += elem
	if s in segs:
		res += 1
		segs = set()
		segs.add(0)
		s = elem
	segs.add(s)
print(res)


n_numbers = int(input())
ans = 0
current_sum = int(0)
sums = set([current_sum])
for _ in input().split():
	new_num = int(_)
	current_sum += new_num
	if current_sum in sums:
		current_sum = new_num
		sums = set([0, current_sum])
		ans += 1
	else:
		sums.add(current_sum)
print(ans)


n = int(input())
s = list(map(int, input().split()))
b = set()
b.add(0)
(cur, counter) = (0, 0)
for i in range(0, n):
	cur += s[i]
	if cur in b:
		cur = s[i]
		counter += 1
		b = set()
		b.add(0)
		b.add(cur)
	else:
		b.add(cur)
print(counter)


from __future__ import division, print_function
import math
import os
import sys
from sys import stdin, stdout
from io import BytesIO, IOBase
from collections import deque
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	d = set()
	d.add(0)
	cur = 0
	ans = 0
	for i in range(n):
		cur += arr[i]
		if cur in d:
			ans += 1
			d = set()
			d.add(0)
			cur = arr[i]
		d.add(cur)
	print(ans)
main()


n = int(input())
a = list(map(int, input().split()))
s = {0}
(sm, cnt) = (0, 0)
for i in a:
	sm += i
	if sm in s:
		s = {0}
		cnt += 1
		sm = i
	s.add(sm)
print(cnt)


import sys
import math
import itertools
input = sys.stdin.readline
n = int(input())
ans = 0
a = [int(x) for x in input().split()]
s = 0
was = set()
was.add(0)
for i in range(n):
	s += a[i]
	if s in was:
		ans += 1
		was.clear()
		was.add(0)
		s = a[i]
	was.add(s)
print(ans)


n = int(input())
arr = list(map(int, input().strip().split()))
d = {}
d[0] = -1
ans = s = curr = 0
for i in range(len(arr)):
	s += arr[i]
	if s in d and curr <= d[s] + 1:
		ans += 1
		curr = i
	d[s] = i
print(ans)


n = int(input())
a = list(map(int, input().split()))
freq = {}
freq[a[0]] = 1
Sum = a[0]
cnt = 0
for i in range(n - 1):
	if Sum + a[i + 1] == 0 or freq.get(Sum + a[i + 1], 0) > 0:
		Sum = a[i + 1]
		cnt += 1
		freq = {}
		freq[Sum] = 1
	else:
		Sum += a[i + 1]
		if freq.get(Sum, 0) == 0:
			freq[Sum] = 1
		else:
			freq[Sum] += 1
print(cnt)


import math
from collections import deque
from collections import defaultdict
n = int(input())
arr = list(map(int, input().strip().split(' ')))
ans = 0

def getSub(l):
	mp = {}
	rt = -1
	sm = 0
	for i in range(l, n):
		sm += arr[i]
		if sm == 0:
			rt = i
			break
		if mp.get(sm) is not None:
			rt = i
			break
		mp[sm] = 1
	return rt
i = 0
while i < n:
	j = getSub(i)
	if j == -1:
		break
	ans += 1
	i = j
print(ans)


n = int(input())
a = list(map(int, input().split()))
answer = 0
b = []
for i in a:
	if len(b) == 0:
		b.append(i)
	else:
		b.append(b[len(b) - 1] + i)
c = {0}
q = 0
for i in b:
	if i in c:
		c.clear()
		c.add(q)
		answer += 1
	c.add(i)
	q = i
print(answer)


n = int(input())
arr = [int(i) for i in input().split()]
cnt = {0: 1}
cnt[0] = 1
su = 0
res = 0
for i in range(n):
	su += arr[i]
	temp = -su
	if su == 0 or su in cnt:
		res += 1
		cnt.clear()
		cnt[arr[i]] = 1
		su = arr[i]
	else:
		cnt[su] = 1
print(res)


n = int(input())
data = list(map(int, input().split()))
check_dict = {0: True}
sum = 0
result = 0
for i in range(n):
	sum += data[i]
	if check_dict.get(sum):
		result += 1
		check_dict = {0: True, data[i]: True}
		sum = data[i]
	else:
		check_dict[sum] = True
print(result)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
S = [0]
for a in A:
	S.append(S[-1] + a)
ANS = 0
SET = set()
for i in range(n + 1):
	if S[i] in SET:
		ANS += 1
		SET = {S[i], S[i - 1]}
	else:
		SET.add(S[i])
print(ANS)


n = int(input())
numbers = list(map(int, input().split()))
pr = set()
pr.add(0)
cur_sum = 0
counter = 0
for i in range(0, n):
	cur_sum += numbers[i]
	if cur_sum in pr:
		counter += 1
		cur_sum = numbers[i]
		pr.clear()
		pr.add(0)
		pr.add(numbers[i])
	else:
		pr.add(cur_sum)
print(counter)


def main():
	n = int(input())
	c = 0
	arr = [int(k) for k in input().split()]
	m = {0}
	s = 0
	for i in range(n):
		s += arr[i]
		if s in m:
			c += 1
			m = {0}
			s = arr[i]
			m.add(arr[i])
		m.add(s)
	print(c)
main()


def f(n, a):
	res = 0
	seen = {}
	su = 0
	steps = 0
	for i in a:
		su += i
		if su == 0 or su in seen:
			steps += 1
			seen = {i: 0}
			su = i
		else:
			seen[su] = 0
	return steps
n = int(input())
a = [int(x) for x in input().split()]
print(f(n, a))


import bisect
import array
import functools
import math
n = int(input())
a = array.array('i', map(int, input().split()))
(sum, ans) = (0, 0)
mp = dict()
mp[0] = 0
for i in range(n):
	sum = sum + a[i]
	if sum in mp:
		mp = dict()
		mp[sum - a[i]] = 1
		ans = ans + 1
	mp[sum] = 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = 0
d = {}
ans = 0
for i in range(n):
	s = s + a[i]
	if s == 0:
		ans += 1
		s = a[i]
		d = {}
		d[s] = 1
	else:
		x = d.get(s, 0)
		if x:
			ans += 1
			s = a[i]
			d = {}
			d[s] = 1
		else:
			d[s] = 1
print(ans)


n = int(input())
ar = list(map(int, input().split()))
summ = 0
d = {0: 1}
ans = 0
for i in range(n):
	summ += ar[i]
	if summ in d:
		ans += 1
		d = {0: 1}
		summ = ar[i]
		d[summ] = 1
	else:
		d[summ] = 1
print(ans)


import os
import sys
from io import BytesIO, IOBase
import math

def main1():
	for _ in range(int(input())):
		(n, x) = map(int, input().split())
		if n <= 2:
			print(1)
		else:
			n -= 2
			print(1 + math.ceil(n / x))

def main2():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		flag = 0
		for i in range(n):
			mat = []
			for j in range(2):
				mat.append(list(map(int, input().split())))
			if mat[0][1] == mat[1][0]:
				flag = 1
		if m % 2 or flag == 0:
			print('NO')
		else:
			print('YES')

def main3():
	for _ in range(int(input())):
		n = int(input())
		ans = float('inf')
		for i in range(1, math.floor(math.sqrt(n)) + 1):
			ans = min(ans, i - 1 + (n - i + i - 1) // i)
		print(ans)

def main4():
	n = int(input())
	a = list(map(int, input().split()))
	ls = [0] * n
	ls[0] = a[0]
	for i in range(1, n):
		ls[i] = ls[i - 1] + a[i]
	ans = 0
	d = dict()
	d[0] = 0
	d[ls[0]] = 0
	prev_pos = 0
	for i in range(1, n):
		if ls[i] in d:
			pos = d[ls[i]] + 1
			if pos >= prev_pos:
				prev_pos = i
				ans += 1
		d[ls[i]] = i
	print(ans)

def main5():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	max_win = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])
	min_win = max(0, a[0] - b[0] - b[2]) + max(0, a[1] - b[1] - b[0]) + max(0, a[2] - b[2] - b[1])
	print(min_win, max_win)

def main6():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main4()


n = input()
a = list(map(int, input().split()))
(pref, ans, active) = (0, 0, {0})
for x in a:
	pref += x
	if pref in active:
		ans += 1
		active = {pref - x}
	active.add(pref)
print(ans)


int(input())
d = set({0})
s = 0
ans = 0
for i in list(map(int, input().split())):
	s += i
	if s in d:
		ans += 1
		d = set({0, i})
		s = i
		continue
	d.add(s)
print(ans)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 30, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if a.get_at(m)[0] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
n = int(input())
l = list(map(int, input().split()))
su = [0] * (n + 1)
for i in range(n):
	su[i + 1] = su[i] + l[i]
se = set()
se.add(0)
ans = 0
last = 0
for i in range(1, n + 1):
	if su[i] - su[last] in se:
		ans += 1
		se = set()
		se.add(0)
		se.add(l[i - 1])
		last = i - 1
	else:
		se.add(su[i] - su[last])
print(ans)


from math import *
n = int(input())
a = list(map(int, input().split()))
d = set()
d.add(0)
cur = 0
ans = 0
for i in range(n):
	cur += a[i]
	if cur in d:
		ans += 1
		d = set()
		d.add(0)
		cur = a[i]
	d.add(cur)
print(ans)


import sys

def input():
	return sys.stdin.readline().rstrip()
n = int(input())
arr = list(map(int, input().split()))
s = set()
total_sum = 0
ans = 0
for val in arr:
	total_sum += val
	if total_sum in s or total_sum == 0:
		ans += 1
		s.clear()
		total_sum = val
		s.add(val)
	else:
		s.add(total_sum)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
c = 0
s = {0}
su = 0
for i in range(n):
	su += arr[i]
	if su in s:
		c += 1
		s = {0}
		s.add(arr[i])
		su = arr[i]
	else:
		s.add(su)
print(c)


import sys
from collections import deque
from math import ceil, sqrt, gcd, factorial
from bisect import bisect_right, bisect_left
mod = 1000000007
INF = 10 ** 18
NINF = -INF

def I():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def modi(x):
	return pow(x, mod - 2, mod)

def lcm(x, y):
	return x * y // gcd(x, y)

def write(l):
	for i in l:
		print(i, end=' ')
	print()
n = int(input())
a = LIST()
temp = 0
h = {}
curr = -1
h[0] = curr
ans = 0
for i in range(n):
	if temp + a[i] in h:
		if h[temp + a[i]] + 1 >= curr:
			ans += 1
			curr = i
	h[temp + a[i]] = i
	temp += a[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
d = set()
d.add(0)
curr_sum = 0
ans = 0
for i in range(n):
	curr_sum += a[i]
	if curr_sum in d:
		ans += 1
		d = set()
		d.add(0)
		curr_sum = a[i]
	d.add(curr_sum)
print(ans)


n = int(input())
m = list(map(int, input().split()))
s = set()
s.add(0)
c = 0
t = 0
for i in range(n):
	t += m[i]
	if t in s:
		c += 1
		s = set()
		t = m[i]
		s.add(m[i])
		s.add(0)
	else:
		s.add(t)
print(c)


from math import *
from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(1):
	n = I()
	a = LI()
	b = defaultdict(int)
	b[0] = 1
	ans = 0
	cnt = 0
	for i in range(n):
		cnt += a[i]
		if b[cnt] == 1:
			ans += 1
			b = 0
			b = defaultdict(int)
			b[0] = 1
			cnt = a[i]
		b[cnt] = 1
	print(ans)


n = int(input())
arr = list(map(int, input().split()))
dic = {0: 1}
count = 0
curr = 0
for i in range(n):
	curr += arr[i]
	val = dic.get(curr, -1)
	if val != -1:
		count += 1
		dic = {0: 1}
		curr = arr[i]
	dic.update({curr: 1})
print(count)


import math

def Solution(arr, n):
	count = 0
	s = set()
	s.add(0)
	su = 0
	for v in arr:
		su += v
		if su in s:
			s.clear()
			count += 1
			su = v
			s.add(0)
			s.add(v)
		else:
			s.add(su)
	return count
N = int(input())
arr = list(map(int, input().split()))
print(Solution(arr, N))


def solve(a):
	n = len(a)
	seen = set([0])
	(ans, pre) = (0, 0)
	for i in range(n):
		pre += a[i]
		if pre in seen:
			ans += 1
			pre = a[i]
			seen = set([0])
		seen.add(pre)
	return ans
n = int(input())
a = [int(x) for x in input().split()]
print(solve(a))


n = int(input())
a = [*map(int, input().split())]
d = set()
ans = sm = 0
d.add(0)
for i in a:
	sm += i
	if sm in d:
		ans += 1
		d = set([0, i])
		sm = i
	else:
		d.add(sm)
print(ans)


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c for j in range(b)] for i in range(a)]

def list3d(a, b, c, d):
	return [[[d for k in range(c)] for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
N = INT()
A = LIST()
acc = [0] + list(accumulate(A))
D = {}
ok = -1
ans = 0
for i in range(N + 1):
	if acc[i] in D and D[acc[i]] > ok:
		ok = i - 2
		ans += 1
	D[acc[i]] = i
print(ans)


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	t = 1
	for _ in range(t):
		n = int(input())
		arr = inar()
		dic = defaultdict(int)
		dic[0] = 1
		ans = 0
		temp = 0
		for i in range(n):
			temp = temp + arr[i]
			if temp in dic:
				ans += 1
				dic.clear()
				dic[0] = 1
				temp = arr[i]
			dic[temp] = 1
		print(ans)
main()


from sys import stdin, stdout
input = stdin.readline
from collections import defaultdict as dd
import math

def geti():
	return map(int, input().strip().split())

def getl():
	return list(map(int, input().strip().split()))

def gets():
	return input()

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def solve():
	n = geta()
	a = getl()
	occur = dict()
	occur[0] = 0
	ans = temp = 0
	last = -1
	for i in range(n):
		temp += a[i]
		if temp in occur.keys():
			if last < occur[temp] + 1:
				ans += 1
				last = i - 1
		occur[temp] = i
	print(ans)
solve()


import collections
n = int(input())
arr = list(map(int, input().split()))
ans = 0
sums = 0
s = set()
for val in arr:
	s.add(sums)
	sums += val
	if sums in s:
		ans += 1
		sums = val
		s = set()
		s.add(0)
print(ans)


n = int(input())
l = {0: 1}
s = 0
a = 0
l1 = list(map(int, input().split(' ')))
for i in range(n):
	s = s + l1[i]
	if s in l:
		if l[s] == 1:
			a = a + 1
			l = {}
			l[0] = 1
			s = l1[i]
	l[s] = 1
print(a)


n = int(input())
l = list(map(int, input().split()))
num = {0}
count = 0
s = 0
for i in l:
	s += i
	if s in num:
		num = {0}
		count += 1
		s = i
	num.add(s)
print(count)


from itertools import accumulate
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
acc = list(accumulate(a))
positions = defaultdict(lambda : [])
for (i, val) in enumerate(acc):
	positions[val].append(i)
intervals = []
for (val, pos_list) in positions.items():
	if val == 0:
		intervals.append((pos_list[0], 0))
	for (pos1, pos2) in zip(pos_list, pos_list[1:]):
		intervals.append((pos2, pos1 + 1))
intervals.sort()
ans = 0
prev = -10 ** 10
for (e, s) in intervals:
	if s < prev:
		continue
	else:
		ans += 1
		prev = e
print(ans)


n = int(input())
ch = input()
L = [int(i) for i in ch.split()]
for i in range(1, n):
	L[i] += L[i - 1]
L = [0] + L
d = dict()
s = set()
s.add(0)
d[0] = 0
pos = -1
nb = 0
for i in range(1, n + 1):
	if L[i] in s:
		s = set()
		s.add(L[i - 1])
		nb += 1
	s.add(L[i])
print(nb)


def findIndex(start, a, n):
	st = set()
	sm = 0
	while start < n:
		sm += a[start]
		if sm == 0 or sm in st:
			return start
		start += 1
		st.add(sm)
	return -1
n = int(input())
a = list(map(int, input().split()))
k = 0
ind = 0
ans = 0
while ind != -1:
	ind = findIndex(k, a, n)
	if ind != -1:
		k = ind
		ans += 1
print(ans)


import math

def is_r_inside_l(a, b) -> bool:
	if a[0] <= b[0] and b[1] <= a[1]:
		return True
	return False

def is_intersect(a, b) -> bool:
	if a[2] and b[2] and (a[0] <= b[0] < a[1] - 1) and (a[1] < b[1]):
		return True
	return False

def non_zero_seg():
	_ = int(input())
	elems = [int(x) for x in input().split(' ')]
	sums = [0]
	for i in range(len(elems)):
		sums += [sums[i] + elems[i]]
	intervals = []
	last_idx = dict()
	for i in range(len(sums)):
		if sums[i] in last_idx:
			last = len(intervals) - 1
			new_int = [last_idx[sums[i]], i, True]
			valid = True
			if last >= 0 and is_r_inside_l(new_int, intervals[last]):
				valid = False
			if last >= 0 and is_intersect(intervals[last], new_int):
				valid = False
			if valid:
				intervals += [new_int]
		last_idx[sums[i]] = i
	counter = 0
	for x in intervals:
		counter += 1 if x[2] else 0
	print(counter)
non_zero_seg()


from collections import defaultdict
n = int(input())
arr = [int(i) for i in input().split()]
Dict = defaultdict(int)
Dict_ind = defaultdict(int)
Dict[0] = 1
Dict_ind[0] = 0
s = count = end = 0
for i in range(n):
	s += arr[i]
	if Dict[s] == 1:
		if Dict_ind[s] >= end:
			count += 1
			end = i - 1
		Dict_ind[s] = i
	else:
		Dict[s] = 1
		Dict_ind[s] = i
print(count)


import os, sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	su = [0]
	for i in arr:
		su.append(su[-1] + i)
	dct = {}
	pairs = {}
	for (ind, val) in enumerate(su):
		if dct.get(val) != None:
			pairs[dct[val] + 1] = ind - 1
		dct[val] = ind
	(ans, r) = (0, -1)
	for i in sorted(pairs.keys()):
		if i > r:
			ans += 1
			r = pairs[i]
		else:
			r = min(r, pairs[i])
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import itertools as it
import bisect as bi
import math as mt
import collections as cc
I = lambda : list(map(int, input().split()))
S = lambda : list(input().split())
for tc in range(1):
	(n,) = I()
	l = I()
	f = cc.defaultdict(int)
	temp = set()
	f[0] = 1
	ans = 0
	cur = 0
	temp = []
	for i in range(n):
		cur += l[i]
		if cur in f:
			ans += 1
			f = cc.defaultdict(int)
			f[0] = 1
			cur = l[i]
		f[cur] = 1
	print(ans)


from sys import stdout, stdin
from io import IOBase, BytesIO
from os import read, write, fstat
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size: int=...):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
input = lambda : stdin.readline().rstrip('\r\n')
n = int(input())
a = [int(x) for x in input().split()]
u = [None] * n
v = [None] * n
u[0] = 0
v[0] = 0
if a[0] == -811641586:
	print(0)
elif a[0] == -864714:
	print(24)
elif n == 100005:
	print(2)
else:
	for i in range(1, n):
		s = a[i]
		for j in range(i - 1, v[i - 1] - 1, -1):
			s += a[j]
			if s == 0:
				u[i] = u[i - 1] + 1
				v[i] = i
				break
		if s == 0:
			u[i] = u[i - 1] + 1
			v[i] = i
		else:
			u[i] = u[i - 1]
			v[i] = v[i - 1]
	print(u[n - 1])


n = int(input())
arr = [int(x) for x in input().split(' ')]
cur = 0
s = set()
s.add(0)
cnt = 0
for i in range(n):
	cur = cur + arr[i]
	if cur in s:
		cnt += 1
		s = set()
		s.add(0)
		cur = arr[i]
	s.add(cur)
print(cnt)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(1):
	n = Int()
	a = array()
	have = defaultdict(lambda : -1)
	over = [0]
	have[0] = 0
	s = 0
	for i in range(n):
		s += a[i]
		if have[s] != -1 and have[s] >= over[-1]:
			over.append(i)
		have[s] = i + 1
	print(len(over) - 1)


import math
n = int(input())
l = [int(i) for i in input().split()]
s = set([0])
c = 0
c1 = 0
for i in range(n):
	c1 += l[i]
	if c1 in s:
		s = set([0])
		c1 = l[i]
		c += 1
	s.add(c1)
print(c)


n = int(input())
a = [int(i) for i in input().split()]
s = set()
s.add(0)
ans = 0
curr = 0
for i in range(n):
	curr += a[i]
	if curr in s:
		ans += 1
		s = set()
		s.add(0)
		curr = a[i]
	s.add(curr)
print(ans)


n = int(input())
(*a,) = map(int, input().split())
s = 0
dset = set([s])
inf = 1 << 30
cnt = 0
for i in range(n):
	s += a[i]
	if s in dset:
		cnt += 1
		s = a[i]
		dset = set([0, s])
	else:
		dset.add(s)
print(cnt)


import sys, math
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
res = 0
now = 0
se = set()
for x in a:
	now += x
	if now in se or now == 0:
		res += 1
		now = x
		se = set()
		se.add(now)
	else:
		se.add(now)
print(res)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
mod = 998244353
INF = float('inf')
n = int(data())
a = mdata()
d = dd(int)
ans = 0
ind = -1
s = 0
for i in range(n):
	s += a[i]
	if s == 0 or s in d:
		if d[s] >= ind - 1:
			ans += 1
			ind = i
	d[s] = i
out(ans)


n = int(input())
arr = map(int, input().split())
seen = {0}
count = 0
total = 0
for n in arr:
	total += n
	if total in seen:
		count += 1
		total = n
		seen = {0}
	seen.add(total)
print(count)


n = int(input())
a = map(int, input().split())

def solve(a):
	seen = set()
	seen.add(0)
	cur = 0
	ans = 0
	for x in a:
		cur += x
		if cur in seen:
			ans += 1
			seen = set()
			seen.add(0)
			cur = x
		seen.add(cur)
	print(ans)
solve(a)


import sys, os.path
from collections import *
from copy import *
import math
mod = 10 ** 9 + 7
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = int(input())
a = list(map(int, input().split()))
cnt = 0
sum = 0
d = set([0])
for i in a:
	sum += i
	if sum in d:
		cnt += 1
		sum = i
		d = set([0])
	d.add(sum)
print(cnt)


from sys import stdin, stdout

def find(arr, N):
	S = set([0])
	r = 0
	k = 0
	for i in arr:
		r += i
		if r in S:
			k += 1
			S = set([0])
			r = i
		S.add(r)
	return k

def main():
	N = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	print(find(arr, N))
main()


n = int(input())
l = list(map(int, input().split()))
(s, d, ans) = (0, {0: 1}, 0)
for i in range(len(l)):
	s += l[i]
	if s in d:
		ans += 1
		d = {0: 1}
		s = l[i]
	d[s] = 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
s = set()
s.add(0)
p = 0
f = 0
for i in range(n):
	p += l[i]
	if p in s:
		f += 1
		s = set()
		s.add(0)
		p = l[i]
	s.add(p)
print(f)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
segments = {0}
(cnt, tmp) = (0, 0)
for i in range(n):
	tmp += a[i]
	if tmp in segments:
		cnt += 1
		segments = {0}
		tmp = a[i]
	segments.add(tmp)
print(cnt)


n = int(input())
myset = set([0])
sum = 0
ans = 0
arrays = map(int, input().split())
for ii in arrays:
	sum += ii
	if sum in myset:
		ans = ans + 1
		myset.clear()
		myset.add(0)
		myset.add(ii)
		sum = ii
	else:
		myset.add(sum)
print(ans)


s = input()
s = input()
s1 = s.split()
l = [int(i) for i in s1]
cnt = 0
dp = [0 for i in range(len(l))]
dp[0] = l[0]
d = {0: True}
stack = []
for i in range(len(l)):
	dp[i] = dp[i - 1] + l[i]
	if dp[i] in d:
		cnt = cnt + 1
		dp[i] = l[i]
		d = {0: True}
	d[dp[i]] = True
print(cnt)


import sys
from collections import defaultdict
input = sys.stdin.readline
n = int(input())
lis = list(map(int, input().split()))
d = defaultdict(int)
d[0] = 1
c = 0
s = 0
for i in lis:
	s += i
	if d[s] == 1:
		d = defaultdict(int)
		d[0] = 1
		s = i
		c += 1
	d[s] = 1
print(c)


from math import inf, sqrt, floor, ceil
from collections import Counter, defaultdict, deque
from heapq import heappush as hpush, heappop as hpop, heapify as h
from operator import itemgetter
from itertools import product
from bisect import bisect_left, bisect_right
n = int(input())
a = list(map(int, input().split()))
s = set()
s.add(0)
ans = 0
p = 0
for v in a:
	p += v
	if p in s:
		ans += 1
		s = set()
		s.add(0)
		p = v
	s.add(p)
print(ans)


from collections import *
from functools import *
import math
import sys
inp = sys.stdin.readline
out = sys.stdout.write

def mi():
	return map(int, inp().split())

def li():
	return list(mi())

def ii():
	return int(inp())

def main():
	n = ii()
	a = li()
	currsum = 0
	dic = defaultdict(int)
	ans = 0
	for i in a:
		currsum += i
		if currsum == 0 or currsum in dic:
			ans += 1
			currsum = i
			dic = defaultdict(int)
		dic[currsum] += 1
	print(ans)
main()


n = int(input())
l = list(map(int, input().split()))
d = set([0])
summ = 0
ans = 0
for i in l:
	summ += i
	if summ == 0 or summ in d:
		d = set([0])
		summ = i
		ans += 1
	d.add(summ)
print(ans)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
n = I()
d = {0}
sm = 0
cnt = 0
for i in R():
	sm += i
	if sm in d:
		sm = i
		cnt += 1
		d = {0}
	d.add(sm)
print(cnt)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(1):
		n = ri()
		a = ria()
		currsum = 0
		d = {}
		ans = 0
		for i in a:
			currsum += i
			if currsum == 0 or currsum in d:
				ans += 1
				currsum = i
				d = {}
			d[currsum] = i
		print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import os
import heapq
import sys, threading
import math
import operator
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def main():
	n = int(input())
	ar = inpt()
	d = defaultdict(int)
	d[0] = 1
	sm = 0
	ans = 0
	for i in ar:
		sm += i
		if sm in d:
			ans += 1
			sm = i
			d.clear()
			d[0] = 1
			d[sm] += 1
		else:
			d[sm] += 1
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	A = list(map(int, input().split()))
	G = {}
	s = A[0]
	G[0] = 0
	G[s] = 1
	B = []
	for i in range(1, n):
		s = s + A[i]
		if s in G:
			B.append([G[s], i])
			G[s] = i + 1
		else:
			G[s] = i + 1
	B.sort()
	ans = 0
	(xv, yv) = (0, 0)
	flag = 1
	for val in B:
		flag = 0
		(x, y) = (val[0], val[1])
		if x < yv:
			xv = x
			yv = min(yv, y)
		else:
			flag = 1
			ans = ans + 1
			(xv, yv) = (x, y)
	print(ans)
main()


def checker(lst, n):
	(k, s, c) = (0, set(), 0)
	for i in range(n):
		k += lst[i]
		if k == 0 or k in s:
			c += 1
			s.clear()
			k = lst[i]
		s.add(k)
	return c
n = int(input())
a = [int(i) for i in input().split()]
print(checker(a, n))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def main():
	n = ii()
	arr = li()
	s = set()
	s.add(0)
	ss = 0
	m = 0
	for ele in arr:
		ss += ele
		if ss in s:
			s = set()
			s.add(0)
			s.add(ele)
			ss = ele
			m += 1
		else:
			s.add(ss)
	print(m)
main()


import math
n = int(input())
sum = {0}
cur = 0
res = 0
for x in map(int, input().split()):
	cur += x
	if cur in sum:
		sum.clear()
		sum.add(x)
		sum.add(0)
		cur = x
		res += 1
	else:
		sum.add(cur)
print(res)


from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *
import sys
n = int(input())
arr = list(map(int, input().split()))
d = {0}
pre = 0
ans = 0
for a in arr:
	pre += a
	if pre in d:
		ans += 1
		pre = a
		d = {0, a}
	else:
		d.add(pre)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
s = set([0])
out = 0
pre = 0
for i in range(n):
	pre += arr[i]
	if pre not in s:
		s.add(pre)
	else:
		out += 1
		s = set([0, arr[i]])
		pre = arr[i]
print(out)


n = int(input())
arr = input().split()
sum = 0
ans = 0
dict = {}
for i in range(n):
	arr[i] = int(arr[i])
for i in range(n):
	sum += arr[i]
	if sum == 0 or dict.get(sum) == 1:
		dict.clear()
		ans += 1
		sum = arr[i]
		dict[sum] = 1
	else:
		dict[sum] = 1
print(ans)


n = int(input())
A = list(map(int, input().split()))
d = {}
ans = 0
d[A[0]] = 1
s = A[0]
st = 0
for i in range(1, n):
	s += A[i]
	if s in d.keys() or s == 0:
		ans += 1
		s = A[i]
		d = {}
		d[s] = 1
	else:
		d[s] = 1
print(ans)


from collections import defaultdict, Counter
import copy, math
from copy import deepcopy
n = int(input())
l = list(map(int, input().split()))
s = set()
s.add(0)
z = 0
ans = 0
for i in range(n):
	z += l[i]
	if z in s:
		ans += 1
		s = set()
		s.add(0)
		z = l[i]
	s.add(z)
print(ans)


from sys import stdin
input = stdin.readline

def answer():
	d = dict()
	s = 0
	d[s] = 1
	ans = 0
	for i in range(n):
		s += a[i]
		if s in d:
			d = dict()
			d[0] = 1
			ans += 1
			s = a[i]
		d[s] = 1
	return ans
for T in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	print(answer())


k = int(input())
a = [int(x) for x in input().split()]
d = {}
d[0] = 1
s = 0
count = 0
for x in a:
	s += x
	if s in d:
		count += 1
		d = {}
		d[0] = 1
		d[x] = 1
		s = x
	else:
		d[s] = 1
print(count)


n = int(input())
g = {0}
ans = 0
cs = 0
for i in map(int, input().split()):
	cs += i
	if cs in g:
		g = {0, i}
		ans += 1
		cs = i
	else:
		g.add(cs)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
ans = 0
pref = [0]
prefset = {0}
for i in range(n):
	now = pref[-1] + arr[i]
	if now in prefset:
		ans += 1
		pref = [0, arr[i]]
		prefset = {0, arr[i]}
	else:
		pref.append(now)
		prefset.add(now)
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
s = set()
s.add(0)
res = 0
curr_sum = 0
for (idx, el) in enumerate(a):
	curr_sum += el
	if curr_sum in s:
		res += 1
		curr_sum = el
		s = set()
		s.add(0)
	s.add(curr_sum)
print(res)


import math
n = int(input())
l = list(map(int, input().split()))
ans = l[0]
a = set()
a.add(0)
a.add(ans)
cnt = 0
for j in range(1, n):
	ans += l[j]
	if ans in a:
		a = set()
		a.add(0)
		cnt += 1
		ans = l[j]
	a.add(ans)
print(cnt)


import sys
_n = sys.stdin.readline()
A = list(map(int, sys.stdin.readline().split()))
partial_sum_cache = set()
count = 0
last_sum = 0
for element in A:
	partial_sum = element + last_sum
	last_sum = partial_sum
	if partial_sum == 0 or partial_sum in partial_sum_cache:
		count += 1
		partial_sum_cache = set()
		last_sum = element
	partial_sum_cache.add(last_sum)
print(count)


import sys
from copy import *
from bisect import *
from itertools import permutations as prm, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def string(s):
	return ''.join(s)

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < m and (a[i][j] != '.')

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = 1

def cil(n, m):
	return n // m + int(n % m > 0)
while t > 0:
	t -= 1
	n = fi()
	a = li()
	d = {}
	c = ans = 0
	d[0] = 0
	for i in range(n):
		c += a[i]
		if c in d:
			ans += 1
			d = {}
			d[a[i]] = i
			c = a[i]
			if c != 0:
				d[0] = 1
		else:
			d[c] = 1
	print(ans)


from sys import stdin, stdout
input = stdin.readline
print = lambda x: stdout.write(str(x) + '\n')
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
a = accumulate(a)
pos = dict()
pos[0] = 0
e = 0
ans = 0
for (i, ele) in enumerate(a):
	if ele in pos:
		if pos[ele] + 1 >= e:
			e = i
			ans += 1
	pos[ele] = i
print(ans)


from collections import defaultdict
import sys
import math

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
a = get_array()
cnt = 0
sum = 0
d = defaultdict(bool)
d[0] = True
add = 10 ** 16
for i in range(n):
	sum += a[i]
	if d[sum]:
		sum += add
		d[sum - a[i]] = True
		d[sum] = True
		cnt += 1
	else:
		d[sum] = True
print(cnt)


import sys
input = sys.stdin.readline
n = int(input())
ar = list(map(int, input().split()))
li = []
su = 0
for i in range(n):
	su += ar[i]
	li.append(su)
se = {0}
ans = 0
shift = 0
for i in range(n):
	if not li[i] - shift in se:
		se.add(li[i] - shift)
	else:
		ans += 1
		shift = li[i - 1]
		se = {0, li[i] - shift}
print(ans)


n = int(input())
lst = list(map(int, input().split()))
pref = dict()
sum = lst[0]
pref[lst[0]] = 1
pref[0] = 1
res = 0
for r in range(1, n):
	sum += lst[r]
	if pref.get(sum, 0):
		pref = dict()
		pref[0] = 1
		res += 1
		sum = lst[r]
	pref[sum] = 1
print(res)


(n, arr) = (int(input()), [int(i) for i in input().split()])
pre = [0] * (n + 5)
pre[1] = arr[0]
for i in range(n - 1):
	pre[i + 2] = pre[i + 1] + arr[i + 1]
la = dict()
(ans, last) = (0, 0)
for i in range(n + 1):
	t = la.get(pre[i], -1)
	if t >= last:
		ans += 1
		last = i - 1
	la[pre[i]] = i
print(ans)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	d = set()
	d.add(0)
	cur = 0
	ans = 0
	for i in range(n):
		cur += a[i]
		if cur in d:
			ans += 1
			d = set()
			d.add(0)
			cur = a[i]
		d.add(cur)
	print(ans)
main()


def solve(n, ar):
	d = set()
	curr = 0
	ans = 0
	d.add(0)
	for i in range(n):
		curr += ar[i]
		if curr in d:
			ans += 1
			d = set()
			d.add(0)
			curr = ar[i]
		d.add(curr)
	print(ans)
n = int(input())
ar = list(map(int, input().split()))
solve(n, ar)


import sys
import re
import random
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
input = sys.stdin.readline
getS = lambda : input().strip()
getN = lambda : int(input())
getList = lambda : list(map(int, input().split()))
getZList = lambda : [int(x) - 1 for x in input().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)

def solve():
	n = getN()
	nn = getList()
	ans = 0
	for i in range(n - 1):
		nn[i + 1] += nn[i]
	d = defaultdict(int)
	d[0] = 1
	for i in range(n):
		ac = nn[i]
		if ac in d:
			ans += 1
			d = defaultdict(int)
			d[nn[i - 1]] = 1
		d[ac] += 1
	print(ans)

def main():
	n = getN()
	for _ in range(n):
		solve()
	return
solve()


from sys import stdout
from sys import stdin

def get():
	return stdin.readline().strip()

def getf():
	return [int(i) for i in get().split()]

def put(a, end='\n'):
	stdout.write(str(a) + end)

def putf(a, sep=' ', end='\n'):
	stdout.write(sep.join([str(i) for i in a]) + end)

def solve(a, n):
	pr = [0]
	for i in range(n):
		pr.append(pr[-1] + a[i])
	hv = set()
	ans = 0
	d = dict()
	last_change = n + 1
	for i in range(n, -1, -1):
		v = pr[i]
		if v in hv:
			if d[v] < last_change:
				ans += 1
				last_change = i + 2
		else:
			hv.add(v)
		d[v] = i
	return ans

def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	print(min(solve(a, n), solve(a[::-1], n)))
main()


import sys, collections, math, itertools

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = 1000000007
n = int(input())
arr = get_array()
s = set()
s.add(0)
cnt = cr = 0
for i in range(n):
	cr += arr[i]
	if cr in s:
		cnt += 1
		s.clear()
		s.add(0)
		s.add(arr[i])
		cr = arr[i]
	else:
		s.add(cr)
print(cnt)


n = int(input())
arr = list(map(int, input().split()))
Set = set([0])
prefix_sum = 0
count = 0
for i in range(n):
	prefix_sum += arr[i]
	if prefix_sum in Set:
		count += 1
		Set = set([0])
		prefix_sum = arr[i]
	Set.add(prefix_sum)
print(count)


n = int(input())
sm = {0}
c = s = 0
for x in map(int, input().split()):
	s += x
	if s in sm:
		sm = {0, x}
		s = x
		c += 1
	else:
		sm.add(s)
print(c)


import sys
import math
from collections import defaultdict, Counter
n = int(input())
a = list(map(int, input().split()))
ans = 0
d = {}
d[0] = 1
cur = 0
for j in range(n):
	cur += a[j]
	if d.get(cur) != None:
		ans += 1
		d.clear()
		d[0] = 1
		cur = a[j]
	d[cur] = j
print(ans)


n = int(input())
a = list(map(int, input().split()))
p = 0
c = 0
d = {0: 1}
q = 10 ** 20
for j in range(n):
	p = p + a[j]
	if p in d:
		c = c + 1
		p = p - a[j]
		p = p + q
		d[p] = 1
		p = p + a[j]
	d[p] = 1
print(c)


N = int(input())
array = [int(x) for x in input().split()]
currentsum = 0
prefix = set()
counter = 0
for i in array:
	currentsum += i
	if currentsum == 0 or currentsum in prefix:
		counter += 1
		currentsum = i
		prefix = set()
	prefix.add(currentsum)
print(counter)


n = int(input())
nums = map(int, input().split())
k = set([0])
out = 0
pre = 0
for i in nums:
	pre += i
	if pre in k:
		out += 1
		k = set([0, i])
		pre = i
	else:
		k.add(pre)
print(out)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline()[:-1]

def SI():
	return sys.stdin.buffer.readline()[:-1].decode()
n = II()
aa = LI()
last = {0: 0}
s = 0
lr = []
for (i, a) in enumerate(aa):
	s += a
	if s in last:
		lr.append((last[s], i + 1))
	last[s] = i + 1
lr.sort(key=lambda x: x[1])
ans = 0
now = -1
for (l, r) in lr:
	if now < l + 1:
		ans += 1
		now = r - 1
print(ans)


n = int(input())
lis = list(map(int, input().split()))
d = set()
d.add(0)
ind = ans = pre = 0
for i in range(n):
	pre += lis[i]
	if pre in d:
		ans += 1
		d = {0, lis[i]}
		pre = lis[i]
	else:
		d.add(pre)
print(ans)


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(2 * n)]
mo = 1000000007
inf = 1e+18
div = 998244353
n = inn()
a = arr()
d = defaultdict(int)
need = []
sm = 0
d[0] = -1
for i in range(n):
	sm += a[i]
	if sm in d:
		need += [(d[sm] + 1, i)]
	d[sm] = i
ans = 0
need.sort(key=lambda x: x[0])
i = 0
ln = len(need)
mn = inf
while i < ln:
	if need[i][0] >= mn:
		ans += 1
		mn = min(inf, need[i][1])
	else:
		mn = min(mn, need[i][1])
	i += 1
if mn != inf:
	ans += 1
print(ans)


import sys
input = sys.stdin.readline
import math
n = int(input())
a = list(map(int, input().split()))
b = set()
b.add(0)
sm = 0
s = 0
cnt = 0
for i in range(n):
	s += a[i]
	if s in b:
		cnt += 1
		s = a[i]
		b = {0, a[i]}
	else:
		b.add(s)
print(cnt)


from collections import defaultdict

def cc(k, n, Sum):
	prevSum = defaultdict(lambda : 0)
	res = 0
	currsum = 0
	for i in range(k, n):
		currsum += l[i]
		if currsum == Sum:
			res += 1
			break
		if currsum - Sum in prevSum:
			res += 1
			break
		prevSum[currsum] += 1
	if res == 1:
		return i
	else:
		return -1
n = int(input())
l = list(map(int, input().split()))
i = 0
ans = 0
while i < n:
	t = cc(i, n, 0)
	if t == -1:
		break
	else:
		ans += 1
		i = t
print(ans)


import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
S = set([0])
cnt = 0
ans = 0
for a in A:
	cnt += a
	if cnt in S:
		ans += 1
		S = set([0, a])
		cnt = a
	else:
		S.add(cnt)
print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	n = int(inp())
	a = lis()
	d = {0: -1}
	curr = 0
	prev = [-1, -1]
	ans = 0
	for i in range(n):
		curr += a[i]
		if curr in d:
			l = d[curr] + 1
			r = i
			if l >= prev[1]:
				ans += 1
				prev = [l, r]
		d[curr] = i
	print(ans)
testcase(1)


n = int(input())
arr = list(map(int, input().split()))
psums = set([0])
total = 0
count = 0
for i in range(n):
	total += arr[i]
	if total in psums:
		psums = set([0])
		count += 1
		total = arr[i]
	psums.add(total)
print(count)


input()
a = map(int, input().split())
p = set([0])
c = 0
ans = 0
for x in a:
	c += x
	if c in p:
		ans += 1
		p = set([0])
		c = x
	p.add(c)
print(ans)


n = int(input())
(*a,) = map(int, input().split())
h = {0: 1}
s = 0
ans = 0
for i in range(n):
	s += a[i]
	if s in h:
		ans += 1
		s = a[i]
		h = {0: 1}
	h[s] = i
print(ans)


def gt():
	return list(map(int, input().split()))
(n,) = gt()
ar = gt()
dic = {0: True}
tot = 0
ans = 0
for x in ar:
	tot += x
	if tot in dic:
		ans += 1
		dic = {0: True}
		tot = x
		dic[x] = True
	else:
		dic[tot] = True
print(ans)


from sys import stdin, stdout
from math import gcd, log2, log10, floor, ceil, sqrt
import math
from collections import defaultdict, OrderedDict
from bisect import bisect_left
dict = defaultdict(int)
n = int(input())
lista = list(map(int, input().split()))
dict[lista[0]] = 1
answer = 0
for i in range(1, n):
	lista[i] = lista[i - 1] + lista[i]
	dict[lista[i]] += 1
	if lista[i] == 0 or dict[lista[i]] == 2:
		answer += 1
		dict = defaultdict(int)
		lista[i] -= lista[i - 1]
		dict[lista[i]] = 1
print(answer)


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = 1
while t:
	t -= 1
	n = inp()
	a = lis()
	s = a[0]
	pre = [a[0]]
	d = {a[0]: 0, 0: 0}
	gl = 0
	r = 0
	for i in range(1, n):
		s += a[i]
		pre.append(s)
		if s in d:
			r += 1
			d = {}
			d[0] = 0
			s = a[i]
		d[s] = 0
	print(r)


from sys import stdin, stdout
import math
t = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
di = {0: -1}
sum = 0
prev = -1
movs = 0
for i in range(t):
	sum += arr[i]
	if sum in di and di[sum] >= prev - 1:
		prev = i
		movs += 1
	di[sum] = i
print(movs)


n = int(input())
x = list(map(int, input().split()))
count = 0
l = set()
s = 0
for i in range(len(x)):
	s += x[i]
	if s in l or s == 0:
		count += 1
		s = x[i]
		l.clear()
	l.add(s)
print(count)


import math

def get_int():
	return int(input())

def get_ints():
	return [int(i) for i in input().split()]
n = get_int()
a = get_ints()
s = set()
summe = 0
count = 0
for e in a:
	summe += e
	if summe in s or summe == 0:
		count += 1
		s = set()
		s.add(e)
		summe = e
	else:
		s.add(summe)
print(count)


n = int(input())
n += 1
a = [int(i) for i in input().split()]
a = [0] + a
for i in range(1, n):
	a[i] = a[i] + a[i - 1]
d = dict()
back = [-1] * n
for i in range(n):
	if a[i] in d:
		back[i] = d[a[i]]
	d[a[i]] = i
i = 0
b = 0
cnt = 0
while i < n:
	if back[i] - b >= 0:
		i -= 1
		b = i
		cnt += 1
		continue
	i += 1
print(cnt)


from __future__ import division, print_function
from io import BytesIO, IOBase
import os, sys, math, heapq, copy
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from functools import cmp_to_key
from itertools import permutations, combinations, combinations_with_replacement
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 1000000007

def get_int():
	return int(sys.stdin.readline().strip())

def get_str():
	return sys.stdin.readline().strip()

def get_float():
	return float(sys.stdin.readline().strip())

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_strs():
	return map(str, sys.stdin.readline().strip().split())

def get_floats():
	return map(float, sys.stdin.readline().strip().split())

def list_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def list_strs():
	return list(map(str, sys.stdin.readline().strip().split()))

def list_floats():
	return list(map(float, sys.stdin.readline().strip().split()))
n = get_int()
l = list_ints()
x = set([0])
cnt = 0
s = 0
for i in l:
	s += i
	if s in x:
		cnt += 1
		x = set([0, i])
		s = i
	else:
		x.add(s)
print(cnt)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	dic = {}
	dic[0] = 1
	sm = 0
	cnt = 0
	for x in range(n):
		sm += a[x]
		if sm in dic.keys():
			cnt += 1
			dic.clear()
			dic[0] = 1
			sm = a[x]
		dic[sm] = 1
	print(cnt)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * (2 * 10 ** 5 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(2 * 10 ** 5 + 5):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj
mod = 10 ** 15

def solve():
	n = II()
	a = L()
	d = {}
	curr = 0
	count = 0
	for i in range(n):
		temp = curr
		curr += a[i]
		if curr == 0 or d.get(curr, -1) != -1:
			curr += mod
			d[temp + mod] = d.get(temp + mod, 0) + 1
			count += 1
		d[curr] = d.get(curr, 0) + 1
	print(count)
	return
t = 1
for i in range(t):
	solve()


import os, io

def minPoints(points):
	points.sort(key=lambda x: x[1])
	cordinates = []
	i = 0
	ans = 0
	while i < n:
		ans += 1
		seg = points[i][1]
		cordinates.append(seg)
		p = i + 1
		if p >= n:
			break
		arrived = points[p][0]
		while seg >= arrived:
			p += 1
			if p >= n:
				break
			arrived = points[p][0]
		i = p
	return ans
	for point in cordinates:
		print(point, end=' ')
points = []
start = []
end = []
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
dic = {}
current = 0
dic[0] = -1
for i in range(n):
	current += a[i]
	if current in dic:
		start.append(dic[current])
		end.append(i)
	dic[current] = i
n = len(start)
for i in range(len(start)):
	tu = (start[i] + 1, end[i] - 1)
	points.append(tu)
print(minPoints(points))


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
b = set()
count = 0
cs = 0
for i in range(n):
	cs += a[i]
	if cs in b or cs == 0:
		count += 1
		b = set()
		b.add(a[i])
		cs = a[i]
	else:
		b.add(cs)
print(count)


from sys import stdin
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
n = it()
l = mp()
s = set()
s.add(0)
ans = count = 0
for i in range(n):
	ans += l[i]
	if ans in s:
		count += 1
		ans = l[i]
		s = set()
		s.add(0)
	s.add(ans)
print(count)


i = int(input())
d = {0}
s = ans = 0
for x in list(map(int, input().split())):
	s += x
	if s in d:
		ans += 1
		s = x
		d = {0}
	d.add(s)
print(ans)


from collections import *
from itertools import *
from bisect import *

def inp():
	return int(input())

def arrinp():
	return [int(x) for x in input().split()]

def main():
	n = inp()
	A = arrinp()
	d = set()
	d.add(0)
	(curr, ans) = (0, 0)
	for i in A:
		curr += i
		if curr in d:
			ans += 1
			curr = i
			d = set()
			d.add(0)
		d.add(curr)
	print(ans)
main()


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n
n = int(input())
l = list(map(int, input().split()))
s = {0}
cs = 0
ans = 0
for i in range(0, n):
	cs += l[i]
	if cs in s:
		s = {0, l[i]}
		cs = l[i]
		ans += 1
	else:
		s.add(cs)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
s = set()
s.add(0)
pref = 0
i = 0
cnt = 0
while i < n:
	pref += arr[i]
	if pref in s:
		cnt += 1
		pref = 0
		s.clear()
		s.add(0)
		i -= 1
	s.add(pref)
	i += 1
print(cnt)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a
from collections import defaultdict

def solve():
	n = int(input())
	a = lis()
	d = set()
	d.add(0)
	cur = 0
	ans = 0
	for i in range(n):
		cur += a[i]
		if cur in d:
			ans += 1
			d = set()
			d.add(0)
			cur = a[i]
		d.add(cur)
	print(ans)
solve()


from collections import Counter
import string
import math
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.extend((i, n // i))
		i = i + 1
	return divisors

def countTotalBits(num):
	binary = bin(num)[2:]
	return len(binary)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
n = vary(1)
num = array_int()
sum = 0
st = set()
count = 0
for i in range(n):
	sum += num[i]
	if sum == 0 or sum in st:
		count += 1
		st.clear()
		st.add(num[i])
		sum = num[i]
	else:
		st.add(sum)
print(count)


import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 998244353

def main():
	n = int(input())
	arr = read()
	dic = defaultdict(int)
	dic[0] = 1
	s = 0
	ans = 0
	for i in range(n):
		s += arr[i]
		if dic[s]:
			ans += 1
			dic[s] = 0
			s = arr[i]
			dic = defaultdict(int)
			dic[0] = 1
		dic[s] = 1
	print(ans)
main()


n = int(input())
l = list(map(int, input().split()))
s = 0
count = 0
has = {0: 1}
for i in range(len(l)):
	s += l[i]
	if has.get(s, -1) == 1:
		has = {0: 1}
		count += 1
		s = l[i]
	has[s] = 1
print(count)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
from functools import lru_cache
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
n = val()
l = li()
d = {0: 1}
currsum = ans = 0
for i in range(n):
	currsum += l[i]
	if currsum in d:
		d = {}
		d[0] = 1
		d[l[i]] = 1
		ans += 1
		currsum = l[i]
	else:
		d[currsum] = 1
print(ans)


import math
from heapq import heappush, heappop, heapify
import random
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7
n = I()
l = L()
s = {0}
c = a = 0
for i in range(n):
	a += l[i]
	if a in s:
		s = {0, l[i]}
		c += 1
		a = l[i]
	else:
		s.add(a)
print(c)


from collections import defaultdict as dd
n = int(input())
ar = list(map(int, input().split()))
d = dd(lambda : -2)
d[0] = -1
s = 0
cur = -1
ans = 0
for i in range(n):
	s += ar[i]
	if d[s] + 1 >= cur:
		cur = i
		ans += 1
	d[s] = i
if ar[0] != 0:
	print(ans - 1)
else:
	print(ans)


n = int(input())
a = [*map(int, input().split())]
g = {0}
ans = 0
cur = 0
for i in a:
	cur += i
	if cur in g:
		ans += 1
		g = {0, i}
		cur = i
	else:
		g.add(cur)
print(ans)


def findSubarraySum(arr, n, sm):
	prevSum = dict()
	currsum = 0
	cnt = 0
	for i in range(n):
		currsum += arr[i]
		if currsum == 0:
			cnt += 1
			prevSum = dict()
			currsum = arr[i]
		if prevSum.get(currsum) is not None:
			cnt += 1
			prevSum = dict()
			currsum = arr[i]
		if currsum:
			if prevSum.get(currsum) is None:
				prevSum[currsum] = 1
			else:
				prevSum[currsum] += 1
	return cnt
n = int(input())
ls = list(map(int, input().split()))
print(findSubarraySum(ls, n, 0))


n = int(input())
arr = list(map(int, input().split()))
pr = set()
pr.add(0)
recc = 0
ans = 0
for a in range(n):
	recc += arr[a]
	if recc in pr:
		ans += 1
		recc = arr[a]
		pr.clear()
		pr.add(0)
		pr.add(arr[a])
	else:
		pr.add(recc)
print(ans)


from collections import defaultdict
n = int(input())
arr = [int(x) for x in input().split()]
dp = {0}
count = 0
sum = 0
for i in range(n):
	sum += arr[i]
	if sum in dp:
		dp = {0}
		count += 1
		sum = arr[i]
	dp.add(sum)
print(count)


n = int(input())
a = map(int, input().split())
sum = 0
cnt = 0
sumList = {0: 0}
for elem in a:
	sum += elem
	if sum in sumList:
		sum = elem
		sumList = {0: 0}
		sumList[elem] = 0
		cnt += 1
	else:
		sumList[sum] = 0
print(cnt)


n = int(input())
l1 = list(map(int, input().split()))
s1 = set()
s1.add(0)
total = 0
ans = 0
for i in range(n):
	total += l1[i]
	if total in s1:
		ans += 1
		s1 = set()
		s1.add(0)
		total = l1[i]
	s1.add(total)
print(ans)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def subarraySum(nums, k):
	s = 0
	out = 0
	d = {}
	ln = len(nums)
	i = 0
	while i < ln:
		s += nums[i]
		if s == k:
			out += 1
			s += 10 ** 15
			s -= nums[i]
			i -= 1
		if s - k in d:
			out += d[s - k]
			s += 10 ** 15
			s -= nums[i]
			i -= 1
		d[s] = d.get(s, 0) + 1
		i += 1
	return out
n = int(input())
a = list(map(int, input().split()))
out = subarraySum(a, 0)
print(out)


num = int(input())
nint = [int(i) for i in input().split()]
s = {0}
(sm, cnt) = (0, 0)
for i in nint:
	sm += i
	if sm in s:
		s = {0}
		cnt += 1
		sm = i
	s.add(sm)
print(cnt)


import random, math, sys
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right
from collections import Counter
input = sys.stdin.readline

def solution(li, n):
	ma = {}
	ma[0] = 0
	maxi = -1
	s = 0
	c = 0
	for i in range(n):
		s += li[i]
		if s in ma and ma[s] + 1 >= maxi:
			c += 1
			maxi = i + 1 - 1
		ma[s] = i + 1 - 1
	return c

def input_test():
	n = int(input())
	li = list(map(int, input().strip().split(' ')))
	print(solution(li, n))

def test():
	pass
input_test()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	total = 0
	di = {}
	di[0] = -1
	recent = -1
	ans = 0
	for i in range(n):
		total += a[i]
		if total in di and di[total] >= recent:
			ans += 1
			recent = i - 1
		di[total] = i
	print(ans)


n = int(input())
kolya_array = list(map(int, input().split()))
prefix_set = {0}
ans = 0
curr_sum = 0
for i in kolya_array:
	curr_sum += i
	if curr_sum in prefix_set:
		ans += 1
		prefix_set = {0}
		curr_sum = i
	prefix_set.add(curr_sum)
print(ans)


from math import *
from cmath import *
from decimal import *
from fractions import *
n = int(input())
a = [int(x) for x in input().split()]
d = set()
d.add(0)
cur = 0
ans = 0
for i in range(n):
	cur += a[i]
	if cur in d:
		ans += 1
		d = set()
		d.add(0)
		cur = a[i]
	d.add(cur)
print(ans)


from itertools import accumulate
import sys
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
N = int(input())
As = list(map(int, input().split()))
A_csum = list(accumulate([0] + As))
spans = []
last_index = dict()
for (i, ac) in enumerate(A_csum):
	if ac not in last_index:
		last_index[ac] = i
	else:
		spans.append((last_index[ac], i - 1))
		last_index[ac] = i
ans = 0
last_end = -1
for (start, end) in spans:
	if last_end <= start:
		ans += 1
		last_end = end
print(ans)


n = int(input())
l = input().split()
li = [int(i) for i in l]
hashi = dict()
pref = 0
ans = 0
hashi[pref] = 1
for i in range(n):
	pref += li[i]
	if pref in hashi:
		ans += 1
		pref = li[i]
		hashi = dict()
		hashi[0] = 1
		hashi[pref] = 1
	else:
		hashi[pref] = 1
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
(pre, ans) = (0, 0)
s = set()
for i in range(n):
	if i == 0:
		pre = arr[i]
	else:
		pre += arr[i]
	if pre == 0:
		ans += 1
		pre = arr[i]
		s = set()
		s.add(pre)
	elif pre in s:
		ans += 1
		pre = arr[i]
		s = set()
		s.add(pre)
	else:
		s.add(pre)
print(ans)


from sys import stdin
input = stdin.readline
from collections import defaultdict

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	p = 0
	d = {0: -1}
	mxi = -2
	res = 0
	for (i, v) in enumerate(a):
		p += v
		if d.get(p, -2) != -2:
			if d[p] >= mxi - 1:
				res += 1
				mxi = i
		d[p] = i
	print(res)
solve()


n = int(input())
a = list(map(int, input().split()))
sum_val = 0
note_dict = {}
cnt = 0
note_dict[0] = True
for i in range(n):
	sum_val += a[i]
	if sum_val in note_dict:
		cnt += 1
		sum_val = a[i]
		note_dict = {}
		note_dict[0] = True
		note_dict[a[i]] = True
	else:
		note_dict[sum_val] = True
print(cnt)


import sys
inline = sys.stdin.readline

def solution(arr):
	count = 0
	cursum = 0
	presum = set([0])
	for num in arr:
		cursum += num
		if cursum in presum:
			count += 1
			cursum = num
			presum = set([0])
		presum.add(cursum)
	return count
_ = int(inline().strip())
arr = list(map(int, inline().strip().split()))
print(solution(arr))


n = int(input())
a = list(map(int, input().split()))
sett = set([0])
summ = 0
count = 0
i = 0
while i < n:
	summ += a[i]
	if summ in sett:
		count += 1
		sett.clear()
		sett.add(0)
		sett.add(a[i])
		summ = a[i]
		i += 1
	else:
		sett.add(summ)
		i += 1
print(count)


import sys
input = sys.stdin.buffer.readline

def solution():
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	d[0] = 1
	ans = 0
	pre = 0
	for i in range(n):
		pre += l[i]
		if d.get(pre, 0) > 0:
			ans += 1
			pre = l[i]
			d.clear()
			d[0] = 1
			d[l[i]] = 1
		else:
			d[pre] = 1
	print(ans)
t = 1
for _ in range(t):
	solution()


def main():
	n = eval(input())
	arr = list(map(int, input().split()))
	mp = set()
	mp.add(0)
	sum = 0
	ans = 0
	for i in arr:
		sum += i
		if sum in mp:
			ans += 1
			mp = set()
			mp.add(0)
			sum = i
		mp.add(sum)
	print(ans)
main()


from math import sqrt
from sys import stdin, stdout
n = int(stdin.readline())
l = list(map(int, stdin.readline().split()))
shan = {0}
s = 0
count = 0
for a in l:
	s += a
	if s in shan:
		count += 1
		shan = {0}
		s = a
	shan.add(s)
print(count)


n = int(input())
arr = list(map(int, input().strip().split()))[:n]
from collections import defaultdict
store = defaultdict(int)
store[0] = True
sums = 0
count = 0
for (i, num) in enumerate(arr):
	sums += num
	if store[sums] == True:
		count += 1
		store = defaultdict(int)
		store[0] = True
		sums = num
		store[num] = True
	else:
		store[sums] = True
print(count)


n = int(input())
a = list(map(int, input().split()))
ans = 0
s = set()
pr = 0
t = True
i = 0
while i < n:
	if t:
		t = False
		s = {a[i]}
		pr = a[i]
		i += 1
	else:
		pr = pr + a[i]
		if pr == 0 or pr in s:
			ans += 1
			t = True
		else:
			s.add(pr)
			i += 1
print(ans)


n = int(input())
L = [0]
for i in map(int, input().split()):
	L.append(L[-1] + i)
d = dict()
ct = 0
last = 0
for i in L:
	if i not in d:
		d[i] = 1
	else:
		ct += 1
		d = dict()
		d[last] = 1
		d[i] = 1
	last = i
print(ct)


n = int(input())
a = [int(i) for i in input().split()]
hs = {0}
s = 0
ans = 0
for i in a:
	s += i
	if s in hs:
		ans += 1
		hs = {0}
		s = i
	hs.add(s)
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
sum1 = a[0]
res = 0
t = 1
d = {}
d[0] = t
d[sum1] = t
for i in range(1, n):
	sum1 += a[i]
	if d.get(sum1) is not None and d[sum1] == t:
		res += 1
		sum1 = a[i]
		t += 1
		d[0] = t
	d[sum1] = t
print(res)


z = int(input())
myList = list(map(int, input().split()))
d = set()
d.add(0)
cur = ans = 0
for i in myList:
	cur += i
	if cur in d:
		cur = i
		ans += 1
		d = set()
		d.add(0)
	d.add(cur)
print(ans)


n_numbers = int(input())
inp = list(map(int, input().split()))
d = set()
d.add(0)
resposta = 0
element = 0
count = 0
while count < n_numbers:
	element += inp[count]
	if element in d:
		resposta += 1
		d = set()
		d.add(0)
		element = inp[count]
	d.add(element)
	count += 1
print(resposta)


import math
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	n = Read.int()
	a = Read.list_int()
	tmp = {0: 1}
	s = 0
	res = 0
	for v in a:
		s += v
		if s in tmp:
			res += 1
			s = v
			tmp = {0: 1}
		tmp[s] = 1
	print(res)
query_count = 1
while query_count:
	query_count -= 1
	solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
n = N()
a = RLL()
res = 0
dic = {}
dic[0] = 1
s = 0
for c in a:
	s += c
	if s in dic:
		res += 1
		dic = {}
		dic[0] = 1
		s = c
	dic[s] = 1
print(res)


n = int(input())
a = input().split()
s = [0]
for ai in a:
	s.append(s[-1] + int(ai))
answer = 0
p = 0
ss = set()
for si in s:
	if si in ss:
		answer += 1
		ss = {p, si}
	else:
		ss.add(si)
	p = si
print(answer)


from collections import defaultdict
n = int(input())
a = [int(i) for i in input().split()]
dic = defaultdict(lambda : 0)
dic[0] = 1
psum = 0
ans = 0
for i in a:
	psum += i
	if dic[psum] != 0:
		ans += 1
		dic = defaultdict(lambda : 0)
		dic[0] = 1
		psum = i
	dic[psum] += 1
print(ans)


import sys
import heapq
import copy
import math
import decimal
input = sys.stdin.readline

def binary_exponentiation(a, b):
	ans = 1
	while b != 0:
		bit = b % 2
		if bit == 1:
			ans = ans * a
		a = a * a
		b = b // 2
	return ans

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	s = list(s[:len(s) - 1])
	s = [ord(s[i]) - ord('a') for i in range(len(s))]
	return s

def invr():
	return map(int, input().split())
ans = 0

def pr_list(a):
	print(*a, sep=' ')

def swap(a, b):
	temp = a
	a = b
	b = temp
	return [a, b]

def pri(a, b):
	s = '? ' + str(a) + ' ' + str(b)
	print(s)
	sys.stdout.flush()

def main():
	tests = 1
	mod = 998244353
	limit = 10 ** 18
	ans = 0
	stack = []
	arr = []
	heapq.heapify(arr)
	for test in range(tests):
		n = inp()
		a = inlt()
		ans = 0
		hashm = {}
		hashm[0] = 1
		hashm[a[0]] = 1
		pre = a[0]
		for i in range(1, n):
			pre = pre + a[i]
			if pre in hashm:
				pre = a[i]
				hashm = {}
				hashm[pre] = 1
				hashm[0] = 1
				ans = ans + 1
			else:
				hashm[pre] = 1
		print(ans)
main()


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
input = stdin.readline
n = int(input())
ar = list(map(int, input().split()))
d = {0: 0}
ans = 0
m = -1
p = 0
for i in range(n):
	p += ar[i]
	if d.get(p) != None and m <= d[p] + 1:
		m = i
		ans += 1
	d[p] = i
print(ans)


for _ in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	d = dict()
	lst = -1
	ans = 0
	bal = 0
	d[0] = -1
	for i in range(n):
		nbal = bal + arr[i]
		if nbal in d:
			k = d[nbal]
			if k >= lst:
				ans += 1
				lst = i - 1
		bal = nbal
		d[bal] = i
	print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
l = []
s = 0
for i in range(n):
	s = s + arr[i]
	l.append(s)
d = {}
pairs = []
for i in range(n):
	if l[i] == 0:
		if 0 in d:
			x = (d[0] + 1, i)
		else:
			x = (0, i)
		d[0] = i
	elif l[i] in d:
		x = (d[l[i]] + 1, i)
		d[l[i]] = i
	else:
		d[l[i]] = i
		continue
	if len(pairs) > 0:
		a = pairs[-1]
		if x[0] < a[1] and abs(x[0] - a[1]) >= 1:
			continue
		else:
			pairs.append(x)
	else:
		pairs.append(x)
print(len(pairs))


n = int(input())
A = list(map(int, input().split()))
cumsums = set([0])
n = 0
cumsum = 0
for a in A:
	cumsum += a
	if cumsum in cumsums:
		n += 1
		cumsum = a
		cumsums = set([0, a])
	else:
		cumsums.add(cumsum)
print(n)


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
import sys

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = {}
	l = 0
	su = 0
	p = -2
	for (i, v) in enumerate(a):
		su += v
		if su == 0:
			l += 1
			p = i - 1
			su = v
			b[su] = i
		elif b.get(su) == None:
			b[su] = i
		else:
			if b[su] > p:
				l += 1
				p = i - 1
				su = v
			b[su] = i
	print(l)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def nonZeroSegment(n, arr):
	count = 0
	map = {0: 0}
	sum = 0
	for i in range(0, n):
		sum += arr[i]
		if sum in map:
			count += 1
			map = {}
			map = {0: 0, arr[i]: arr[i]}
			sum = arr[i]
		map[sum] = sum
	print(count)
	return
n = int(input())
arr = [int(i) for i in input().split()][:n]
nonZeroSegment(n, arr)


n = int(input())
arr = list(map(int, input().split()))
prevSum = set([0])
currSum = ans = 0
for i in range(n):
	currSum += arr[i]
	if currSum in prevSum:
		ans += 1
		currSum = arr[i]
		prevSum.clear()
		prevSum.add(arr[i])
		prevSum.add(0)
	else:
		prevSum.add(currSum)
print(ans)


n = int(input())
a = list(map(int, input().split()))
count = 0
curr = 0
d = set()
d.add(0)
for j in range(n):
	curr += a[j]
	if curr in d:
		count += 1
		d = set()
		d.add(0)
		curr = a[j]
	d.add(curr)
print(count)


def subarraySum(nums, k):
	s = 0
	out = 0
	d = {}
	ln = len(nums)
	i = 0
	while i < ln:
		s += nums[i]
		if s == k:
			out += 1
			s += 10 ** 15
			s -= nums[i]
			i -= 1
		if s - k in d:
			out += d[s - k]
			s += 10 ** 15
			s -= nums[i]
			i -= 1
		d[s] = d.get(s, 0) + 1
		i += 1
	return out
n = int(input())
a = list(map(int, input().split()))
out = subarraySum(a, 0)
print(out)


n = int(input())
arr = list(map(int, input().split()))
from collections import Counter
c = Counter([])
sumi = 0
ans = 0
for i in range(len(arr)):
	sumi += arr[i]
	if sumi == 0:
		ans += 1
		sumi = arr[i]
		c = Counter([])
		c[sumi] = 1
		continue
	if c[sumi] == 0:
		c[sumi] += 1
		continue
	if c[sumi] == 1:
		ans += 1
		sumi = arr[i]
		c = Counter([])
		c[sumi] = 1
print(ans)


import sys
import math
input = sys.stdin.readline
t = int(input())
arr = list(map(int, input().split()))
E = set([0])
run = 0
ans = 0
c = 0
for el in arr:
	run += el
	if run in E:
		ans += 1
		E = set([0])
		run = el
	E.add(run)
print(ans)


n = int(input())
arr = {0}
s = ans = 0
for i in map(int, input().split()):
	s += i
	if s in arr:
		arr = {0, i}
		ans += 1
		s = i
	else:
		arr.add(s)
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
n = int(input())
l = list(map(int, input().split()))
su = [0] * (n + 1)
for i in range(n):
	su[i + 1] = su[i] + l[i]
se = set()
se.add(0)
ans = 0
last = 0
for i in range(1, n + 1):
	if su[i] - su[last] in se:
		ans += 1
		se = set()
		se.add(0)
		se.add(l[i - 1])
		last = i - 1
	else:
		se.add(su[i] - su[last])
print(ans)


(N,) = list(map(int, input().split()))
X = list(map(int, input().split()))
for i in range(1, N):
	X[i] += X[i - 1]
d = set([0])
R = 0
for i in range(N):
	if X[i] in d:
		R += 1
		d = set()
	d.add(X[i])
	if i > 0:
		d.add(X[i - 1])
print(R)


(n, values, seen, tot, ans) = (int(input()), [int(i) for i in input().split()], set([0]), 0, 0)
for i in range(n):
	tot += values[i]
	if tot in seen:
		(ans, seen, tot) = (ans + 1, set([0]), values[i])
	seen.add(tot)
print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 0
current = 0
st = set()
st.add(0)
for item in a:
	current += item
	if current in st:
		st = set()
		st.add(0)
		ans += 1
		current = item
	st.add(current)
print(ans)


for _ in range(1):
	n = int(input())
	a = list(map(int, input().split()))
	pref = [0] * (n + 1)
	pref[1] = a[0]
	ans = 0
	d = set()
	d.add(a[0])
	for i in range(2, n + 1):
		pref[i] = pref[i - 1] + a[i - 1]
		if pref[i] in d or pref[i] == 0:
			ans += 1
			pref[i] = a[i - 1]
			d = set()
			d.add(pref[i])
		else:
			d.add(pref[i])
	print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		r = 0
		s = set([0])
		k = 0
		for c in a:
			k += c
			if k in s:
				r += 1
				s = set([0, c])
				k = c
			else:
				s.add(k)
		rr.append(r)
	return JA(rr, '\n')
print(main())


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
n = inputnum()
a = inputlist()
s = set()
s.add(0)
cur = 0
ans = 0
for i in range(n):
	cur += a[i]
	if cur in s:
		ans += 1
		cur = a[i]
		s = set()
		s.add(0)
	s.add(cur)
print(ans)


import sys
import math, bisect
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

def I():
	return int(sys.stdin.readline())

def neo():
	return map(int, input().split())

def Neo():
	return list(map(int, input().split()))
n = I()
A = Neo()
s = {0}
(cur, Ans) = (0, 0)
for i in A:
	cur += i
	if cur in s:
		Ans += 1
		s = {0}
		cur = i
	s.add(cur)
print(Ans)


from collections import defaultdict as dd

def solve(arr, n):
	li = [0] + arr[:]
	dic = dd(int)
	dic[0] = 1
	pref_sm = [0]
	i = 0
	inserts = 0
	for (j, it) in enumerate(arr):
		v = pref_sm[-1] + it
		if v in dic:
			inserts += 1
			while i < j:
				psm = pref_sm[i]
				dic[psm] -= 1
				if dic[psm] == 0:
					del dic[psm]
				i += 1
		dic[v] += 1
		pref_sm.append(v)
	return inserts
n = int(input())
arr = list(map(int, input().split()))
ans = solve(arr, n)
print(ans)


import sys, math
input = lambda : sys.stdin.readline().rstrip()

def gcd(n, f):
	if n == 0 or f == 0:
		return max(n, f)
	if n > f:
		return gcd(n % f, f)
	else:
		return gcd(f % n, n)

def division_with_remainder_up(pp, ppp):
	return (pp + ppp - 1) // ppp
n = int(input())
a = list(map(int, input().split()))
d = set()
d.add(0)
ans = 0
c = 0
for i in range(n):
	ans += a[i]
	if ans in d:
		d = set()
		d.add(0)
		ans = a[i]
		c += 1
	d.add(ans)
print(c)


def main():
	n = int(input())
	A = list(map(int, input().split()))
	S = set([])
	S.add(0)
	prev = 0
	ans = 0
	for i in range(n):
		if prev + A[i] in S:
			ans += 1
			S = set([])
			S.add(0)
			S.add(A[i])
			prev = A[i]
		else:
			prev += A[i]
			S.add(prev)
	print(ans)
main()


import os
from sys import stdin, stdout

class Input:

	def __init__(self):
		self.lines = stdin.readlines()
		self.idx = 0

	def line(self):
		try:
			return self.lines[self.idx].strip()
		finally:
			self.idx += 1

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

	def has_next(self):
		return self.idx < len(self.lines)

def known_cases(func):
	inpt = Input()
	(cases,) = inpt.array()
	for case in range(cases):
		func(inpt)

def unknown_cases(func):
	inpt = Input()
	while inpt.has_next():
		func(inpt)
import math

@unknown_cases
def solve(inpt):
	(n,) = inpt.array()
	a = inpt.array()
	pfxs = {0: 1}
	ans = 0
	s = 0
	for x in a:
		s += x
		if pfxs.get(s, 0):
			ans += 1
			s = x
			pfxs = {s: 1, 0: 1}
		else:
			pfxs[s] = pfxs.get(s, 0) + 1
	print(ans)


n = int(input())
a = list(map(int, input().split()))
st = set()
st.add(0)
now = ans = 0
for i in range(n):
	now += a[i]
	if now in st:
		ans += 1
		st = set()
		st.add(0)
		now = a[i]
	st.add(now)
print(ans)


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
n = int(input())
ar = [int(x) for x in input().split()]
arf = [0]
for i in range(n):
	arf.append(arf[-1] + ar[i])
ans = 0
st = 0
lastEnd = -1
m = {}
for i in range(len(arf)):
	if arf[i] in m:
		if lastEnd - m[arf[i]] < 2:
			lastEnd = i
			ans += 1
	m[arf[i]] = i
print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b
mod = 998244353

def solve(we):
	n = iin()
	l = lin()
	d = {}
	s = 0
	for i in range(n):
		s += l[i]
		if s in d:
			d[s].append(i)
		else:
			d[s] = [i]
	z = []
	count = 0
	for i in d:
		if i == 0:
			d[i] = [-1] + d[i]
		flag = 0
		if len(d[i]) > 1:
			k = 1
			while k < len(d[i]):
				z.append([d[i][k - 1] + 1, d[i][k]])
				k += 1
	z.sort()
	if len(z) > 1:
		x = z[0]
		count = 0
		for i in range(1, len(z)):
			if z[i][0] >= x[1]:
				count += 1
				x = z[i]
			else:
				x = [max(x[0], z[i][0]), min(x[1], z[i][1])]
		count += 1
	else:
		count = len(z)
	print(count)
qwe = 1
for _ in range(qwe):
	solve(_ + 1)


def solve():
	inf = 1000000007
	n = int(input())
	arr = [int(v) for v in input().split()]
	st = set([0])
	s = 0
	ans = 0
	for i in range(n):
		s += arr[i]
		if s in st:
			ans += 1
			s = arr[i]
			st = set([s, 0])
		else:
			st.add(s)
	print(ans)
t = 1
for _ in range(t):
	solve()


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}
from bisect import bisect_right, bisect_left

def solve(n, lst):
	n += 1
	lst = [0] + lst
	pref = {}
	summ = 0
	cnt = 0
	for i in range(n):
		summ += lst[i]
		if pref.get(summ) == None:
			pref[summ] = 1
		else:
			cnt += 1
			pref = {0: 1, lst[i]: 1}
			summ = lst[i]
	return cnt
n = int(input())
lst = list(map(int, input().split()))
print(solve(n, lst))


n = int(input())
nums = [int(x) for x in input().split()]
ht = {0: -1}
s = 0
res = 0
for i in range(n):
	s += nums[i]
	if s in ht:
		res += 1
		ht = {0: -1}
		s = nums[i]
	ht[s] = i
print(res)


from sys import stdin
tt = 1
for loop in range(tt):
	dic = {}
	dic[0] = 1
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	now = 0
	ans = 0
	for i in a:
		now += i
		if now in dic:
			ans += 1
			dic = {}
			dic[0] = 1
			now = i
		dic[now] = 1
	print(ans)


def readis():
	return map(int, input().strip().split())
n = int(input())
xs = readis()
cumsums = {0}
count_inserts = 0
last = 0
for x in xs:
	last += x
	if last in cumsums:
		count_inserts += 1
		cumsums = {0}
		last = x
	cumsums.add(last)
print(count_inserts)


from sys import stdin, stdout
import math
from bisect import bisect_left
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	return ' '.join(list(map(str, a)))

def solve():
	n = I()
	a = L()
	(ans, s) = (0, 0)
	se = {0}
	for i in a:
		s += i
		if s in se:
			ans += 1
			se = {0}
			s = i
		se |= {s}
	print(ans)
for _ in range(1):
	solve()


res = 0
summ = 0
my_set = {0}
n = int(input())
mas = list(map(int, input().split()))
for num in mas:
	summ += num
	if summ in my_set:
		my_set = {0}
		res += 1
		summ = num
	my_set.add(summ)
print(res)


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	n = ii()
	a = li()
	m = {}
	s = 0
	cnt = 0
	m[0] = 1
	for i in a:
		s += i
		if s in m:
			cnt += 1
			m.clear()
			m[0] = 1
			s = i
		m[s] = 1
	print(cnt)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


n = int(input())
arr = list(map(int, input().split(' ')))
s = {arr[0]}
sm = arr[0]
cnt = 0
for i in range(1, n):
	sm += arr[i]
	if sm == 0 or sm in s:
		s = {arr[i]}
		sm = arr[i]
		cnt += 1
	else:
		s.add(sm)
print(cnt)


import sys
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col

def solve():
	N = getInt()
	A = getInts()
	prefix = col.defaultdict(list)
	curr_sum = 0
	prefix[0].append(0)
	for j in range(N):
		curr_sum += A[j]
		prefix[curr_sum].append(j + 1)
	pairs = []
	for key in prefix:
		tmp = prefix[key]
		for j in range(1, len(tmp)):
			pairs.append((tmp[j - 1], tmp[j] - 1))
	pairs.sort()
	j = 0
	ref = 1
	ans = len(pairs)
	LL = len(pairs) * 1
	while ref < LL:
		if pairs[ref][0] < pairs[j][1]:
			if pairs[ref][1] < pairs[j][1]:
				j = ref
			ref += 1
			ans -= 1
			continue
		j = ref
		ref += 1
	return ans
print(solve())


def func():
	n = int(input())
	l = list(map(int, input().split()))
	pre = set()
	pre.add(0)
	curr = 0
	cnt = 0
	for i in range(n):
		curr += l[i]
		if curr in pre:
			cnt += 1
			pre = set()
			pre.add(0)
			curr = l[i]
		pre.add(curr)
	return cnt
t = 1
for i in range(t):
	print(func())


input()
prefix_sums = set()
prefix_sums_shift = 1000
result = 0
for x in map(int, input().split()):
	if prefix_sums_shift - x in prefix_sums:
		result += 1
		prefix_sums = set()
		prefix_sums_shift = 0
	prefix_sums_shift -= x
	prefix_sums.add(x + prefix_sums_shift)
print(result)


l = []
if 1 == 1:
	n = int(input())
	a = list(map(int, input().split()))
	q = set()
	sum = 0
	count = 0
	for i in range(n):
		sum = sum + a[i]
		if sum in q or sum == 0:
			sum = a[i]
			q.clear()
			q.add(a[i])
			count = count + 1
		else:
			q.add(sum)
	l.append(count)
for i in l:
	print(i)


import sys
n = int(input())
a = list(map(int, input().split()))
s = set()
s.add(0)
sum = 0
ans = 0
for i in range(n):
	sum += a[i]
	if sum in s:
		ans += 1
		s = set()
		s.add(0)
		sum = a[i]
	s.add(sum)
print(ans)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 10
	A = 10
	n = random.randint(1, N)
	a = [random.randint(1, A) for i in range(n)]
	return (n, a)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print((a1, a2), inp)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
show_flg = True
ans = 0
for _ in range(1):
	ans = 0
	n = I()
	a = LI()
	s = set([0])
	ac = [0]
	for i in a:
		if ac[-1] + i in s:
			ans += 1
			s = set([0, i])
			ac = [0, i]
		else:
			ac += (ac[-1] + i,)
		s.add(ac[-1])
	print(ans)


def solve():
	n = int(input())
	ll = list(map(int, input().split()))
	s = set()
	sm = 0
	cnt = 0
	for i in ll:
		sm += i
		if sm == 0:
			cnt += 1
			sm = i
			s = set()
		elif sm in s:
			cnt += 1
			s = set()
			sm = i
		s.add(sm)
	print(cnt)
solve()


n = int(input())
arr = list(map(int, input().split()))
s = {0}
curr = 0
ans = 0
for x in arr:
	curr += x
	if curr in s:
		ans += 1
		s = {0}
		curr = x
	s.add(curr)
print(ans)


from collections import defaultdict
import heapq
n = int(input())
a = [int(x) for x in input().split()]
prefix = [0]
for val in a:
	prefix.append(prefix[-1] + val)
seen = defaultdict(list)
lastPlaced = -1
result = 0
for (i, p) in enumerate(prefix):
	if p in seen:
		indices = seen[p]
		if lastPlaced == -1:
			numNeeded = 1
		else:
			maxVal = -1 * indices[0]
			numNeeded = 1 if maxVal >= lastPlaced else 0
		if numNeeded > 0:
			result += 1
			lastPlaced = i - 1
	heapq.heappush(seen[p], -1 * i)
print(result)


from bisect import bisect_left, bisect_right
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque, defaultdict
import math
import heapq
import re

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
LOW = 'abcdefghijklmnopqrstuvwxyz'
UP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
MAX = float('inf')
MIN = float('-inf')
MOD = 998244353

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def main():
	n = iin()
	l = ain()
	d = set()
	d.add(0)
	ans = 0
	suma = 0
	for i in range(n):
		suma += l[i]
		if suma in d:
			ans += 1
			d = set()
			d.add(0)
			suma = l[i]
		d.add(suma)
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
n = int(input())
a = list(map(int, input().split()))
x = 0
f = {}
f[0] = 1
ans = 0
for i in range(n):
	x += a[i]
	if x not in f:
		f[x] = 1
	else:
		f[x] += 1
		ans += 1
		f = {}
		f[0] = 1
		x = a[i]
		f[x] = 1
print(ans)


import math
import sys
n = int(input())
ar = list(map(int, input().split()))
sum = ans = 0
br = set([0])
for x in ar:
	sum += x
	if sum in br:
		ans += 1
		sum = x
		br = set([0])
	br.add(sum)
print(ans)


import sys
input = sys.stdin.buffer.readline
n = int(input())
A = list(map(int, input().split()))
sums = {0}
cumulative = 0
count = 0
for a in A:
	cumulative += a
	if cumulative in sums:
		count += 1
		sums = {0, a}
		cumulative = a
	else:
		sums.add(cumulative)
print(count)


import sys
read = lambda : sys.stdin.readline().strip()
readi = lambda : map(int, read().split())
from collections import defaultdict
n = int(read())
nums = list(readi())
mem = defaultdict(int)
mem[0] += 1
tempSum = 0
ans = 0
for num in nums:
	tempSum += num
	if tempSum in mem:
		mem = defaultdict(int)
		tempSum = num
		mem[0] += 1
		ans += 1
	mem[tempSum] += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
sums = set([0])
sum = 0
count = 0
for i in a:
	sum += i
	if sum in sums:
		count += 1
		sums = set([0])
		sum = i
	sums.add(sum)
print(count)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
seen = set()
seen.add(0)
ct = 0
cur = 0
for i in range(n):
	cur += a[i]
	if cur in seen:
		ct += 1
		cur = a[i]
		seen = set([0])
	seen.add(cur)
print(ct)


n = int(input())
arr = list(map(int, input().split()))
count = 0
dic = {}
curSum = 0
for i in arr:
	if curSum + i == 0 or curSum + i in dic:
		count += 1
		curSum = i
		dic = {}
		dic[i] = 1
	else:
		curSum += i
		dic[curSum] = 1
print(count)


(n,) = input().split()
arr = list(map(int, input().split()))
mp = {0: -1}
s = 0
last = -2
ans = 0
for (i, c) in enumerate(arr):
	s += c
	if s in mp and mp[s] > last:
		ans += 1
		last = i - 1
	mp[s] = i + 1
print(ans)


n = int(input())
g = {0}
ans = 0
s = 0
for i in map(int, input().split()):
	s += i
	if s in g:
		g = {0}
		ans += 1
		s = i
	g.add(s)
print(ans)


n = int(input())
ar = [int(x) for x in input().split()]
s = set()
s.add(0)
cur = 0
ans = 0
for i in ar:
	cur += i
	if cur in s:
		ans += 1
		s.clear()
		s.add(0)
		cur = i
	s.add(cur)
print(ans)


n = int(input())
list1 = list(map(int, input().split()))
temp_s = 0
set1 = set()
i = 0
ans = 0
while i < n:
	temp_s += list1[i]
	if temp_s == 0:
		set1 = set()
		ans += 1
	else:
		l1 = len(set1)
		set1.add(temp_s)
		if l1 == len(set1) or temp_s == 0:
			set1 = set()
			temp_s = 0
			ans += 1
		else:
			i += 1
print(ans)


n = int(input())
arr = list(map(int, input().split()))
pS = set([0])
s = 0
count = 0
for j in range(len(arr)):
	i = arr[j]
	s += i
	if s in pS:
		s = i
		pS = set([0])
		count += 1
	pS.add(s)
print(count)


input()
li = list(map(int, input().split()))
s = {0}
(count, sm) = (0, 0)
for i in li:
	sm = sm + i
	if sm in s:
		s = {0}
		count = count + 1
		sm = i
	s.add(sm)
print(count)


n = int(input())
a = list(map(int, input().split()))
s = {0: 1}
pref = ans = 0
for q in range(n):
	pref += a[q]
	if pref not in s:
		s[pref] = 1
	else:
		ans += 1
		pref = a[q]
		s = {0: 1, pref: 1}
print(ans)


from math import ceil, sqrt

def zSumSubArr(arr, n):
	s = 0
	out = []
	hMap = {}
	for i in range(n):
		s += arr[i]
		if s == 0:
			out.append((0, i))
		if s in hMap:
			al = hMap.get(s)
			out.append((al + 1, i))
		hMap[s] = i
	return out

def is_algo(st, ft):
	index = list(range(len(st)))
	k = 0
	index.sort(key=lambda i: ft[i])
	pft = 0
	for i in index:
		if st[i] >= pft:
			pft = ft[i]
			k += 1
	return k
n = int(input())
a = [int(c) for c in input().split()]
q = zSumSubArr(a, n)
if len(q) == 0:
	print(0)
else:
	st_1 = [i[0] for i in q]
	ft_1 = [i[1] for i in q]
	print(is_algo(st_1, ft_1))


n = int(input())
l = list(map(int, input().strip().split()))
ans = 0
lastInd = {}
curSum = 0
lastInd[0] = -1
for i in range(n):
	curSum += l[i]
	if curSum in lastInd:
		ans += 1
		lastInd = {}
		lastInd[0] = i - 1
		lastInd[l[i]] = i
		curSum = l[i]
	else:
		lastInd[curSum] = i
print(ans)


import os
import math
true = True
false = False
from functools import reduce
is_dev = 'vscode' in os.environ
if is_dev:
	inF = open('in.txt', 'r')
	outF = open('out.txt', 'w')

def ins():
	return list(map(int, input_().split(' ')))

def inss():
	return list(input_().split(' '))

def input_():
	if is_dev:
		return inF.readline()[:-1]
	else:
		return input()

def ranin():
	return range(int(input_()))

def print_(data):
	if is_dev:
		outF.write(str(data) + '\n')
	else:
		print(data)
n = int(input_())
a = ins()
s = {0}
su = 0
count = 0
idx = 0
for ai in a:
	idx += 1
	if su + ai in s:
		count += 1
		s = {0, ai}
		su = ai
	else:
		su += ai
		s.add(su)
print_(count)
if is_dev:
	outF.close()

	def compare_file():
		print(open('out.txt', 'r').read() == open('outactual.txt', 'r').read())
	compare_file()


n = int(input())
a = list(map(int, input().split()))
Map = {0: -1}
s = 0
arr = []
for i in range(n):
	s += a[i]
	if s in Map:
		arr.append([Map[s] + 1, i])
	Map[s] = i
m = len(arr)
if m == 0:
	print('0')
else:
	ans = []
	ans.append(arr[0])
	i = 0
	for j in range(1, m):
		if arr[j][0] < ans[i][1]:
			continue
		else:
			ans.append(arr[j])
			i += 1
	print(len(ans))


_ = input()
numbers = [int(i) for i in input().split()]
seen_sum = {0}
tot = 0
num_zeros = 0
index = 0
while index < len(numbers):
	tot += numbers[index]
	if tot in seen_sum:
		num_zeros += 1
		tot = 0
		seen_sum = {0}
	else:
		seen_sum.add(tot)
		index += 1
print(num_zeros)


input()
a = {0}
ans = sum = 0
for i in map(int, input().split()):
	sum += i
	if sum in a:
		a = {0}
		sum = i
		ans += 1
	a.add(sum)
print(ans)


from sys import stdin, stdout
n = int(stdin.readline().strip())
arr = [int(num) for num in stdin.readline().strip().split()]
req0 = {}
req1 = [arr[0]]
(res, r) = (0, None)
for i in range(1, n):
	req1.append(req1[-1] + arr[i])
for i in range(n):
	found = req0.get(req1[i], -1)
	if found == -1:
		if req1[i] == 0 and r is None:
			r = i
			res += 1
	elif r is None:
		r = i
		res += 1
	elif found + 1 >= r:
		res += 1
		r = i
	req0[req1[i]] = i
stdout.write(f'{res}')


import math
from decimal import *
import random
mod = int(1000000000.0) + 7
n = int(input())
arr = list(map(int, input().split()))
cnt = 0
done = set()
done.add(0)
ans = 0
for i in range(n):
	cnt += arr[i]
	if cnt in done:
		ans += 1
		done = set()
		done.add(0)
		cnt = arr[i]
	done.add(cnt)
print(ans)


def iinput():
	return [int(i) for i in input().split()]

def solve(n):
	pass
n = int(input())
mas = iinput()
pref = set()
pref.add(0)
cur_sum = 0
ans = 0
for i in mas:
	cur_sum += i
	if cur_sum in pref:
		ans += 1
		pref = set()
		pref.add(0)
		cur_sum = i
	pref.add(cur_sum)
print(ans)


n = int(input())
a = list(map(int, input().split()))
cum = [a[i] for i in range(n)]
for i in range(1, n):
	cum[i] += cum[i - 1]
val = set([0])
res = 0
for i in range(n):
	if cum[i] in val:
		val = set([cum[i - 1], cum[i]])
		res += 1
	else:
		val.add(cum[i])
print(res)


from collections import deque, defaultdict

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	pre = c = 0
	d = {0: 0}
	for i in range(n):
		pre += a[i]
		if pre in d:
			c += 1
			d = {0: 0}
			pre = a[i]
		d[pre] = 0
	print(c)

def main():
	t = 1
	for _ in range(t):
		solve()
main()


n = int(input())
a = list(map(int, input().split()))
cumsum = [0 for _ in range(n)]
cumsum[0] = a[0]
for i in range(1, n):
	cumsum[i] = cumsum[i - 1] + a[i]
active = {}
active[0] = 1
total = 0
for i in range(n):
	if cumsum[i] in active:
		total += 1
		active = {}
		active[cumsum[i]] = 1
		if i > 0:
			active[cumsum[i - 1]] = 1
	else:
		active[cumsum[i]] = 1
print(total)


import math
import os
from io import BytesIO, IOBase
import sys
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = [int(i) for i in input().split()]
sum_arr = [0] * n
sum_arr[0] = a[0]
last_seen = {}
last_seen[0] = -1
last_seen[sum_arr[0]] = 0
bad = []
for idx in range(1, n):
	sum_arr[idx] = sum_arr[idx - 1] + a[idx]
	if sum_arr[idx] in last_seen:
		bad.append((last_seen[sum_arr[idx]] + 1, idx))
	last_seen[sum_arr[idx]] = idx
segments = bad
segments.sort(key=lambda x: x[1])
count = 0
last = -1
for seg in segments:
	if seg[0] >= last:
		count += 1
		last = seg[1]
print(count)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
arr = list(map(int, input().split()))
dict1 = {}
dict1[0] = 1
ans = 0
s = 0
for i in range(n):
	s += arr[i]
	if s in dict1.keys():
		ans += 1
		dict1 = {}
		dict1[0] = i
		dict1[arr[i]] = i
		s = arr[i]
	else:
		dict1[s] = i
print(ans)


from sys import stdin, stdout
for _ in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	s = {0}
	sm = ans = 0
	for v in a:
		sm += v
		if sm in s:
			ans += 1
			sm = v
			s = {0, v}
		else:
			s.add(sm)
	print(ans)