#include <bits/stdc++.h>
using namespace std;
const long long int MAX = 4 * 1e6;
long long int tree[2][MAX] = {{}, {}};
void update(long long int pos, long long int i, long long int j,
            long long int target, long long int t) {
  tree[t][pos]++;
  if (i == j) return;
  if (target <= (i + j) / 2)
    update(2 * pos, i, (i + j) / 2, target, t);
  else
    update(2 * pos + 1, (i + j) / 2 + 1, j, target, t);
}
long long int query(long long int pos, long long int a, long long int b,
                    long long int i, long long int j, long long int t) {
  if (a > j || b < i) return 0;
  if (a >= i && b <= j) {
    return tree[t][pos];
  } else {
    return query(2 * pos, a, (a + b) / 2, i, j, t) +
           query(2 * pos + 1, (a + b) / 2 + 1, b, i, j, t);
  }
}
int32_t main() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int> > cres, dec;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    --x;
    cres.push_back({x, i});
    dec.push_back({x, i});
  }
  sort(cres.begin(), cres.end());
  sort(dec.begin(), dec.end());
  reverse(dec.begin(), dec.end());
  long long int ans = 0;
  vector<long long int> aux1, aux2;
  while (!cres.empty()) {
    pair<long long int, long long int> c = cres.back();
    cres.pop_back();
    aux1.push_back(query(1, 0, n - 1, 0, c.second, 0));
    update(1, 0, n - 1, c.second, 0);
  }
  while (!dec.empty()) {
    pair<long long int, long long int> d = dec.back();
    dec.pop_back();
    aux2.push_back(query(1, 0, n - 1, 0, n - d.second, 1));
    update(1, 0, n - 1, n - d.second, 1);
  }
  reverse(aux2.begin(), aux2.end());
  for (long long int i = 0; i < aux1.size(); i++) {
    ans += aux1[i] * aux2[i];
  }
  cout << ans << '\n';
  return 0;
}

### Prompt

Your task is to create a Cpp solution to the following problem:

The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep". 

Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.

In Shapur's opinion the weakness of an army is equal to the number of triplets i, j, k such that i < j < k and ai > aj > ak where ax is the power of man standing at position x. The Roman army has one special trait — powers of all the people in it are distinct.

Help Shapur find out how weak the Romans are.

Input

The first line of input contains a single number n (3 ≤ n ≤ 106) — the number of men in Roman army. Next line contains n different positive integers ai (1 ≤ i ≤ n, 1 ≤ ai ≤ 109) — powers of men in the Roman army. 

Output

A single integer number, the weakness of the Roman army. 

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

Examples

Input

3
3 2 1


Output

1


Input

3
2 3 1


Output

0


Input

4
10 8 3 1


Output

4


Input

4
1 5 4 3


Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int MAX = 4 * 1e6;
long long int tree[2][MAX] = {{}, {}};
void update(long long int pos, long long int i, long long int j,
            long long int target, long long int t) {
  tree[t][pos]++;
  if (i == j) return;
  if (target <= (i + j) / 2)
    update(2 * pos, i, (i + j) / 2, target, t);
  else
    update(2 * pos + 1, (i + j) / 2 + 1, j, target, t);
}
long long int query(long long int pos, long long int a, long long int b,
                    long long int i, long long int j, long long int t) {
  if (a > j || b < i) return 0;
  if (a >= i && b <= j) {
    return tree[t][pos];
  } else {
    return query(2 * pos, a, (a + b) / 2, i, j, t) +
           query(2 * pos + 1, (a + b) / 2 + 1, b, i, j, t);
  }
}
int32_t main() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int> > cres, dec;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    --x;
    cres.push_back({x, i});
    dec.push_back({x, i});
  }
  sort(cres.begin(), cres.end());
  sort(dec.begin(), dec.end());
  reverse(dec.begin(), dec.end());
  long long int ans = 0;
  vector<long long int> aux1, aux2;
  while (!cres.empty()) {
    pair<long long int, long long int> c = cres.back();
    cres.pop_back();
    aux1.push_back(query(1, 0, n - 1, 0, c.second, 0));
    update(1, 0, n - 1, c.second, 0);
  }
  while (!dec.empty()) {
    pair<long long int, long long int> d = dec.back();
    dec.pop_back();
    aux2.push_back(query(1, 0, n - 1, 0, n - d.second, 1));
    update(1, 0, n - 1, n - d.second, 1);
  }
  reverse(aux2.begin(), aux2.end());
  for (long long int i = 0; i < aux1.size(); i++) {
    ans += aux1[i] * aux2[i];
  }
  cout << ans << '\n';
  return 0;
}

```