#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<long long> s(n + 1);
  unordered_map<long long, long long> d;
  for (long long i = 1; i <= n; i++) {
    long long t;
    cin >> t;
    s[i] = s[i - 1] + t;
    if (d.find(s[i]) == d.end()) d[s[i]] = 0;
    if (i != n) d[s[i]]++;
  }
  long long result = 0;
  for (long long i = 1; i <= n - 2; i++) {
    d[s[i]]--;
    if (3 * s[i] == s[n]) {
      result += d[2 * s[i]];
    }
  }
  cout << result << '\n';
}
