from collections import defaultdict M = 30 def main(): n = int(input()) a = list(map(int, input().split())) ans = n * (n + 1) // 2 for x in range(1, M + 1): b = [a[i] - x for i in range(n)] s = [0] * (n + 1) for i in range(n): s[i + 1] = s[i] + b[i] map_zero = defaultdict(int) map_non_zero = defaultdict(int) for i in range(n): if b[i] == 0: map_zero[s[i]] += 1 ans -= map_zero[s[i + 1]] + map_non_zero[s[i + 1]] else: map_non_zero[s[i]] += 1 ans -= map_zero[s[i + 1]] ans += 1 print(ans) if __name__ == "__main__": main()