#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using llu = unsigned long long;
unordered_map<ll, ll> p;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t, n, m, i, j, k;
  cin >> n;
  ll a[n], c[n];
  for (i = 0; i < n; i++) cin >> a[i];
  k = 0;
  for (i = n - 1; i >= 0; i--) k += a[i], p[k]++, c[i] = k;
  k = 0;
  p[c[0]]--;
  ll ans = 0;
  for (i = 0; i < n - 1; i++) {
    k += a[i];
    p[c[i + 1]]--;
    if (k * 3 == c[0]) ans += p[k];
  }
  cout << ans;
}
