#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<long long, long long>& a,
         const pair<long long, long long>& b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
long long q = 1;
vector<long long> tree;
vector<long long> is;
void ins(long long x, long long y) {
  tree[x] = y;
  x /= 2;
  while (x != 0) {
    tree[x] = tree[2 * x] + tree[2 * x + 1];
    x /= 2;
  }
}
long long get_sum(long long v, long long tl, long long tr, long long l,
                  long long r) {
  if (l > r) return 0;
  if (l == tl && r == tr) return tree[v];
  long long tm = (tl + tr) / 2;
  return get_sum(v * 2, tl, tm, l, min(r, tm)) +
         get_sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
}
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n), b(n, -1);
  vector<pair<long long, long long> > tmp(n);
  is.resize(n);
  long long m = n;
  while (m != 0) {
    m /= 2;
    q *= 2;
  }
  if (q / 2 == n) q = n;
  tree.assign(q * 2, 0);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    tmp[i].first = a[i];
    tmp[i].second = i;
  }
  sort(tmp.begin(), tmp.end(), cmp);
  for (long long i = 0; i < n; i++) is[tmp[i].second] = i;
  vector<long long> h(n);
  ins(q + is[n - 1], 1);
  for (long long i = n - 2; i >= 0; i--) {
    long long s = get_sum(1, 0, q - 1, 0, is[i]);
    ins(q + is[i], 1);
    h[i] = s;
  }
  tree.assign(q * 2, 0);
  ins(q + is[n - 2], h[n - 2]);
  long long inv = 0;
  for (long long i = n - 3; i >= 0; i--) {
    long long s = get_sum(1, 0, q - 1, 0, is[i]);
    ins(q + is[i], h[i]);
    inv += s;
  }
  cout << inv;
  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;
bool cmp(const pair<long long, long long>& a,
         const pair<long long, long long>& b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
long long q = 1;
vector<long long> tree;
vector<long long> is;
void ins(long long x, long long y) {
  tree[x] = y;
  x /= 2;
  while (x != 0) {
    tree[x] = tree[2 * x] + tree[2 * x + 1];
    x /= 2;
  }
}
long long get_sum(long long v, long long tl, long long tr, long long l,
                  long long r) {
  if (l > r) return 0;
  if (l == tl && r == tr) return tree[v];
  long long tm = (tl + tr) / 2;
  return get_sum(v * 2, tl, tm, l, min(r, tm)) +
         get_sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
}
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n), b(n, -1);
  vector<pair<long long, long long> > tmp(n);
  is.resize(n);
  long long m = n;
  while (m != 0) {
    m /= 2;
    q *= 2;
  }
  if (q / 2 == n) q = n;
  tree.assign(q * 2, 0);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    tmp[i].first = a[i];
    tmp[i].second = i;
  }
  sort(tmp.begin(), tmp.end(), cmp);
  for (long long i = 0; i < n; i++) is[tmp[i].second] = i;
  vector<long long> h(n);
  ins(q + is[n - 1], 1);
  for (long long i = n - 2; i >= 0; i--) {
    long long s = get_sum(1, 0, q - 1, 0, is[i]);
    ins(q + is[i], 1);
    h[i] = s;
  }
  tree.assign(q * 2, 0);
  ins(q + is[n - 2], h[n - 2]);
  long long inv = 0;
  for (long long i = n - 3; i >= 0; i--) {
    long long s = get_sum(1, 0, q - 1, 0, is[i]);
    ins(q + is[i], h[i]);
    inv += s;
  }
  cout << inv;
  return 0;
}

```