#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  size_t n;
  std::cin >> n;
  std::vector<int32_t> a(n);
  int32_t sum = 0;
  for (size_t i = 0; i < n; ++i) {
    std::cin >> a[i];
    sum += a[i];
  }
  if (sum % 3 != 0) {
    std::cout << "0\n";
    return 0;
  }
  const int32_t third = sum / 3;
  const int32_t two_thirds = third * 2;
  int64_t count = 0;
  int32_t cur = 0;
  int64_t result = 0;
  for (size_t i = 0; i + 1 < n; ++i) {
    cur += a[i];
    if (cur == two_thirds) {
      result += count;
    }
    if (cur == third) {
      count += 1;
    }
  }
  std::cout << result << '\n';
}
