#include <bits/stdc++.h>
using namespace std;
int n;
int arr[100001] = {0};
int sum[100001] = {0};
int main() {
  scanf("%d", &n);
  if (n < 3) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    sum[i] = arr[i];
  }
  for (int i = 1; i < n; i++) {
    sum[i] += sum[i - 1];
  }
  if (sum[n - 1] % 3 != 0) {
    printf("0\n");
    return 0;
  }
  if (sum[n - 1] == 0) {
    long long int zero = 0;
    for (int i = 0; i < n; i++) {
      if (sum[i] == 0) {
        zero++;
      }
    }
    cout << (zero - 1) * (zero - 2) / 2 << endl;
  } else {
    long long int tot = 0, curr = 0;
    for (int i = 0; i < n; i++) {
      if (sum[i] == sum[n - 1] / 3) {
        curr++;
      }
      if (sum[i] == (2 * sum[n - 1]) / 3) {
        tot += curr;
      }
    }
    printf("%d\n", tot);
  }
}
