#include <bits/stdc++.h>
using namespace std;
int n;
vector<long long> t;
void update(long long pos, long long val, long long v = 0, long long l = 0,
            long long r = n) {
  if (l + 1 == r) {
    t[v] += val;
    return;
  }
  long long m = (l + r) / 2;
  if (pos < m)
    update(pos, val, v * 2 + 1, l, m);
  else
    update(pos, val, 2 * v + 2, m, r);
  t[v] = t[v * 2 + 1] + t[2 * v + 2];
}
long long ask(long long askl, long long askr, long long v = 0, long long l = 0,
              long long r = n) {
  if (askr <= l || r <= askl) return 0;
  if (l == askl && r == askr) return t[v];
  long long m = (l + r) / 2, ans = 0;
  if (m > askl) ans += ask(askl, min(m, askr), v * 2 + 1, l, m);
  if (m < askr) ans += ask(max(askl, m), askr, 2 * v + 2, m, r);
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  t.resize(4 * n);
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  for (int i = 0; i < n; i++)
    a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
  vector<long long> inversion(n);
  for (int i = n - 1; i >= 0; --i) {
    inversion[i] = ask(0, a[i]);
    update(a[i], 1);
  }
  fill(t.begin(), t.end(), 0);
  vector<long long> revinversion(n);
  for (int i = 0; i < n; ++i) {
    revinversion[i] = ask(a[i] + 1, n);
    update(a[i], 1);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) ans += inversion[i] * revinversion[i];
  cout << ans;
}

### 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;
int n;
vector<long long> t;
void update(long long pos, long long val, long long v = 0, long long l = 0,
            long long r = n) {
  if (l + 1 == r) {
    t[v] += val;
    return;
  }
  long long m = (l + r) / 2;
  if (pos < m)
    update(pos, val, v * 2 + 1, l, m);
  else
    update(pos, val, 2 * v + 2, m, r);
  t[v] = t[v * 2 + 1] + t[2 * v + 2];
}
long long ask(long long askl, long long askr, long long v = 0, long long l = 0,
              long long r = n) {
  if (askr <= l || r <= askl) return 0;
  if (l == askl && r == askr) return t[v];
  long long m = (l + r) / 2, ans = 0;
  if (m > askl) ans += ask(askl, min(m, askr), v * 2 + 1, l, m);
  if (m < askr) ans += ask(max(askl, m), askr, 2 * v + 2, m, r);
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  t.resize(4 * n);
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  for (int i = 0; i < n; i++)
    a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
  vector<long long> inversion(n);
  for (int i = n - 1; i >= 0; --i) {
    inversion[i] = ask(0, a[i]);
    update(a[i], 1);
  }
  fill(t.begin(), t.end(), 0);
  vector<long long> revinversion(n);
  for (int i = 0; i < n; ++i) {
    revinversion[i] = ask(a[i] + 1, n);
    update(a[i], 1);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) ans += inversion[i] * revinversion[i];
  cout << ans;
}

```