#include <bits/stdc++.h>
using namespace std;
int dX[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dY[] = {0, 1, 0, -1, 1, 1, -1, -1};
long long int n;
vector<long long int> A;
vector<long long int> mapped;
long long int lft[10 * 100007];
long long int ryt[10 * 100007];
vector<pair<long long int, long long int> > aux;
struct tree {
  long long int sum;
};
tree seg[5000001];
void build(long long int node, long long int i, long long int j) {
  if (i > j) return;
  if (i == j) {
    seg[node].sum = 0;
    return;
  }
  build(node * 2, i, (i + j) / 2);
  build(node * 2 + 1, 1 + (i + j) / 2, j);
  seg[node].sum = 0;
  return;
}
long long int qsum(long long int node, long long int a, long long int b,
                   long long int i, long long int j) {
  if (a > b || a > j || b < i) return 0;
  if (a >= i && b <= j) return seg[node].sum;
  long long int q1, q2;
  q1 = qsum(node * 2, a, (a + b) / 2, i, j);
  q2 = qsum(1 + node * 2, 1 + (a + b) / 2, b, i, j);
  long long int res = q1 + q2;
  return res;
}
void upd(long long int node, long long int pos, long long int i,
         long long int j, long long int val) {
  if (i > j) return;
  if (i == j && i == pos) {
    seg[node].sum = val;
    return;
  }
  if (i <= pos && j >= pos) {
    upd(2 * node, pos, i, (i + j) / 2, val);
    upd(2 * node + 1, pos, (i + j) / 2 + 1, j, val);
    seg[node].sum = seg[2 * node].sum + seg[1 + 2 * node].sum;
    return;
  }
}
void compress(vector<long long int> &source, vector<long long int> &target) {
  target = source;
  vector<pair<int, int> > tmp;
  for (long long int i = 0; i < source.size(); ++i) {
    tmp.push_back(make_pair(source[i], i));
  }
  sort(tmp.begin(), tmp.end());
  long long int lastGivenLabel = 1;
  long long int lastNum = tmp[0].first;
  target[tmp[0].second] = 1;
  for (long long int i = 1; i < tmp.size(); ++i) {
    if (tmp[i].first == lastNum) {
      target[tmp[i].second] = lastGivenLabel;
    } else {
      target[tmp[i].second] = lastGivenLabel + 1;
      lastGivenLabel = target[tmp[i].second];
      lastNum = tmp[i].first;
    }
  }
  return;
}
void onemore(vector<long long int> &source, vector<long long int> &target) {
  vector<long long int> tmp = source;
  sort(tmp.begin(), tmp.end());
  for (int i = 0; i < source.size(); ++i) {
    long long int label =
        (lower_bound(tmp.begin(), tmp.end(), source[i]) - tmp.begin());
    target.push_back(label);
  }
  return;
}
bool cmp(pair<long long int, long long int> l,
         pair<long long int, long long int> r) {
  return l.first > r.first;
}
int main() {
  long long int tmp;
  scanf("%I64d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", &tmp);
    A.push_back(tmp);
  }
  onemore(A, mapped);
  for (int i = 0; i < A.size(); i++) {
    aux.push_back(make_pair(A[i], i));
  }
  sort(aux.begin(), aux.end(), cmp);
  build(1, 1, n);
  for (int i = 0; i < aux.size(); i++) {
    lft[aux[i].second] = qsum(1, 1, n, 1, aux[i].second);
    upd(1, aux[i].second + 1, 1, n, 1);
  }
  sort(aux.begin(), aux.end());
  build(1, 1, n);
  for (int i = 0; i < aux.size(); i++) {
    ryt[aux[i].second] = qsum(1, 1, n, aux[i].second + 2, n);
    upd(1, aux[i].second + 1, 1, n, 1);
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += lft[i] * ryt[i];
  }
  printf("%I64d\n", ans);
  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;
int dX[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dY[] = {0, 1, 0, -1, 1, 1, -1, -1};
long long int n;
vector<long long int> A;
vector<long long int> mapped;
long long int lft[10 * 100007];
long long int ryt[10 * 100007];
vector<pair<long long int, long long int> > aux;
struct tree {
  long long int sum;
};
tree seg[5000001];
void build(long long int node, long long int i, long long int j) {
  if (i > j) return;
  if (i == j) {
    seg[node].sum = 0;
    return;
  }
  build(node * 2, i, (i + j) / 2);
  build(node * 2 + 1, 1 + (i + j) / 2, j);
  seg[node].sum = 0;
  return;
}
long long int qsum(long long int node, long long int a, long long int b,
                   long long int i, long long int j) {
  if (a > b || a > j || b < i) return 0;
  if (a >= i && b <= j) return seg[node].sum;
  long long int q1, q2;
  q1 = qsum(node * 2, a, (a + b) / 2, i, j);
  q2 = qsum(1 + node * 2, 1 + (a + b) / 2, b, i, j);
  long long int res = q1 + q2;
  return res;
}
void upd(long long int node, long long int pos, long long int i,
         long long int j, long long int val) {
  if (i > j) return;
  if (i == j && i == pos) {
    seg[node].sum = val;
    return;
  }
  if (i <= pos && j >= pos) {
    upd(2 * node, pos, i, (i + j) / 2, val);
    upd(2 * node + 1, pos, (i + j) / 2 + 1, j, val);
    seg[node].sum = seg[2 * node].sum + seg[1 + 2 * node].sum;
    return;
  }
}
void compress(vector<long long int> &source, vector<long long int> &target) {
  target = source;
  vector<pair<int, int> > tmp;
  for (long long int i = 0; i < source.size(); ++i) {
    tmp.push_back(make_pair(source[i], i));
  }
  sort(tmp.begin(), tmp.end());
  long long int lastGivenLabel = 1;
  long long int lastNum = tmp[0].first;
  target[tmp[0].second] = 1;
  for (long long int i = 1; i < tmp.size(); ++i) {
    if (tmp[i].first == lastNum) {
      target[tmp[i].second] = lastGivenLabel;
    } else {
      target[tmp[i].second] = lastGivenLabel + 1;
      lastGivenLabel = target[tmp[i].second];
      lastNum = tmp[i].first;
    }
  }
  return;
}
void onemore(vector<long long int> &source, vector<long long int> &target) {
  vector<long long int> tmp = source;
  sort(tmp.begin(), tmp.end());
  for (int i = 0; i < source.size(); ++i) {
    long long int label =
        (lower_bound(tmp.begin(), tmp.end(), source[i]) - tmp.begin());
    target.push_back(label);
  }
  return;
}
bool cmp(pair<long long int, long long int> l,
         pair<long long int, long long int> r) {
  return l.first > r.first;
}
int main() {
  long long int tmp;
  scanf("%I64d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", &tmp);
    A.push_back(tmp);
  }
  onemore(A, mapped);
  for (int i = 0; i < A.size(); i++) {
    aux.push_back(make_pair(A[i], i));
  }
  sort(aux.begin(), aux.end(), cmp);
  build(1, 1, n);
  for (int i = 0; i < aux.size(); i++) {
    lft[aux[i].second] = qsum(1, 1, n, 1, aux[i].second);
    upd(1, aux[i].second + 1, 1, n, 1);
  }
  sort(aux.begin(), aux.end());
  build(1, 1, n);
  for (int i = 0; i < aux.size(); i++) {
    ryt[aux[i].second] = qsum(1, 1, n, aux[i].second + 2, n);
    upd(1, aux[i].second + 1, 1, n, 1);
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += lft[i] * ryt[i];
  }
  printf("%I64d\n", ans);
  return 0;
}

```