#include <bits/stdc++.h>
long long ans, s, ss;
int n, f[211111], a[211111], col1;
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  if (s % 3)
    puts("0");
  else {
    s /= 3;
    ss = 0;
    for (int i = n - 1; i >= 0; i--) {
      ss += a[i];
      if (ss == s + s)
        f[i] = col1;
      else
        f[i] = 0;
      if (ss == s) col1++;
    }
    ss = 0;
    for (int i = 0; i < n; i++) {
      ss += a[i];
      if (ss == s) ans += f[i + 1];
    }
    printf("%I64lld\n", ans);
  }
  return 0;
}
