import itertools n = int(input()) a = list(map(int,input().split())) b = [[0 for j in range(n)] for i in range(31)] for i in range(31): for j in range(n): b[i][j] = a[j] - i b[i] = list(itertools.accumulate(b[i])) + [0] ans = 0 import collections c = [collections.defaultdict(int) for i in range(31)] for i in reversed(range(n)): for j in range(31): c[j][b[j][i]] += 1 ans -= c[a[i]][b[a[i]][i]] #print(i,c[a[i]][b[a[i]][i]]) a.reverse() b = [[0 for j in range(n)] for i in range(31)] for i in range(31): for j in range(n): b[i][j] = a[j] - i b[i] = list(itertools.accumulate(b[i])) + [0] import collections c = [collections.defaultdict(int) for i in range(31)] for i in reversed(range(n)): for j in range(31): c[j][b[j][i]] += 1 ans -= c[a[i]][b[a[i]][i]] #print(i,c[a[i]][b[a[i]][i]]) ans += n*(n+1)//2 print(ans+1)