#include <bits/stdc++.h>
using namespace std;
const long long maxn = 200010;
void solve(long long case_no) {
  long long n;
  cin >> n;
  vector<long long> arr(n + 1), sum(n + 1);
  for (long long i = 1; i <= n; i++)
    cin >> arr[i], sum[i] = arr[i] + sum[i - 1];
  long long res = 0, first_repeat = n + 1, last_zero = n + 1;
  map<long long, long long> last_found;
  set<int> found;
  for (long long i = n; i > 0; i--) {
    if (arr[i] == 0) {
      last_zero = i;
      continue;
    }
    if (last_found[sum[i - 1]] == 0) last_found[sum[i - 1]] = n + 1;
    if (last_found[sum[i]] != 0 and last_found[sum[i]] != n + 1)
      first_repeat = min(first_repeat, last_found[sum[i]]);
    res += min(last_found[sum[i - 1]], min(first_repeat, last_zero)) - i;
    last_found[sum[i]] = i;
  }
  cout << res << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long test_cnt = 1, case_no = 1;
  while (case_no <= test_cnt) solve(case_no++);
  return 0;
}
