#include <bits/stdc++.h>
using namespace std;
struct node {
  long long pre[5];
};
node tree[4 * 1000005];
int in[1000005], arr[1000005];
int n, k, i;
long long cnt[5];
void query(int nod, int s, int e, int i, int j) {
  if (s > j || e < i) return;
  if (s >= i && e <= j) {
    for (int i = 1; i <= 3; i++) cnt[i] = cnt[i] + tree[nod].pre[i];
    return;
  }
  int mid = (s + e) / 2, l = 2 * nod, r = l + 1;
  query(l, s, mid, i, j);
  query(r, mid + 1, e, i, j);
}
void update(int nod, int s, int e, int i) {
  if (s > i || e < i) return;
  if (s == e) {
    tree[nod].pre[1] += 1;
    for (int i = 1; i < 3; i++) tree[nod].pre[i + 1] += cnt[i];
    return;
  }
  int mid = (s + e) / 2, l = 2 * nod, r = l + 1;
  update(l, s, mid, i);
  update(r, mid + 1, e, i);
  for (int i = 1; i <= 3; i++)
    tree[nod].pre[i] = tree[l].pre[i] + tree[r].pre[i];
}
int main() {
  scanf("%d", &n);
  int tt = k;
  for (i = 1; i <= n; i++) {
    scanf("%d", &in[i]);
    arr[i] = in[i];
  }
  map<int, int> mp;
  int k = 1;
  sort(arr + 1, arr + n + 1);
  for (i = 1; i <= n; i++) {
    mp[arr[i]] = i;
  }
  for (i = n; i >= 1; i--) {
    memset(cnt, 0, sizeof cnt);
    query(1, 1, n, 1, mp[in[i]] - 1);
    update(1, 1, n, mp[in[i]]);
  }
  printf("%I64d\n", tree[1].pre[3]);
  return 0;
}

### Prompt

Please create a solution in CPP 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;
struct node {
  long long pre[5];
};
node tree[4 * 1000005];
int in[1000005], arr[1000005];
int n, k, i;
long long cnt[5];
void query(int nod, int s, int e, int i, int j) {
  if (s > j || e < i) return;
  if (s >= i && e <= j) {
    for (int i = 1; i <= 3; i++) cnt[i] = cnt[i] + tree[nod].pre[i];
    return;
  }
  int mid = (s + e) / 2, l = 2 * nod, r = l + 1;
  query(l, s, mid, i, j);
  query(r, mid + 1, e, i, j);
}
void update(int nod, int s, int e, int i) {
  if (s > i || e < i) return;
  if (s == e) {
    tree[nod].pre[1] += 1;
    for (int i = 1; i < 3; i++) tree[nod].pre[i + 1] += cnt[i];
    return;
  }
  int mid = (s + e) / 2, l = 2 * nod, r = l + 1;
  update(l, s, mid, i);
  update(r, mid + 1, e, i);
  for (int i = 1; i <= 3; i++)
    tree[nod].pre[i] = tree[l].pre[i] + tree[r].pre[i];
}
int main() {
  scanf("%d", &n);
  int tt = k;
  for (i = 1; i <= n; i++) {
    scanf("%d", &in[i]);
    arr[i] = in[i];
  }
  map<int, int> mp;
  int k = 1;
  sort(arr + 1, arr + n + 1);
  for (i = 1; i <= n; i++) {
    mp[arr[i]] = i;
  }
  for (i = n; i >= 1; i--) {
    memset(cnt, 0, sizeof cnt);
    query(1, 1, n, 1, mp[in[i]] - 1);
    update(1, 1, n, mp[in[i]]);
  }
  printf("%I64d\n", tree[1].pre[3]);
  return 0;
}

```