#include <bits/stdc++.h>                                                                           
                                                                                                   
using namespace std;                                                                               
                                                                                                   
#define all(x) x.begin(), x.end()                                                                  
#define rep(i, n) for (int i = 0; i < n; ++i)                                                      
#define reps(i, m, n) for (int i = m; i <= n; ++i)                                                 
                                                                                                   
using i64 = long long;                                                                             
using pii = pair<i64, i64>;                                                                        
                                                                                                   
template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}         
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}         
                                                                                                   
constexpr int INF = 0x3f3f3f3f;                                                                    
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;                                                         
constexpr int MOD = int(1e9) + 7;                                                                  
                                                                                                   
signed main()                                                                                      
{                                                                                                  
  ios::sync_with_stdio(false);                                                                     
  cin.tie(nullptr);                                                                                
                                                                                                   
  int N;                                                                                           
  cin >> N;                                                                                        
                                                                                                   
  vector<i64> cum(N+1);                                                                            
  reps(i, 1, N) {                                                                                  
    int a;                                                                                         
    cin >> a;                                                                                      
    cum[i] = cum[i-1] + a;                                                                         
  }                                                                                                
                                                                                                   
  map<i64, i64> cnt;                                                                               
  reps(i, 0, N) {                                                                                  
    ++cnt[cum[i]];                                                                                 
  }                                                                                                
                                                                                                   
  i64 ans = 0;                                                                                     
  map<i64, bool> exist;                                                                            
  reps(i, 0, N) {                                                                                  
    if (exist[cum[i]]) continue;                                                                   
    exist[cum[i]] = true;                                                                          
    ans += (cnt[cum[i]] - 1) * cnt[cum[i]] / 2;                                                    
  }                                                                                                
                                                                                                   
  cout << ans << "\n";                                                                             
                                                                                                   
  return 0;                                                                                        
}                                                                                                  

Measured memory_bytes: 26880