def main(): n = int(input()) a = list(map(int, input().split())) M = 30 R = n * M ans = n * (n + 1) // 2 cnt = [0] * (R + 1) # [x or not x, \cdots, x] for x in range(1, M + 1): b = [a[i] - x for i in range(n)] C = n * x s = [0] * (n + 1) for i in range(n): s[i + 1] = s[i] + b[i] for i in range(n): cnt[C + s[i]] += 1 if b[i] == 0: ans -= cnt[C + s[i + 1]] for i in range(n): cnt[C + s[i]] = 0 # [x, \cdots, not x] for x in range(1, M + 1): b = [a[i] - x for i in range(n)] C = n * x s = [0] * (n + 1) for i in range(n): s[i + 1] = s[i] + b[i] for i in range(n): if b[i] == 0: cnt[C + s[i]] += 1 else: ans -= cnt[C + s[i + 1]] for i in range(n): if b[i] == 0: cnt[C + s[i]] = 0 ans += 1 print(ans) if __name__ == "__main__": main()