#include <bits/stdc++.h>
#define FOR(i , l , r) for(int i = l ; i <= r ; ++i)
#define FORD(i , r , l) for(int i = r ; i >= l ; --i)
#define ll long long
using namespace std;
const int N = 1e5;
int n,a[N + 3];
ll ans;
namespace sub1{
    void solve(){
        FOR(i , 1 , n)
            FOR(j , i + 1 , n)
                FOR(k , j + 1 , n)
                    if(a[i] < a[j] && a[j] < a[k]) ans++;
        cout << ans;
    }
}
namespace sub2{
    int cnt[1003];
    void solve(){
        FOR(j , 1 , n)
            FOR(i , 1 , j - 1)
                if(a[i] < a[j]) cnt[j]++;
        FOR(j , 1 , n)
            FOR(k , j + 1 , n)
                if(a[j] < a[k])
                    ans += cnt[j];
        cout << ans;
    }
}
namespace sub3{
    map<int,int> cnt;
    ll L[N + 3],R[N + 3];
    int t[N + 3],t1[N + 3];
    int get(int x){
        int res = 0;
        for(; x ; x -= x & -x) res += t[x];
        return res;
    }
    void upd(int x){
        for(; x <= n ; x += x & -x)  t[x]++;
    }
    int get1(int x){
        int res = 0;
        for(; x <= n ; x += x & -x) res += t1[x];
        return res;
    }
    void upd1(int x){
        for(; x  ; x -= x & -x)  t1[x]++;
    }
    void solve(){
        FOR(i , 1 , n)  cnt[a[i]] = 1;
        int m = 0;
        for(auto [u , v] : cnt) cnt[u] = ++m;
        FOR(i , 1 , n) a[i] = cnt[a[i]];
        FOR(i  ,1 , n){
            L[i] = get(a[i] - 1);
            upd(a[i]);
        }
        FORD(i , n , 1){
            R[i] = get1(a[i] + 1);
            upd1(a[i]);
        }
        FOR(i , 1 , n) ans += L[i] * R[i];
        cout << ans;
    }
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    freopen("COUNT.inp" , "r" , stdin);
    freopen("COUNT.out" , "w" , stdout);
    cin >> n;
    FOR(i , 1 , n) cin >> a[i];
    if(n <= 100) sub1::solve();
    else if(n <= 1000) sub2::solve();
    else sub3::solve();
    return 0;
}
