#include <bits/stdc++.h>
using namespace std;
const long long int N = 500009;
const long long int mod = 1000000007;
vector<long long int> bit;
struct Query {
  long long int l, r, x, idx;
};
struct ArrayElement {
  long long int val, idx;
};
bool cmp1(Query q1, Query q2) { return q1.x < q2.x; }
bool cmp2(ArrayElement x, ArrayElement y) { return x.val < y.val; }
void update(vector<long long int> &bit, long long int idx, long long int val,
            long long int n) {
  for (; idx <= n; idx += idx & -idx) bit[idx] += val;
}
long long int query(vector<long long int> &bit, long long int idx,
                    long long int n) {
  long long int sum = 0;
  for (; idx > 0; idx -= idx & -idx) sum += bit[idx];
  return sum;
}
void answerQueries(vector<long long int> &ans, vector<Query> &queries,
                   vector<ArrayElement> &arr) {
  long long int n = (long long int)((arr).size());
  long long int q = (long long int)((queries).size());
  bit.assign(n + 1, 0);
  sort(arr.begin(), arr.end(), cmp2);
  sort(queries.begin(), queries.end(), cmp1);
  long long int curr = 0;
  ans.resize(q);
  for (long long int i = 0; i < q; i++) {
    while (arr[curr].val <= queries[i].x && curr < n) {
      update(bit, arr[curr].idx + 1, 1, n);
      curr++;
    }
    ans[queries[i].idx] =
        query(bit, queries[i].r + 1, n) - query(bit, queries[i].l, n);
  }
}
long long int n;
vector<ArrayElement> a;
vector<ArrayElement> b;
vector<Query> q1;
vector<Query> q2;
vector<long long int> ans1, ans2;
void pre() {}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  pre();
  cin >> n;
  a.resize(n);
  b = a;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i].val;
    a[i].idx = i;
    b[i].val = -a[i].val;
    b[i].idx = i;
  }
  q1.resize(n - 2);
  ans1.assign(n - 2, 0);
  ans2 = ans1;
  q2 = q1;
  for (long long int i = 1; i < (n - 1); i++) {
    q1[i - 1].l = 0;
    q1[i - 1].r = i - 1;
    q1[i - 1].x = -a[i].val - 1;
    q1[i - 1].idx = i - 1;
  }
  answerQueries(ans1, q1, b);
  for (long long int i = 1; i < (n - 1); i++) {
    q2[i - 1].l = i + 1;
    q2[i - 1].r = n - 1;
    q2[i - 1].x = a[i].val - 1;
    q2[i - 1].idx = i - 1;
  }
  answerQueries(ans2, q2, a);
  long long int ANS = 0;
  for (long long int i = 0; i < (n - 2); i++) {
    ANS += (ans1[i] * ans2[i]);
  }
  cout << ANS << "\n";
  return 0;
}

### Prompt

In cpp, your task is to solve 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 N = 500009;
const long long int mod = 1000000007;
vector<long long int> bit;
struct Query {
  long long int l, r, x, idx;
};
struct ArrayElement {
  long long int val, idx;
};
bool cmp1(Query q1, Query q2) { return q1.x < q2.x; }
bool cmp2(ArrayElement x, ArrayElement y) { return x.val < y.val; }
void update(vector<long long int> &bit, long long int idx, long long int val,
            long long int n) {
  for (; idx <= n; idx += idx & -idx) bit[idx] += val;
}
long long int query(vector<long long int> &bit, long long int idx,
                    long long int n) {
  long long int sum = 0;
  for (; idx > 0; idx -= idx & -idx) sum += bit[idx];
  return sum;
}
void answerQueries(vector<long long int> &ans, vector<Query> &queries,
                   vector<ArrayElement> &arr) {
  long long int n = (long long int)((arr).size());
  long long int q = (long long int)((queries).size());
  bit.assign(n + 1, 0);
  sort(arr.begin(), arr.end(), cmp2);
  sort(queries.begin(), queries.end(), cmp1);
  long long int curr = 0;
  ans.resize(q);
  for (long long int i = 0; i < q; i++) {
    while (arr[curr].val <= queries[i].x && curr < n) {
      update(bit, arr[curr].idx + 1, 1, n);
      curr++;
    }
    ans[queries[i].idx] =
        query(bit, queries[i].r + 1, n) - query(bit, queries[i].l, n);
  }
}
long long int n;
vector<ArrayElement> a;
vector<ArrayElement> b;
vector<Query> q1;
vector<Query> q2;
vector<long long int> ans1, ans2;
void pre() {}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  pre();
  cin >> n;
  a.resize(n);
  b = a;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i].val;
    a[i].idx = i;
    b[i].val = -a[i].val;
    b[i].idx = i;
  }
  q1.resize(n - 2);
  ans1.assign(n - 2, 0);
  ans2 = ans1;
  q2 = q1;
  for (long long int i = 1; i < (n - 1); i++) {
    q1[i - 1].l = 0;
    q1[i - 1].r = i - 1;
    q1[i - 1].x = -a[i].val - 1;
    q1[i - 1].idx = i - 1;
  }
  answerQueries(ans1, q1, b);
  for (long long int i = 1; i < (n - 1); i++) {
    q2[i - 1].l = i + 1;
    q2[i - 1].r = n - 1;
    q2[i - 1].x = a[i].val - 1;
    q2[i - 1].idx = i - 1;
  }
  answerQueries(ans2, q2, a);
  long long int ANS = 0;
  for (long long int i = 0; i < (n - 2); i++) {
    ANS += (ans1[i] * ans2[i]);
  }
  cout << ANS << "\n";
  return 0;
}

```