#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  long long count = 0, ans = 0;
  cin >> n;
  vector<long long int> v(n);
  cin >> v[0];
  for (long long int i = 1; i < n; i++) {
    cin >> v[i];
    v[i] += v[i - 1];
  }
  for (long long int i = 0; i < n - 1; i++) {
    if (v[i] * 3 == 2 * v[n - 1]) ans += count;
    if (v[i] * 3 == v[n - 1]) count++;
  }
  cout << ans;
  return 0;
}
