#include <bits/stdc++.h>
using namespace std;
int f1[200001], f2[200001];
int rec1[200001], rec2[200001], num1 = 0, num2 = 0;
int a[200001], n;
int main() {
  cin >> n;
  num1++;
  num2++;
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum % 3 != 0) {
    cout << "0" << endl;
    return 0;
  }
  sum /= 3;
  f1[0] = 0;
  for (int i = 1; i <= n; i++) {
    f1[i] = f1[i - 1] + a[i];
    if (f1[i] == sum) {
      rec1[num1] = i;
      num1++;
    }
  }
  f2[0] = 0;
  for (int i = n; i >= 1; i--) {
    f2[n - i + 1] = f2[n - i] + a[i];
    if (f2[n - i + 1] == sum) {
      rec2[num2] = i;
      num2++;
    }
  }
  long long int ans = 0;
  long long int loc = num2 - 1;
  for (int i = 1; i < num1; i++) {
    for (int j = loc; j >= 1; j--)
      if (rec2[j] > (rec1[i] + 1)) {
        loc = j;
        ans += j;
        break;
      }
  }
  cout << ans << endl;
  return 0;
}
