#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 90;
const int MAX1 = 1e6 + 9;
const double pi = acos(-1);
const long long int inf = INT_MAX;
const long long int mod = 1e9;
bool prime[MAX];
int dp[MAX];
int pfactors[MAX];
long long mexp(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2) {
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    b = b / 2;
  }
  return res;
}
vector<int> totient() {
  long long tt[MAX];
  for (int i = 1; i < MAX; i++) tt[i] = i;
  for (int i = 2; i < MAX; i++) {
    if (tt[i] == i) {
      for (int j = i; j < MAX; j += i) {
        tt[j] /= i;
        tt[j] *= i - 1;
      }
    }
  }
  vector<int> v;
  for (int i = 1; i < MAX; i++) v.push_back(tt[i]);
  return v;
}
vector<int> seive() {
  for (int i = 2; i < MAX; i++) prime[i] = false;
  int k = 0;
  vector<int> p;
  for (int i = 2; i < MAX; i++) {
    if (!prime[i]) {
      for (int j = 2 * i; j < MAX; j += i) prime[j] = true;
    }
  }
  for (int i = 2; i < MAX; i++) {
    if (!prime[i]) p.push_back(i);
  }
  return p;
}
int main() {
  int n;
  cin >> n;
  int arr[n + 1];
  for (int i = 1; i <= n; i++) cin >> arr[i];
  int pre[n + 1];
  pre[1] = arr[1];
  for (int i = 2; i <= n; i++) pre[i] = pre[i - 1] + arr[i];
  map<long long, long long> mp;
  if (pre[n] % 3 != 0) {
    cout << 0 << "\n";
    return 0;
  }
  long long ans = 0;
  long long need = pre[n] * 2 / 3;
  for (int i = 1; i < n; i++) {
    if (pre[i] == need) {
      ans += mp[pre[n] / 3];
    }
    mp[pre[i]]++;
  }
  cout << ans << "\n";
}
