#include <bits/stdc++.h>
using namespace std;
class SegmentTree {
 public:
  SegmentTree(std::vector<long long>& inputArray) {
    n = inputArray.size();
    N = 1;
    while (N < n) N <<= 1;
    _treeArray = std::vector<long long>(N, 0);
    _endpoints = std::vector<std::pair<long, long>>(2 * N);
    _treeArray.insert(_treeArray.end(), inputArray.begin(), inputArray.end());
    _treeArray.resize(2 * N, 0);
    for (auto i = N; i < 2 * N; ++i) {
      _endpoints[i] = {i - N, i - N + 1};
    }
    for (auto i = N - 1; i > 0; --i) {
      _treeArray[i] = _treeArray[i << 1] + _treeArray[(i << 1) | 1];
      _endpoints[i] = {_endpoints[i << 1].first,
                       _endpoints[(i << 1) | 1].second};
    }
  }
  long long query(long i, long j) {
    if (i < 0 || j > n) {
      std::cout << "query: " << i << "," << j
                << " out of range for array with indices " << 0 << "," << n
                << std::endl;
      return -1;
    }
    return recursiveQuery(1, i, j);
  }
  void reveal() {
    std::cout << "underlying array:  ";
    for (auto& x : _treeArray) std::cout << x << " ";
    std::cout << std::endl;
  }
  void increment(long i, long long addend) {
    if (i < 0 || i >= n) {
      std::cout << "increment at index: " << i
                << " out of range for array with indices " << 0 << "," << n
                << std::endl;
      return;
    }
    recursiveIncrement(1, i, addend);
  }
  void update(long i, long long newValue) {
    if (i < 0 || i >= n) {
      std::cout << "index: " << i << " out of range for array with indices "
                << 0 << "," << n << std::endl;
      return;
    }
    recursiveUpdate(1, i, newValue);
  }

 private:
  long n;
  long N;
  std::vector<long long> _treeArray;
  long long nil = 0;
  std::vector<std::pair<long, long>> _endpoints;
  long long recursiveUpdate(long node, long i, long newValue) {
    long left, right;
    std::tie(left, right) = _endpoints[node];
    if (left == i && right == i + 1) {
      _treeArray[node] = newValue;
      return newValue;
    }
    if (i < left || i >= right) {
      return _treeArray[node];
    }
    auto leftChildNode = (node << 1), rightChildNode = ((node << 1) | 1);
    auto newChildrenSum = recursiveUpdate(leftChildNode, i, newValue) +
                          recursiveUpdate(rightChildNode, i, newValue);
    _treeArray[node] = newChildrenSum;
    return newChildrenSum;
  }
  long long recursiveIncrement(long node, long i, long addend) {
    long left, right;
    std::tie(left, right) = _endpoints[node];
    if (left == i && right == i + 1) {
      _treeArray[node] += addend;
      return _treeArray[node];
    }
    if (i < left || i >= right) {
      return _treeArray[node];
    }
    auto leftChildNode = (node << 1), rightChildNode = ((node << 1) | 1);
    auto newChildrenSum = recursiveIncrement(leftChildNode, i, addend) +
                          recursiveIncrement(rightChildNode, i, addend);
    _treeArray[node] = newChildrenSum;
    return newChildrenSum;
  }
  long long recursiveQuery(long node, long i, long j) {
    long left, right;
    std::tie(left, right) = _endpoints[node];
    if (i >= right || j <= left || j <= i) return nil;
    if (i == left && j == right) {
      return _treeArray[node];
    }
    auto med = left + ((right - left) >> 1);
    auto leftChildNode = (node << 1);
    auto rightChildNode = ((node << 1) | 1);
    auto ret = recursiveQuery(leftChildNode, i, std::min(j, med)) +
               recursiveQuery(rightChildNode, std::max(i, med), j);
    return ret;
  }
};
vector<long> readLongVector() {
  vector<long> ret{};
  std::string line;
  std::getline(std::cin, line);
  std::istringstream lineAsStream(line);
  std::copy(std::istream_iterator<long>(lineAsStream),
            std::istream_iterator<long>(), std::back_inserter(ret));
  return ret;
}
int main() {
  long n;
  cin >> n;
  cin.ignore();
  auto v = readLongVector();
  auto u = v;
  std::sort(u.begin(), u.end());
  unordered_map<long, long> rank{};
  long temp = 0;
  for (auto x : u) {
    rank[x] = temp;
    ++temp;
  }
  for (auto& x : v) {
    x = rank[x];
  }
  u.clear();
  rank.clear();
  vector<long long> s(n, 0);
  vector<long long> t(n, 0);
  SegmentTree st(s);
  SegmentTree st2(t);
  long long ret = 0;
  for (long i = n - 1; i >= 0; --i) {
    auto rk = v[i];
    ret += st2.query(1, rk);
    st2.increment(rk, st.query(0, rk));
    st.increment(rk, 1);
  }
  cout << ret << endl;
}

