#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
struct Fenwick {
int n;
std::vector<T> a;
Fenwick(int n_ = 0) {
init(n_);
}
void init(int n_) {
n = n_;
a.assign(n, T{});
}
void add(int x, const T &v) {
for (int i = x + 1; i <= n; i += i & -i) {
a[i - 1] = a[i - 1] + v;
}
}
T sum(int x) {
T ans{};
for (int i = x; i > 0; i -= i & -i) {
ans = ans + a[i - 1];
}
return ans;
}
T rangeSum(int l, int r) {
return sum(r) - sum(l);
}
int select(const T &k) {
int x = 0;
T cur{};
for (int i = 1 << std::__lg(n); i; i /= 2) {
if (x + i <= n && cur + a[x + i - 1] <= k) {
x += i;
cur = cur + a[x - 1];
}
}
return x;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<ll> h(n), h2;
for(auto &i : h) cin >> i;
h2 = h;
ranges::sort(h2);
h2.erase(unique(h2.begin(), h2.end()), h2.end());
auto g = [&](ll v) {
return ranges::lower_bound(h2, v) - h2.begin();
};
vector<int> L(n), R(n);
{
Fenwick<int> ft(n + 1);
for(int i = 0; i < n; i++) {
int r = g(h[i]);
L[i] = ft.sum(r);
ft.add(r, 1);
}
}
{
Fenwick<int> ft(n + 1);
for(int i = n - 1; ~i; --i) {
int r = g(h[i]);
R[i] = ft.sum(r);
ft.add(r, 1);
}
}
ll tot = 0;
for(int i = 0; i < n; ++i)
tot += 1LL * L[i] * R[i];
cout << tot;
return 0;
}