#include <bits/stdc++.h>
using namespace std;
const long long int inf = 0x3f3f3f3f;
const long long int INF = 0x3f3f3f3f3f3f3f3f;
long long int n, m, k, q;
string s;
vector<long long int> adj[(long long int)2e5 + 5];
long long int vis[(long long int)2e5 + 5], par[(long long int)2e5 + 5],
    a[(long long int)2e5 + 5];
vector<long long int> v;
void go() {
  cin >> n;
  for (long long int i = 1; i < n + 1; i++) cin >> a[i], a[i] += a[i - 1];
  if (a[n] % 3 != 0) {
    cout << 0 << '\n';
    return;
  }
  long long int sum = a[n] / 3;
  long long int nSum = 2 * sum;
  long long int cn = 0;
  long long int ans = 0;
  for (long long int i = 1; i < n; i++) {
    if (a[i] == nSum) ans += cn;
    if (a[i] == sum) cn++;
  }
  cout << ans << '\n';
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) go();
}