### Prompt

Please provide a Cpp coded solution 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;
class SegmentTree {
 public:
  SegmentTree(std::vector<long long>& inputArray) {
    n = inputArray.size();
    N = 1;
    while (N < n) N <<= 1;
    _treeArray = std::vector<long long>(N, 0);
    _endpoints = std::vector<std::pair<long, long>>(2 * N);
    _treeArray.insert(_treeArray.end(), inputArray.begin(), inputArray.end());
    _treeArray.resize(2 * N, 0);
    for (auto i = N; i < 2 * N; ++i) {
      _endpoints[i] = {i - N, i - N + 1};
    }
    for (auto i = N - 1; i > 0; --i) {
      _treeArray[i] = _treeArray[i << 1] + _treeArray[(i << 1) | 1];
      _endpoints[i] = {_endpoints[i << 1].first,
                       _endpoints[(i << 1) | 1].second};
    }
  }
  long long query(long i, long j) {
    if (i < 0 || j > n) {
      std::cout << "query: " << i << "," << j
                << " out of range for array with indices " << 0 << "," << n
                << std::endl;
      return -1;
    }
    return recursiveQuery(1, i, j);
  }
  void reveal() {
    std::cout << "underlying array:  ";
    for (auto& x : _treeArray) std::cout << x << " ";
    std::cout << std::endl;
  }
  void increment(long i, long long addend) {
    if (i < 0 || i >= n) {
      std::cout << "increment at index: " << i
                << " out of range for array with indices " << 0 << "," << n
                << std::endl;
      return;
    }
    recursiveIncrement(1, i, addend);
  }
  void update(long i, long long newValue) {
    if (i < 0 || i >= n) {
      std::cout << "index: " << i << " out of range for array with indices "
                << 0 << "," << n << std::endl;
      return;
    }
    recursiveUpdate(1, i, newValue);
  }

 private:
  long n;
  long N;
  std::vector<long long> _treeArray;
  long long nil = 0;
  std::vector<std::pair<long, long>> _endpoints;
  long long recursiveUpdate(long node, long i, long newValue) {
    long left, right;
    std::tie(left, right) = _endpoints[node];
    if (left == i && right == i + 1) {
      _treeArray[node] = newValue;
      return newValue;
    }
    if (i < left || i >= right) {
      return _treeArray[node];
    }
    auto leftChildNode = (node << 1), rightChildNode = ((node << 1) | 1);
    auto newChildrenSum = recursiveUpdate(leftChildNode, i, newValue) +
                          recursiveUpdate(rightChildNode, i, newValue);
    _treeArray[node] = newChildrenSum;
    return newChildrenSum;
  }
  long long recursiveIncrement(long node, long i, long addend) {
    long left, right;
    std::tie(left, right) = _endpoints[node];
    if (left == i && right == i + 1) {
      _treeArray[node] += addend;
      return _treeArray[node];
    }
    if (i < left || i >= right) {
      return _treeArray[node];
    }
    auto leftChildNode = (node << 1), rightChildNode = ((node << 1) | 1);
    auto newChildrenSum = recursiveIncrement(leftChildNode, i, addend) +
                          recursiveIncrement(rightChildNode, i, addend);
    _treeArray[node] = newChildrenSum;
    return newChildrenSum;
  }
  long long recursiveQuery(long node, long i, long j) {
    long left, right;
    std::tie(left, right) = _endpoints[node];
    if (i >= right || j <= left || j <= i) return nil;
    if (i == left && j == right) {
      return _treeArray[node];
    }
    auto med = left + ((right - left) >> 1);
    auto leftChildNode = (node << 1);
    auto rightChildNode = ((node << 1) | 1);
    auto ret = recursiveQuery(leftChildNode, i, std::min(j, med)) +
               recursiveQuery(rightChildNode, std::max(i, med), j);
    return ret;
  }
};
vector<long> readLongVector() {
  vector<long> ret{};
  std::string line;
  std::getline(std::cin, line);
  std::istringstream lineAsStream(line);
  std::copy(std::istream_iterator<long>(lineAsStream),
            std::istream_iterator<long>(), std::back_inserter(ret));
  return ret;
}
int main() {
  long n;
  cin >> n;
  cin.ignore();
  auto v = readLongVector();
  auto u = v;
  std::sort(u.begin(), u.end());
  unordered_map<long, long> rank{};
  long temp = 0;
  for (auto x : u) {
    rank[x] = temp;
    ++temp;
  }
  for (auto& x : v) {
    x = rank[x];
  }
  u.clear();
  rank.clear();
  vector<long long> s(n, 0);
  vector<long long> t(n, 0);
  SegmentTree st(s);
  SegmentTree st2(t);
  long long ret = 0;
  for (long i = n - 1; i >= 0; --i) {
    auto rk = v[i];
    ret += st2.query(1, rk);
    st2.increment(rk, st.query(0, rk));
    st.increment(rk, 1);
  }
  cout << ret << endl;
}

```