#include <bits/stdc++.h>
using namespace std;
int psum[100005], tmp[100005];
map<int, int> hsh;
long long dp[4][100005];
long long sum[4][100005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n); i += (1)) {
    int v;
    scanf("%d", &v);
    tmp[i] = psum[i] = psum[i - 1] + v;
  }
  sort(tmp, tmp + n + 1);
  int it = 0;
  for (int i = (0); i <= (n); i += (1)) {
    it += (i == 0 || tmp[i] != tmp[i - 1]);
    hsh[tmp[i]] = it;
  }
  memset(sum, 0, sizeof(sum));
  dp[0][0] = sum[0][hsh[0]] = 1;
  for (int i = (1); i <= (n); i += (1)) {
    int id = hsh[psum[i]];
    for (int j = (1); j <= (3); j += (1)) {
      if (psum[i] % j) continue;
      int k = hsh[psum[i] / j * (j - 1)];
      if (!k) continue;
      dp[j][i] = sum[j - 1][k];
    }
    for (int j = (1); j <= (3); j += (1)) sum[j][id] += dp[j][i];
  }
  printf("%lld\n", dp[3][n]);
  return 0;
}
