#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e6 + 5;
int v[nmax], s[nmax], gr[nmax], arb[4 * nmax + 5], le[nmax], arb2[4 * nmax + 5],
    lazy[4 * nmax + 5], lazy2[4 * nmax + 5];
int a, n;
inline void pushdown(int node, int st, int dr) {
  if (st == dr) return;
  if (lazy[node]) {
    int med = ((dr - st) >> 1) + st;
    lazy[node << 1] += lazy[node];
    lazy[node << 1 | 1] += lazy[node];
    arb[node << 1] += lazy[node] * (med - st + 1);
    arb[node << 1 | 1] += lazy[node] * (dr - med);
    lazy[node] = 0;
  }
}
inline void update(int node, int st, int dr) {
  if (1 <= st && dr <= a) {
    arb[node] += dr - st + 1;
    lazy[node]++;
    return;
  }
  pushdown(node, st, dr);
  int med = ((dr - st) >> 1) + st;
  if (a >= st) update(node << 1, st, med);
  if (a > med) update(node << 1 | 1, med + 1, dr);
  arb[node] = arb[node << 1] + arb[node << 1 | 1];
}
inline int query(int node, int st, int dr) {
  if (st == dr) return arb[node];
  pushdown(node, st, dr);
  int med = ((dr - st) >> 1) + st;
  if (a > med) return query(node << 1 | 1, med + 1, dr);
  return query(node << 1, st, med);
}
inline void pushdown2(int node, int st, int dr) {
  if (st == dr) return;
  if (lazy2[node]) {
    int med = ((dr - st) >> 1) + st;
    lazy2[node << 1] += lazy2[node];
    lazy2[node << 1 | 1] += lazy2[node];
    arb2[node << 1] += lazy2[node] * (med - st + 1);
    arb2[node << 1 | 1] += lazy2[node] * (dr - med);
    lazy2[node] = 0;
  }
}
inline void update2(int node, int st, int dr) {
  if (a <= st && dr <= n) {
    arb2[node] += dr - st + 1;
    lazy2[node]++;
    return;
  }
  pushdown2(node, st, dr);
  int med = ((dr - st) >> 1) + st;
  if (a <= dr) update2(node << 1 | 1, med + 1, dr);
  if (a <= med) update2(node << 1, st, med);
  arb2[node] = arb2[node << 1] + arb2[node << 1 | 1];
}
inline int query2(int node, int st, int dr) {
  if (st == dr) return arb2[node];
  pushdown2(node, st, dr);
  int med = ((dr - st) >> 1) + st;
  if (a > med)
    return query2(node << 1 | 1, med + 1, dr);
  else
    return query2(node << 1, st, med);
}
int main() {
  map<int, int> m;
  int cnt = 0, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n && scanf("%d", &v[i]); ++i) s[i] = v[i];
  sort(s + 1, s + n + 1);
  for (i = 1; i <= n; ++i) m[s[i]] = ++cnt;
  for (i = 1; i <= n; ++i) v[i] = m[v[i]];
  for (i = 1; i <= n; ++i) {
    a = v[i] - 1;
    update(1, 1, n);
    a++;
    gr[i] = query(1, 1, n);
  }
  for (i = n; i; --i) {
    a = v[i] + 1;
    if (a <= n) update2(1, 1, n);
    a--;
    le[i] = query2(1, 1, n);
  }
  long long sum = 0;
  for (i = 1; i <= n; ++i) sum += 1LL * gr[i] * le[i];
  printf("%I64d", sum);
}

### Prompt

Develop a solution in Cpp to the problem described below:

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 nmax = 1e6 + 5;
int v[nmax], s[nmax], gr[nmax], arb[4 * nmax + 5], le[nmax], arb2[4 * nmax + 5],
    lazy[4 * nmax + 5], lazy2[4 * nmax + 5];
int a, n;
inline void pushdown(int node, int st, int dr) {
  if (st == dr) return;
  if (lazy[node]) {
    int med = ((dr - st) >> 1) + st;
    lazy[node << 1] += lazy[node];
    lazy[node << 1 | 1] += lazy[node];
    arb[node << 1] += lazy[node] * (med - st + 1);
    arb[node << 1 | 1] += lazy[node] * (dr - med);
    lazy[node] = 0;
  }
}
inline void update(int node, int st, int dr) {
  if (1 <= st && dr <= a) {
    arb[node] += dr - st + 1;
    lazy[node]++;
    return;
  }
  pushdown(node, st, dr);
  int med = ((dr - st) >> 1) + st;
  if (a >= st) update(node << 1, st, med);
  if (a > med) update(node << 1 | 1, med + 1, dr);
  arb[node] = arb[node << 1] + arb[node << 1 | 1];
}
inline int query(int node, int st, int dr) {
  if (st == dr) return arb[node];
  pushdown(node, st, dr);
  int med = ((dr - st) >> 1) + st;
  if (a > med) return query(node << 1 | 1, med + 1, dr);
  return query(node << 1, st, med);
}
inline void pushdown2(int node, int st, int dr) {
  if (st == dr) return;
  if (lazy2[node]) {
    int med = ((dr - st) >> 1) + st;
    lazy2[node << 1] += lazy2[node];
    lazy2[node << 1 | 1] += lazy2[node];
    arb2[node << 1] += lazy2[node] * (med - st + 1);
    arb2[node << 1 | 1] += lazy2[node] * (dr - med);
    lazy2[node] = 0;
  }
}
inline void update2(int node, int st, int dr) {
  if (a <= st && dr <= n) {
    arb2[node] += dr - st + 1;
    lazy2[node]++;
    return;
  }
  pushdown2(node, st, dr);
  int med = ((dr - st) >> 1) + st;
  if (a <= dr) update2(node << 1 | 1, med + 1, dr);
  if (a <= med) update2(node << 1, st, med);
  arb2[node] = arb2[node << 1] + arb2[node << 1 | 1];
}
inline int query2(int node, int st, int dr) {
  if (st == dr) return arb2[node];
  pushdown2(node, st, dr);
  int med = ((dr - st) >> 1) + st;
  if (a > med)
    return query2(node << 1 | 1, med + 1, dr);
  else
    return query2(node << 1, st, med);
}
int main() {
  map<int, int> m;
  int cnt = 0, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n && scanf("%d", &v[i]); ++i) s[i] = v[i];
  sort(s + 1, s + n + 1);
  for (i = 1; i <= n; ++i) m[s[i]] = ++cnt;
  for (i = 1; i <= n; ++i) v[i] = m[v[i]];
  for (i = 1; i <= n; ++i) {
    a = v[i] - 1;
    update(1, 1, n);
    a++;
    gr[i] = query(1, 1, n);
  }
  for (i = n; i; --i) {
    a = v[i] + 1;
    if (a <= n) update2(1, 1, n);
    a--;
    le[i] = query2(1, 1, n);
  }
  long long sum = 0;
  for (i = 1; i <= n; ++i) sum += 1LL * gr[i] * le[i];
  printf("%I64d", sum);
}

```