#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T ABS(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T MIN(T a, T b) {
  return a < b ? a : b;
}
template <typename T>
inline T MAX(T a, T b) {
  return a > b ? a : b;
}
template <typename T>
inline T CHKMIN(T &a, T b) {
  if (a > b) a = b;
  return a;
}
template <typename T>
inline T CHKMAX(T &a, T b) {
  if (a < b) a = b;
  return a;
}
template <typename T>
inline void SWAP(T &a, T &b) {
  static T c;
  c = a;
  a = b;
  b = c;
}
template <typename T, typename... T0>
T MAX(T a, T b, T0... c) {
  return a > b ? MAX(a, c...) : MAX(b, c...);
}
template <typename T, typename... T0>
T MIN(T a, T b, T0... c) {
  return a < b ? MIN(a, c...) : MIN(b, c...);
}
template <typename T, int n>
void myin(T a[]) {
  for (int i = (0); i < (int)(n); ++i) cin >> a[i];
}
template <typename T>
void myin(T &a) {
  cin >> a;
}
template <typename T>
void print(T a) {
  cout << a << ' ';
}
template <typename T, typename... T0>
void print(T a, T0... b) {
  print(a);
  print(b...);
}
template <typename T>
void println(T a) {
  cout << a << endl;
}
template <typename T, typename... T0>
void println(T a, T0... b) {
  print(a);
  println(b...);
}
int n, in[120000];
long long dp[120000];
int main() {
  long long sum = 0;
  while (cin >> n) {
    for (int i = (0); i < (int)(n); ++i) {
      scanf("%d", in + i);
      sum += in[i];
    }
    if (sum % 3 != 0) {
      puts("0");
      continue;
    }
    long long tmp = sum / 3, now = 0, ans = 0;
    for (int i = (0); i < (int)(n); ++i) {
      now += in[i];
      if (i == 0)
        dp[i] = 0;
      else
        dp[i] = dp[i - 1];
      if (now == tmp) ++dp[i];
    }
    tmp += tmp, now = in[0];
    for (int i = (1); i < (int)(n - 1); ++i) {
      now += in[i];
      if (now == tmp) ans += dp[i - 1];
    }
    println(ans);
  }
  return 0;
}
