#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;
const ll inf = 2e18;
const ll mod = 1e8;
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
int kr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int kc[] = {-2, -2, -1, 1, 2, 2, -1, 1};
int dgr[] = {-1, -1, 1, 1};
int dgc[] = {1, -1, -1, 1};
int main() {
  int n, x;
  cin >> n;
  vector<ll> pref(n + 2);
  for (int i = 0; i < n; i++) {
    cin >> x;
    pref[i + 1] = pref[i] + x;
  }
  ll ans = 0;
  if (n < 3) {
    printf("0\n");
  } else {
    int cnt = 0;
    ll sum = pref[n];
    for (int i = 0; i < n - 1; i++) {
      if (((2 * sum) % 3 == 0) && pref[i + 1] == ((2 * sum) / 3)) ans += cnt;
      if ((sum % 3) == 0 && pref[i + 1] == (sum / 3)) cnt++;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
