#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> pi;
typedef pair<double , int > dpi;
typedef pair<long long , long long> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef unsigned long long ull;
#define MP make_pair
#define mem(a , v) memset(a , v , sizeof(a))
#define all(v) ((v).begin()), ((v).end())
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scd(a) scanf("%lf" , &a)
#define sch(a) scanf("%c" , &a)
#define blank printf("\n")
#define pla printf("plapla\n")
#define pb push_back
#define INF 1e9
#define EPS 1e-9
vector<int> months = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
const int MAX = 1e6+55;
const int inf = 1e9+77;
const int MOD = 1e9+7;
const double PI = acos(-1.0);
const double eps = 1e-7;
int n;
pi a[MAX];
int tree[4*MAX];
int _left[MAX] , _right[MAX];
void update(int p , int st , int en , int loc){
if(st > loc || en < loc)
return;
if(st == en){
tree[p] = 1;
return;
}
int md = (st+en)>>1;
update(p * 2 ,st , md , loc);
update(p * 2 + 1 , md + 1 ,en , loc);
tree[p] = tree[p*2] + tree[p*2+1];
}
int qwr(int p , int st , int en , int l , int r){
if(st > r || en < l)
return 0;
if(st >= l && en <= r)
return tree[p];
int md = (st+en)>>1;
return qwr(p * 2 , st , md , l , r) + qwr(p * 2 + 1 , md + 1 , en , l , r);
}
int main(){
//freopen("output.txt" , "w" , stdout);
//freopen("input.txt" , "r" , stdin);
sc(n);
for(int i = 0 ; i < n ; ++i){
sc(a[i].first);
a[i].second = i;
}
sort(a , a + n);
_right[0] = 0;
update(1 , 0 , n - 1 , a[0].second);
for(int i = 1 ; i < n ; ++i){
if(a[i].second < n - 1)
_right[i] = qwr(1 , 0 , n - 1 , a[i].second + 1 , n - 1);
else
_right[i] = 0;
update(1 , 0 , n - 1 , a[i].second);
}
mem(tree , 0);
reverse(a , a + n);
_left[0] = 0;
update(1 , 0 , n - 1 , a[0].second);
for(int i = 1 ; i < n ; ++i){
if(a[i].second){
_left[i] = qwr(1 , 0 , n - 1 , 0 , a[i].second - 1);
}
else
_left[i] = 0;
update(1 , 0 , n - 1 , a[i].second);
}
reverse(_left , _left + n);
ll res = 0;
for(int i = 1 ; i < n ; ++i){
res += (ll)_left[i] * (ll)_right[i];
}
printf("%I64d" , res);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHBhaXI8aW50ICwgaW50PiBwaTsKdHlwZWRlZiBwYWlyPGRvdWJsZSAsIGludCA+IGRwaTsKdHlwZWRlZiBwYWlyPGxvbmcgbG9uZyAsIGxvbmcgbG9uZz4gcGxsOwp0eXBlZGVmIHZlY3RvcjxpbnQ+IHZpOwp0eXBlZGVmIHZlY3RvcjxsbD4gdmxsOwp0eXBlZGVmIHZlY3RvcjxwaT4gdnBpOwp0eXBlZGVmIHVuc2lnbmVkIGxvbmcgbG9uZyB1bGw7CiNkZWZpbmUgTVAgIG1ha2VfcGFpcgojZGVmaW5lIG1lbShhICwgdikgIG1lbXNldChhICwgdiAsIHNpemVvZihhKSkKI2RlZmluZSBhbGwodikJKCh2KS5iZWdpbigpKSwgKCh2KS5lbmQoKSkKI2RlZmluZSBzYyhhKSBzY2FuZigiJWQiLCZhKQojZGVmaW5lIHNjbChhKSBzY2FuZigiJWxsZCIsJmEpCiNkZWZpbmUgc2NkKGEpIHNjYW5mKCIlbGYiICwgJmEpCiNkZWZpbmUgc2NoKGEpIHNjYW5mKCIlYyIgLCAmYSkKI2RlZmluZSBibGFuayBwcmludGYoIlxuIikKI2RlZmluZSBwbGEgcHJpbnRmKCJwbGFwbGFcbiIpCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgSU5GIDFlOQojZGVmaW5lIEVQUyAxZS05CnZlY3RvcjxpbnQ+IG1vbnRocyA9IHsgMCwgMzEsIDI4LC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