def main(): n = int(input()) a = list(map(int, input().split())) M = 30 R = n * M cnt_zero = [0] * (2 * R + 1) cnt_non_zero = [0] * (2 * R + 1) 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] for i in range(n): if b[i] == 0: cnt_zero[R + s[i]] += 1 ans -= cnt_zero[R + s[i + 1]] + cnt_non_zero[R + s[i + 1]] else: cnt_non_zero[R + s[i]] += 1 ans -= cnt_zero[R + s[i + 1]] for i in range(n): if b[i] == 0: cnt_zero[R + s[i]] = 0 else: cnt_non_zero[R + s[i]] = 0 ans += 1 print(ans) if __name__ == "__main__": main()