#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
pair<long long, long long> subArraylen(long long arr[], long long n,
                                       long long K) {
  unordered_map<long long, long long> mp;
  mp[arr[0]] = 0;
  for (long long i = 1; i < n; i++) {
    arr[i] = arr[i] + arr[i - 1];
    mp[arr[i]] = i;
  }
  long long len = INT_MAX;
  for (long long i = 0; i < n; i++) {
    if (arr[i] < K)
      continue;
    else {
      long long x = arr[i] - K;
      if (x == 0) len = min(len, i);
      if (mp.find(x) == mp.end())
        continue;
      else {
        len = min(len, i - mp[x]);
      }
    }
  }
}
long long solve() {
  long long n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum % 3 != 0 || n < 3) return 0;
  sum /= 3;
  long long lsum = sum, rsum = lsum * 2;
  sum = 0;
  long long cnt = 0, ans = 0;
  for (long long i = 0; i < n - 1; i++) {
    sum += a[i];
    if (sum == rsum) ans += cnt;
    if (sum == lsum) cnt++;
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << solve();
  return 0;
}

### Prompt

Create a solution in cpp for the following problem:

Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?

Input

The first input line contains integer n (1 ≤ n ≤ 105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.

Output

Output the amount of ways to cut the stripe into three non-empty pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.

Examples

Input

4
1 2 3 3


Output

1


Input

5
1 2 3 4 5


Output

0

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
pair<long long, long long> subArraylen(long long arr[], long long n,
                                       long long K) {
  unordered_map<long long, long long> mp;
  mp[arr[0]] = 0;
  for (long long i = 1; i < n; i++) {
    arr[i] = arr[i] + arr[i - 1];
    mp[arr[i]] = i;
  }
  long long len = INT_MAX;
  for (long long i = 0; i < n; i++) {
    if (arr[i] < K)
      continue;
    else {
      long long x = arr[i] - K;
      if (x == 0) len = min(len, i);
      if (mp.find(x) == mp.end())
        continue;
      else {
        len = min(len, i - mp[x]);
      }
    }
  }
}
long long solve() {
  long long n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum % 3 != 0 || n < 3) return 0;
  sum /= 3;
  long long lsum = sum, rsum = lsum * 2;
  sum = 0;
  long long cnt = 0, ans = 0;
  for (long long i = 0; i < n - 1; i++) {
    sum += a[i];
    if (sum == rsum) ans += cnt;
    if (sum == lsum) cnt++;
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << solve();
  return 0;
}

```