#include <bits/stdc++.h>
using namespace std;
struct SegTree {
  int n, *v;
  int t[4 * 1000010];
  int neutral = 0;
  int join(int a, int b) { return (a + b); }
  void build(int node, int i, int j) {
    if (i == j) {
      t[node] = v[i];
    } else {
      int mid = i + (j - i) / 2;
      build((node << 1), i, mid);
      build(((node << 1) + 1), mid + 1, j);
      t[node] = join(t[(node << 1)], t[((node << 1) + 1)]);
    }
  }
  void update(int node, int i, int j, int index, int value) {
    if (i == j) {
      t[node] = v[index] += value;
    } else {
      int mid = i + (j - i) / 2;
      if (index <= mid)
        update((node << 1), i, mid, index, value);
      else
        update(((node << 1) + 1), mid + 1, j, index, value);
      t[node] = join(t[(node << 1)], t[((node << 1) + 1)]);
    }
  }
  int query(int node, int i, int j, int l, int r) {
    if (l <= i && j <= r) return t[node];
    if (i > r || l > j) return neutral;
    int mid = i + (j - i) / 2;
    return join(query((node << 1), i, mid, l, min(r, mid)),
                query(((node << 1) + 1), mid + 1, j, max(l, mid + 1), r));
  }
  void build(int _v[], int _n) {
    n = _n;
    v = _v;
    build(1, 1, n);
  }
  void update(int index, int value) { update(1, 1, n, index, value); }
  int query(int a, int b) { return query(1, 1, n, a, b); }
};
int n, a[1000010], v[1000010], freq[1000010], freq2[1000010];
unordered_map<int, int> mp;
SegTree st1, st2;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    v[i] = a[i];
  }
  sort(v + 1, v + 1 + n);
  int ind = 0;
  for (int i = 1; i <= n; ++i) {
    if (!mp[v[i]]) {
      freq[ind + 1] = 1;
      mp[v[i]] = ++ind;
    } else {
      freq[mp[v[i]]]++;
    }
  }
  st1.build(freq, n);
  st2.build(freq2, n);
  long long int ans = 0;
  for (int i = 1; i <= n; ++i) {
    st1.update(mp[a[i]], -1);
    long long int ret1 = st1.query(1, mp[a[i]] - 1);
    long long int ret2 = st2.query(mp[a[i]] + 1, n);
    ans += ret1 * ret2;
    st2.update(mp[a[i]], 1);
  }
  cout << ans << "\n";
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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 SegTree {
  int n, *v;
  int t[4 * 1000010];
  int neutral = 0;
  int join(int a, int b) { return (a + b); }
  void build(int node, int i, int j) {
    if (i == j) {
      t[node] = v[i];
    } else {
      int mid = i + (j - i) / 2;
      build((node << 1), i, mid);
      build(((node << 1) + 1), mid + 1, j);
      t[node] = join(t[(node << 1)], t[((node << 1) + 1)]);
    }
  }
  void update(int node, int i, int j, int index, int value) {
    if (i == j) {
      t[node] = v[index] += value;
    } else {
      int mid = i + (j - i) / 2;
      if (index <= mid)
        update((node << 1), i, mid, index, value);
      else
        update(((node << 1) + 1), mid + 1, j, index, value);
      t[node] = join(t[(node << 1)], t[((node << 1) + 1)]);
    }
  }
  int query(int node, int i, int j, int l, int r) {
    if (l <= i && j <= r) return t[node];
    if (i > r || l > j) return neutral;
    int mid = i + (j - i) / 2;
    return join(query((node << 1), i, mid, l, min(r, mid)),
                query(((node << 1) + 1), mid + 1, j, max(l, mid + 1), r));
  }
  void build(int _v[], int _n) {
    n = _n;
    v = _v;
    build(1, 1, n);
  }
  void update(int index, int value) { update(1, 1, n, index, value); }
  int query(int a, int b) { return query(1, 1, n, a, b); }
};
int n, a[1000010], v[1000010], freq[1000010], freq2[1000010];
unordered_map<int, int> mp;
SegTree st1, st2;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    v[i] = a[i];
  }
  sort(v + 1, v + 1 + n);
  int ind = 0;
  for (int i = 1; i <= n; ++i) {
    if (!mp[v[i]]) {
      freq[ind + 1] = 1;
      mp[v[i]] = ++ind;
    } else {
      freq[mp[v[i]]]++;
    }
  }
  st1.build(freq, n);
  st2.build(freq2, n);
  long long int ans = 0;
  for (int i = 1; i <= n; ++i) {
    st1.update(mp[a[i]], -1);
    long long int ret1 = st1.query(1, mp[a[i]] - 1);
    long long int ret2 = st2.query(mp[a[i]] + 1, n);
    ans += ret1 * ret2;
    st2.update(mp[a[i]], 1);
  }
  cout << ans << "\n";
  return 0;
}

```