#include <bits/stdc++.h>
using namespace std;
long long dp[200003];
int main(void) {
  std::ios::sync_with_stdio(false);
  int n;
  long long a[200003];
  while (cin >> n && n != 0) {
    int i;
    dp[0] = 0;
    for (i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    long long sum = 0;
    for (i = 1; i <= n; ++i) {
      int cishu = 0;
      if (a[i] == 0) {
        dp[i] = dp[i - 1] + 1;
        sum += dp[i];
        continue;
      }
      long long q = a[i];
      int j;
      for (j = i - 1; j >= 1; --j) {
        cishu++;
        if (cishu >= 100000) break;
        q += a[j];
        if (q == 0) {
          break;
        }
      }
      if (j >= 1) {
        dp[i] = 1 + dp[j - 1];
        sum += dp[i];
      }
    }
    cout << sum << endl;
  }
  return 0;
}
