#include <bits/stdc++.h>
int main() {
  int i, j, contador, c = 0, now = 0, n, sum = 0;
  long long int resp = 0;
  scanf("%d", &n);
  long long int vec[n + 1], vec2[n + 1];
  memset(vec, 0, sizeof(vec));
  memset(vec2, 0, sizeof(vec2));
  for (i = 1; i <= n; i++) {
    scanf("%d", &vec[i]);
    sum += vec[i];
  }
  for (i = 1; i <= n; i++) {
    now += vec[i];
    vec2[i] = vec2[i - 1] + (now * 3 == sum);
  }
  now = 0;
  for (i = n; i > 2; i--) {
    now += vec[i];
    if (now * 3 == sum) resp += vec2[i - 2];
  }
  printf("%I64d", resp);
  return 0;
}
