#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  long long arr[n], s = 0;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    s += arr[i];
  }
  if (s % 3 != 0 or n <= 2) {
    cout << 0;
  } else {
    long long t = s / 3, ad = 0, w = 0, a = 0;
    for (long long i = 0; i < n - 1; i++) {
      ad += arr[i];
      if (ad == 2 * t) {
        a += w;
      }
      if (ad == t) {
        w++;
      }
    }
    cout << a;
  }
  return 0;
}
