#include <bits/stdc++.h>
using namespace std;
struct item {};
const int inf = 1000 * 1000 * 1000;
const int MAX_N = 101000;
int A[MAX_N], D[MAX_N];
vector<long long> S1, S2;
int n;
int main() {
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    sum += A[i];
    S1.push_back(sum);
  }
  sum = 0;
  for (int i = n - 1; i >= 0; i--) {
    sum += A[i];
    S2.push_back(sum);
  }
  if (sum % 3 != 0) {
    cout << 0;
    return 0;
  }
  sum /= 3;
  int c1 = 0, c2 = 0;
  int sum1 = 0;
  for (int i = 0; i < n; i++) {
    if (S1[i] == sum) sum1++;
    D[i] = sum1;
  }
  long long res = 0;
  for (int i = 0; i <= n - 3; i++) {
    if (S2[i] == sum) res += D[n - 3 - i];
  }
  cout << res;
  return 0;
}
