#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
clock_t time_p = clock();
void rtime() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
long long power(long long a, long long b, long long m = mod) {
  long long ans = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) ans = (1ll * a * ans) % m;
    b >>= 1;
    a = (1ll * a * a) % m;
  }
  return ans;
}
int rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
int cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int N = 4000001;
vector<vector<int>> tree(N);
vector<int> a(N);
void build(int i, int s, int e) {
  if (s == e) {
    tree[i].push_back(a[s]);
    return;
  }
  int m = (s + e) / 2;
  build(2 * i + 1, s, m);
  build(2 * i + 2, m + 1, e);
  int it1 = 0, it2 = 0;
  while (it1 < tree[2 * i + 1].size() && it2 < tree[2 * i + 2].size()) {
    if (tree[2 * i + 1][it1] < tree[2 * i + 2][it2]) {
      tree[i].push_back(tree[2 * i + 1][it1]);
      it1++;
    } else {
      tree[i].push_back(tree[2 * i + 2][it2]);
      it2++;
    }
  }
  while (it1 < tree[2 * i + 1].size()) {
    tree[i].push_back(tree[2 * i + 1][it1]);
    it1++;
  }
  while (it2 < tree[2 * i + 2].size()) {
    tree[i].push_back(tree[2 * i + 2][it2]);
    it2++;
  }
}
int find(int i, int s, int e, int l, int r, int x) {
  if (l > e || s > r) return 0;
  if (l <= s && e <= r) {
    auto it = upper_bound(tree[i].begin(), tree[i].end(), x);
    return (int)(tree[i].end() - it);
  }
  int m = (s + e) / 2;
  return find(2 * i + 1, s, m, l, r, x) + find(2 * i + 2, m + 1, e, l, r, x);
}
int find2(int i, int s, int e, int l, int r, int x) {
  if (l > e || s > r) return 0;
  if (l <= s && e <= r) {
    auto it = lower_bound(tree[i].begin(), tree[i].end(), x);
    return (int)(it - tree[i].begin());
  }
  int m = (s + e) / 2;
  return find2(2 * i + 1, s, m, l, r, x) + find2(2 * i + 2, m + 1, e, l, r, x);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    build(0, 0, n - 1);
    long long ans = 0;
    for (int i = 1; i < n - 1; i++) {
      ans += 1ll * find(0, 0, n - 1, 0, i - 1, a[i]) *
             find2(0, 0, n - 1, i + 1, n - 1, a[i]);
    }
    cout << ans;
  }
  rtime();
  return 0;
}

### Prompt

Generate 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 int mod = 1e9 + 7;
clock_t time_p = clock();
void rtime() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
long long power(long long a, long long b, long long m = mod) {
  long long ans = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) ans = (1ll * a * ans) % m;
    b >>= 1;
    a = (1ll * a * a) % m;
  }
  return ans;
}
int rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
int cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int N = 4000001;
vector<vector<int>> tree(N);
vector<int> a(N);
void build(int i, int s, int e) {
  if (s == e) {
    tree[i].push_back(a[s]);
    return;
  }
  int m = (s + e) / 2;
  build(2 * i + 1, s, m);
  build(2 * i + 2, m + 1, e);
  int it1 = 0, it2 = 0;
  while (it1 < tree[2 * i + 1].size() && it2 < tree[2 * i + 2].size()) {
    if (tree[2 * i + 1][it1] < tree[2 * i + 2][it2]) {
      tree[i].push_back(tree[2 * i + 1][it1]);
      it1++;
    } else {
      tree[i].push_back(tree[2 * i + 2][it2]);
      it2++;
    }
  }
  while (it1 < tree[2 * i + 1].size()) {
    tree[i].push_back(tree[2 * i + 1][it1]);
    it1++;
  }
  while (it2 < tree[2 * i + 2].size()) {
    tree[i].push_back(tree[2 * i + 2][it2]);
    it2++;
  }
}
int find(int i, int s, int e, int l, int r, int x) {
  if (l > e || s > r) return 0;
  if (l <= s && e <= r) {
    auto it = upper_bound(tree[i].begin(), tree[i].end(), x);
    return (int)(tree[i].end() - it);
  }
  int m = (s + e) / 2;
  return find(2 * i + 1, s, m, l, r, x) + find(2 * i + 2, m + 1, e, l, r, x);
}
int find2(int i, int s, int e, int l, int r, int x) {
  if (l > e || s > r) return 0;
  if (l <= s && e <= r) {
    auto it = lower_bound(tree[i].begin(), tree[i].end(), x);
    return (int)(it - tree[i].begin());
  }
  int m = (s + e) / 2;
  return find2(2 * i + 1, s, m, l, r, x) + find2(2 * i + 2, m + 1, e, l, r, x);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    build(0, 0, n - 1);
    long long ans = 0;
    for (int i = 1; i < n - 1; i++) {
      ans += 1ll * find(0, 0, n - 1, 0, i - 1, a[i]) *
             find2(0, 0, n - 1, i + 1, n - 1, a[i]);
    }
    cout << ans;
  }
  rtime();
  return 0;
}

```