#include using namespace std; int main() { int N; cin >> N; vector A(N + 1); for(int i = 1; i <= N; i++) { cin >> A[i]; } constexpr int M = 30; long long ans = (long long) N * (N + 1) / 2; for(int x = 1; x <= M; x++) { vector B = A; for(int i = 1; i <= N; i++) { B[i] += B[i - 1] - x; } map mp, mp2; for(int i = 0; i <= N; i++) { if(A[i] == x) { ans -= mp[B[i]] + mp2[B[i]]; mp2[B[i]]++; }else { ans -= mp2[B[i]]; mp[B[i]]++; } } } cout << ans + 1 << endl; }