n = int(input()) a = list(map(int,input().split())) m = max(a); s = n*(n+1)//2+1 for i in range(1,m+1): b = [0]; d = {} for v in a: b.append(b[-1]+v-i) for i,v in enumerate(b): if v in d: if d[v][2]==i-1: d[v][1] += 1; d[v][2] = i else: d[v][0] += 1; d[v][1] += 1; d[v][2] = i else: d[v] = [1,1,i] for p,q,_ in d.values(): s -= q*(q-1)//2-p*(p-1)//2 print(s)