/**     Md. Mujahedul Azad (Turin)
        Hajee Mohammad Danesh Science & Technology University **/

#include <map>
#include <math.h>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstring>
#include <algorithm>
using namespace std;

template<class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template<class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template<typename T> T power(T val, T p, T mod){val%=mod; T result=1; while(p>0){if(p&0x1)result=(result*val)%mod;val=(val*val)%mod;p>>=1;}return result;}
template<typename T> inline void read(T &res){int sign=1; res=0;char ch = getchar();while(true){if(ch == '-') break;if(ch >= '0' && ch <='9') break;ch = getchar();}if(ch == '-') sign = -1;else res = ch-'0';while(true){ch = getchar();if(ch < '0' || ch > '9') break;res = (res * 10 + (ch - '0'));}res *= sign;}

#define ff                  first
#define se                  second
#define sfr(a)              read(a)
#define G()                 getchar()
#define pb                  push_back
#define pi                  acos(-1.0)
#define sq(x)               ((x) * (x))
#define sfi(x)              scanf("%d", &x)
#define sfrr(a,b)           read(a), read(b)
#define inOut               {input; output;}
#define SZ(x)               ((int) (x).size())
#define all(x)              (x).begin(), (x).end()
#define mem(a,b)            memset((a),(b),sizeof(a))
#define Case                printf("Case %d: ", cases)
#define input               freopen("input.txt","r",stdin)
#define output              freopen("output.txt","w",stdout)

#define PF                  printf
#define CASE                printf("Case %d: ", cs);
#define CASEN               printf("Case %d:\n", cs);

typedef long long ll;
typedef pair<int,int> pii;

const double eps=3e-8;
const int mx = 1e6+5;

int n;
int a[mx];
pii t[mx<<2];

void build(int p, int l, int r){
    if(l == r) t[p] = {a[l], a[l]};
    else{
        int m = (l+r); m>>=1;

        build(p<<1, l, m);
        build(p<<1|1, m+1, r);

        t[p].ff = max(t[p<<1].ff, t[p<<1|1].ff);
        t[p].se = min(t[p<<1].se, t[p<<1|1].se);
    }
}

ll queryMax(int p, int l, int r, int i, int j, int v){
    if(l>r || l>j || r<i) return 0;
    if(l>=i && r<=j){
        if(t[p].se > v) return (r-l+1);
        if(l == r) return t[p].ff > v;
    }
    int m = (l+r); m>>=1;
    return queryMax(p<<1, l, m, i, j, v) +
           queryMax(p<<1|1, m+1, r, i, j, v);
}

ll queryMin(int p, int l, int r, int i, int j, int v){
    if(l>r || l>j || r<i) return 0;
    if(l>=i && r<=j){
        if(t[p].ff < v) return (r-l+1);
        if(l == r) return t[p].ff < v;
    }
    int m = (l+r); m>>=1;
    return queryMin(p<<1, l, m, i, j, v) +
           queryMin(p<<1|1, m+1, r, i, j, v);
}

int main(){
    sfr(n);
    for(int i=0; i<n; i++)
        sfr(a[i]);
    build(1, 0, n-1);

    ll ans = 0;
    for(int i=1; i<n-1; i++)
        ans += (queryMax(1, 0, n-1, 0, i-1, a[i]) *
                queryMin(1, 0, n-1, i+1, n-1, a[i]));
    PF("%lld\n", ans);

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define lowbit(x) (x&(-x))
#define MAXN 100010
#define MAXK 15
#define P 1000000007
using namespace std;
void in(int &x)
{
    char ch=getchar();x=0;
    while (!(ch>='0'&&ch<='9')) ch=getchar();
    while ((ch>='0'&&ch<='9')) x=x*10+ch-'0',ch=getchar();
}
int n,k;
struct array
{
    long long c[MAXN];
    inline void add(int x,long long delta)
    {
        while (x<=n) c[x]+=delta,x+=lowbit(x),c[x]%=P;
    }
    inline long long sum(int x)
    {
        long long ret=0;
        while (x) ret+=c[x],x-=lowbit(x),ret%=P;
        return ret;
    }
}A[MAXK];
struct num
{
    int id,data;
    bool operator <(const num& a)const
    {
        return data>a.data;
    }
}a[MAXN];
int main()
{
    scanf("%d",&n);
    k=3;
    for (int i=1;i<=n;i++) in(a[i].data),a[i].id=i;
    sort(a+1,a+n+1);
    long long ans=0;
    for (int i=1;i<=n;i++)
    {
        ans+=A[k-1].sum(a[i].id);
        ans%=P;
        for (int j=k-1;j>1;j--)	A[j].add(a[i].id,A[j-1].sum(a[i].id));
        A[1].add(a[i].id,1);
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define lowbit(x) (x&(-x))
#define MAXN 300010
using namespace std;
void in(int &x)
{
	char ch=getchar();x=0;
	while (!(ch>='0'&&ch<='9')) ch=getchar();
	while ((ch>='0'&&ch<='9')) x=x*10+ch-'0',ch=getchar();
}
int n;
struct array
{
	long long c[MAXN];
	void add(int x,long long delta)
	{
		while (x) c[x]+=delta,x-=lowbit(x);
	}
	long long sum(int x)
	{
		long long ret=0;
		while (x<=n) ret+=c[x],x+=lowbit(x);
		return ret;
	}
}A,B;
struct num
{
	int id,data;
	bool operator <(const num& a)const
	{
		return data<a.data;
	}
}a[MAXN];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) in(a[i].data),a[i].id=i;
	sort(a+1,a+n+1);
	long long ans=0;
	for (int i=1;i<=n;i++)
	{
		ans+=B.sum(a[i].id);
		B.add(a[i].id,A.sum(a[i].id));
		A.add(a[i].id,1);
	}
	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define lowbit(x) (x&(-x))
#define MAXN 3000010
using namespace std;
void in(int &x)
{
	char ch=getchar();x=0;
	while (!(ch>='0'&&ch<='9')) ch=getchar();
	while ((ch>='0'&&ch<='9')) x=x*10+ch-'0',ch=getchar();
}
int n;
struct array
{
	long long c[MAXN];
	void add(int x,long long delta)
	{
		while (x) c[x]+=delta,x-=lowbit(x);
	}
	long long sum(int x)
	{
		long long ret=0;
		while (x<=n) ret+=c[x],x+=lowbit(x);
		return ret;
	}
}A,B;
struct num
{
	int id,data;
	bool operator <(const num& a)const
	{
		return data<a.data;
	}
}a[MAXN];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) in(a[i].data),a[i].id=i;
	sort(a+1,a+n+1);
	long long ans=0;
	for (int i=1;i<=n;i++)
	{
		ans+=B.sum(a[i].id);
		B.add(a[i].id,A.sum(a[i].id));
		A.add(a[i].id,1);
	}
	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define lowbit(x) (x&(-x))
#define MAXN 3000010
#define MAXK 15
#define P 1000000007
using namespace std;
void in(int &x)
{
    char ch=getchar();x=0;
    while (!(ch>='0'&&ch<='9')) ch=getchar();
    while ((ch>='0'&&ch<='9')) x=x*10+ch-'0',ch=getchar();
}
int n,k;
struct array
{
    long long c[MAXN];
    inline void add(int x,long long delta)
    {
        while (x<=n) c[x]+=delta,x+=lowbit(x),c[x]%=P;
    }
    inline long long sum(int x)
    {
        long long ret=0;
        while (x) ret+=c[x],x-=lowbit(x),ret%=P;
        return ret;
    }
}A[4];
struct num
{
    int id,data;
    bool operator <(const num& a)const
    {
        return data>a.data;
    }
}a[MAXN];
int main()
{
    scanf("%d",&n);
    k=3;
    for (int i=1;i<=n;i++) in(a[i].data),a[i].id=i;
    sort(a+1,a+n+1);
    long long ans=0;
    for (int i=1;i<=n;i++)
    {
        ans+=A[k-1].sum(a[i].id);
        ans%=P;
        for (int j=k-1;j>1;j--)	A[j].add(a[i].id,A[j-1].sum(a[i].id));
        A[1].add(a[i].id,1);
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define lowbit(x) (x&(-x))
#define MAXN 3000010
#define MAXK 25
using namespace std;
void in(int &x)
{
    char ch=getchar();x=0;
    while (!(ch>='0'&&ch<='9')) ch=getchar();
    while ((ch>='0'&&ch<='9')) x=x*10+ch-'0',ch=getchar();
}
int n,k;
struct array
{
    long long c[MAXN];
    void add(int x,long long delta)
    {
        while (x) c[x]+=delta,x-=lowbit(x);
    }
    long long sum(int x)
    {
        long long ret=0;
        while (x<=n) ret+=c[x],x+=lowbit(x);
        return ret;
    }
}A[3];
struct num
{
    int id,data;
    bool operator <(const num& a)const
    {
        return data<a.data;
    }
}a[MAXN];
int main()
{
    scanf("%d",&n);
    k=3;
    for (int i=1;i<=n;i++) in(a[i].data),a[i].id=i;
    sort(a+1,a+n+1);
    long long ans=0;
    for (int i=1;i<=n;i++)
    {
        ans+=A[k-1].sum(a[i].id);
        for (int j=k-1;j>1;j--)	A[j].add(a[i].id,A[j-1].sum(a[i].id));
        A[1].add(a[i].id,1);
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define lowbit(x) (x&(-x))
#define MAXN 3000010
#define MAXK 15
#define P 1000000007
using namespace std;
void in(int &x)
{
    char ch=getchar();x=0;
    while (!(ch>='0'&&ch<='9')) ch=getchar();
    while ((ch>='0'&&ch<='9')) x=x*10+ch-'0',ch=getchar();
}
int n,k;
struct array
{
    long long c[MAXN];
    inline void add(int x,long long delta)
    {
        while (x<=n) c[x]+=delta,x+=lowbit(x),c[x]%=P;
    }
    inline long long sum(int x)
    {
        long long ret=0;
        while (x) ret+=c[x],x-=lowbit(x),ret%=P;
        return ret;
    }
}A[MAXK];
struct num
{
    int id,data;
    bool operator <(const num& a)const
    {
        return data>a.data;
    }
}a[4];
int main()
{
    scanf("%d",&n);
    k=3;
    for (int i=1;i<=n;i++) in(a[i].data),a[i].id=i;
    sort(a+1,a+n+1);
    long long ans=0;
    for (int i=1;i<=n;i++)
    {
        ans+=A[k-1].sum(a[i].id);
        ans%=P;
        for (int j=k-1;j>1;j--)	A[j].add(a[i].id,A[j-1].sum(a[i].id));
        A[1].add(a[i].id,1);
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define lowbit(x) (x&(-x))
#define MAXN 3000010
#define MAXK 25
using namespace std;
void in(int &x)
{
    char ch=getchar();x=0;
    while (!(ch>='0'&&ch<='9')) ch=getchar();
    while ((ch>='0'&&ch<='9')) x=x*10+ch-'0',ch=getchar();
}
int n,k;
struct array
{
    long long c[MAXN];
    void add(int x,long long delta)
    {
        while (x) c[x]+=delta,x-=lowbit(x);
    }
    long long sum(int x)
    {
        long long ret=0;
        while (x<=n) ret+=c[x],x+=lowbit(x);
        return ret;
    }
}A[MAXK];
struct num
{
    int id,data;
    bool operator <(const num& a)const
    {
        return data<a.data;
    }
}a[MAXN];
int main()
{
    scanf("%d",&n);
    k=3;
    for (int i=1;i<=n;i++) in(a[i].data),a[i].id=i;
    sort(a+1,a+n+1);
    long long ans=0;
    for (int i=1;i<=n;i++)
    {
        ans+=A[k-1].sum(a[i].id);
        for (int j=k-1;j>1;j--)	A[j].add(a[i].id,A[j-1].sum(a[i].id));
        A[1].add(a[i].id,1);
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define lowbit(x) (x&(-x))
#define MAXN 3000010
#define MAXK 15
#define P 1000000007
using namespace std;
void in(int &x)
{
    char ch=getchar();x=0;
    while (!(ch>='0'&&ch<='9')) ch=getchar();
    while ((ch>='0'&&ch<='9')) x=x*10+ch-'0',ch=getchar();
}
int n,k;
struct array
{
    long long c[MAXN];
    inline void add(int x,long long delta)
    {
        while (x<=n) c[x]+=delta,x+=lowbit(x);
    }
    inline long long sum(int x)
    {
        long long ret=0;
        while (x) ret+=c[x],x-=lowbit(x);
        return ret;
    }
}A[4];
struct num
{
    int id,data;
    bool operator <(const num& a)const
    {
        return data>a.data;
    }
}a[MAXN];
int main()
{
    scanf("%d",&n);
    k=3;
    for (int i=1;i<=n;i++) in(a[i].data),a[i].id=i;
    sort(a+1,a+n+1);
    long long ans=0;
    for (int i=1;i<=n;i++)
    {
        ans+=A[k-1].sum(a[i].id);
        for (int j=k-1;j>1;j--)	A[j].add(a[i].id,A[j-1].sum(a[i].id));
        A[1].add(a[i].id,1);
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define lowbit(x) (x&(-x))
#define MAXN 100010
#define MAXK 15
#define P 1000000007
using namespace std;
void in(int &x)
{
    char ch=getchar();x=0;
    while (!(ch>='0'&&ch<='9')) ch=getchar();
    while ((ch>='0'&&ch<='9')) x=x*10+ch-'0',ch=getchar();
}
int n,k;
struct array
{
    long long c[MAXN];
    inline void add(int x,long long delta)
    {
        while (x<=n) c[x]+=delta,x+=lowbit(x),c[x]%=P;
    }
    inline long long sum(int x)
    {
        long long ret=0;
        while (x) ret+=c[x],x-=lowbit(x),ret%=P;
        return ret;
    }
}A[MAXK];
struct num
{
    int id,data;
    bool operator <(const num& a)const
    {
        return data>a.data;
    }
}a[MAXN];
int main()
{
    scanf("%d",&n);
    k=0;
    for (int i=1;i<=n;i++) in(a[i].data),a[i].id=i;
    sort(a+1,a+n+1);
    long long ans=0;
    for (int i=1;i<=n;i++)
    {
        ans+=A[k-1].sum(a[i].id);
        ans%=P;
        for (int j=k-1;j>1;j--)	A[j].add(a[i].id,A[j-1].sum(a[i].id));
        A[1].add(a[i].id,1);
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define N 1000009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll n, m, v[4 * N], c[4*N], z[4*N], t[4*N], ans, t1[4*N];

void upd(int nd, int l, int r, int x){
	if(l==r){
		t[nd]++;
		return;
	}
	if(x <= (l+r)/2)
		upd(nd*2, l, (l+r)/2, x);
	else
		upd(nd*2+1, (l+r)/2+1, r, x);
	t[nd]=t[nd*2]+t[nd*2+1];
}

void upd1(int nd, int l, int r, int x, int y){
	if(l==r){
		t1[nd]+=y;
		return;
	}
	if(x <= (l+r)/2)
		upd1(nd*2, l, (l+r)/2, x, y);
	else
		upd1(nd*2+1, (l+r)/2+1, r, x, y);
	t1[nd]=t1[nd*2]+t1[nd*2+1];
}

int tap(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;
	else if(l>=x and r<=y)
		return t[nd];
	ll cep=tap(nd*2, l, (l+r)/2, x, y);
	ll sag=tap(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int tap1(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;

	if(l>=x and r<=y)
		return t1[nd];

	ll cep=tap1(nd*2, l, (l+r)/2, x, y);
	ll sag=tap1(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		scanf("%d", &v[i]), c[i]=v[i];

	sort(c+1, c+1+n);

	for(int i=1; i<=n; i++){
		if(c[i]==c[i-1])
			z[c[i]]=z[c[i-1]];
		else
			z[c[i]]=z[c[i-1]]+1;
	}
	for(int i=1; i<=n; i++){
		v[i]=z[v[i]];
		upd(1, 1, n, v[i]);
		ll asd=tap(1, 1, n, v[i]+1, n);
//		cout<<asd<<' '<<v[i]<<'\n';
		upd1(1, 1, n, v[i], asd);
		if(i>2)
			ans+=tap1(1, 1, n, v[i]+1, n);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

int n, m, v[N], c[N], z[N], t[N], ans;
int t1[N];

void upd(int nd, int l, int r, int x){
	if(l==r){
		t[nd]++;
		return;
	}
	if(x <= (l+r)/2)
		upd(nd*2, l, (l+r)/2, x);
	else
		upd(nd*2+1, (l+r)/2+1, r, x);
	t[nd]=t[nd*2]+t[nd*2+1];
}

void upd1(int nd, int l, int r, int x, int y){
	if(l==r){
		t1[nd]+=y;
		return;
	}
	if(x <= (l+r)/2)
		upd1(nd*2, l, (l+r)/2, x, y);
	else
		upd1(nd*2+1, (l+r)/2+1, r, x, y);
	t1[nd]=t1[nd*2]+t1[nd*2+1];
}

int tap(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;
	else if(l>=x and r<=y)
		return t[nd];
	int cep=tap(nd*2, l, (l+r)/2, x, y);
	int sag=tap(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int tap1(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;

	if(l>=x and r<=y)
		return t1[nd];

	int cep=tap1(nd*2, l, (l+r)/2, x, y);
	int sag=tap1(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int main(){
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>v[i], c[i]=v[i];

	sort(c+1, c+1+n);

	for(int i=1; i<=n; i++){
		if(c[i]==c[i-1])
			z[c[i]]=z[c[i-1]];
		else
			z[c[i]]=z[c[i-1]]+1;
	}
	for(int i=1; i<=n; i++){
		v[i]=z[v[i]];
		upd(1, 1, n, v[i]);
		int asd=tap(1, 1, n, v[i]+1, n);
//		cout<<asd<<' '<<v[i]<<'\n';
		upd1(1, 1, n, v[i], asd);
		if(i>2)
			ans+=tap1(1, 1, n, v[i]+1, n);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll n, m, v[N], c[N], z[N], t[N], ans, t1[N];

void upd(int nd, int l, int r, int x){
	if(l==r){
		t[nd]++;
		return;
	}
	if(x <= (l+r)/2)
		upd(nd*2, l, (l+r)/2, x);
	else
		upd(nd*2+1, (l+r)/2+1, r, x);
	t[nd]=t[nd*2]+t[nd*2+1];
}

void upd1(int nd, int l, int r, int x, int y){
	if(l==r){
		t1[nd]+=y;
		return;
	}
	if(x <= (l+r)/2)
		upd1(nd*2, l, (l+r)/2, x, y);
	else
		upd1(nd*2+1, (l+r)/2+1, r, x, y);
	t1[nd]=t1[nd*2]+t1[nd*2+1];
}

int tap(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;
	else if(l>=x and r<=y)
		return t[nd];
	ll cep=tap(nd*2, l, (l+r)/2, x, y);
	ll sag=tap(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int tap1(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;

	if(l>=x and r<=y)
		return t1[nd];

	ll cep=tap1(nd*2, l, (l+r)/2, x, y);
	ll sag=tap1(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int main(){
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>v[i], c[i]=v[i];

	sort(c+1, c+1+n);

	for(int i=1; i<=n; i++){
		if(c[i]==c[i-1])
			z[c[i]]=z[c[i-1]];
		else
			z[c[i]]=z[c[i-1]]+1;
	}
	for(int i=1; i<=n; i++){
		v[i]=z[v[i]];
		upd(1, 1, n, v[i]);
		ll asd=tap(1, 1, n, v[i]+1, n);
//		cout<<asd<<' '<<v[i]<<'\n';
		upd1(1, 1, n, v[i], asd);
		if(i>2)
			ans+=tap1(1, 1, n, v[i]+1, n);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define N 1000009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll n, m, v[4 * N], c[4*N], t[4*N], ans, t1[4*N];
map<ll, ll>z;

void upd(ll nd, ll l, ll r, ll x){
	if(l==r){
		t[nd]++;
		return;
	}
	if(x <= (l+r)/2)
		upd(nd*2, l, (l+r)/2, x);
	else
		upd(nd*2+1, (l+r)/2+1, r, x);
	t[nd]=t[nd*2]+t[nd*2+1];
}

void upd1(ll nd, ll l, ll r, ll x, ll y){
	if(l==r){
		t1[nd]+=y;
		return;
	}
	if(x <= (l+r)/2)
		upd1(nd*2, l, (l+r)/2, x, y);
	else
		upd1(nd*2+1, (l+r)/2+1, r, x, y);
	t1[nd]=t1[nd*2]+t1[nd*2+1];
}

ll tap(ll nd, ll l, ll r, ll x, ll y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;
	else if(l>=x and r<=y)
		return t[nd];
	ll cep=tap(nd*2, l, (l+r)/2, x, y);
	ll sag=tap(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

ll tap1(ll nd, ll l, ll r, ll x, ll y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;

	if(l>=x and r<=y)
		return t1[nd];

	ll cep=tap1(nd*2, l, (l+r)/2, x, y);
	ll sag=tap1(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int main(){
	scanf("%d", &n);
	for(ll i=1; i<=n; i++)
		scanf("%d", &v[i]), c[i]=v[i];

	sort(c+1, c+1+n);

	for(ll i=1; i<=n; i++){
		if(c[i]==c[i-1])
			z[c[i]]=z[c[i-1]];
		else
			z[c[i]]=z[c[i-1]]+1;
	}
	for(ll i=1; i<=n; i++){
		v[i]=z[v[i]];
		upd(1, 1, n, v[i]);
		ll asd=tap(1, 1, n, v[i]+1, n);
//		cout<<asd<<' '<<v[i]<<'\n';
		upd1(1, 1, n, v[i], asd);
		if(i>2)
			ans+=tap1(1, 1, n, v[i]+1, n);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll n, m, v[N], c[N], z[N], t[N], ans, t1[N];

void upd(int nd, int l, int r, int x){
	if(l==r){
		t[nd]++;
		return;
	}
	if(x <= (l+r)/2)
		upd(nd*2, l, (l+r)/2, x);
	else
		upd(nd*2+1, (l+r)/2+1, r, x);
	t[nd]=t[nd*2]+t[nd*2+1];
}

void upd1(int nd, int l, int r, int x, int y){
	if(l==r){
		t1[nd]+=y;
		return;
	}
	if(x <= (l+r)/2)
		upd1(nd*2, l, (l+r)/2, x, y);
	else
		upd1(nd*2+1, (l+r)/2+1, r, x, y);
	t1[nd]=t1[nd*2]+t1[nd*2+1];
}

int tap(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;
	else if(l>=x and r<=y)
		return t[nd];
	ll cep=tap(nd*2, l, (l+r)/2, x, y);
	ll sag=tap(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int tap1(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;

	if(l>=x and r<=y)
		return t1[nd];

	ll cep=tap1(nd*2, l, (l+r)/2, x, y);
	ll sag=tap1(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		scanf("%d", &v[i]), c[i]=v[i];

	sort(c+1, c+1+n);

	for(int i=1; i<=n; i++){
		if(c[i]==c[i-1])
			z[c[i]]=z[c[i-1]];
		else
			z[c[i]]=z[c[i-1]]+1;
	}
	for(int i=1; i<=n; i++){
		v[i]=z[v[i]];
		upd(1, 1, n, v[i]);
		ll asd=tap(1, 1, n, v[i]+1, n);
//		cout<<asd<<' '<<v[i]<<'\n';
		upd1(1, 1, n, v[i], asd);
		if(i>2)
			ans+=tap1(1, 1, n, v[i]+1, n);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define N 1000009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll n, m, v[4 * N], c[4*N], z[4*N], t[4*N], ans, t1[4*N];

void upd(ll nd, ll l, ll r, ll x){
	if(l==r){
		t[nd]++;
		return;
	}
	if(x <= (l+r)/2)
		upd(nd*2, l, (l+r)/2, x);
	else
		upd(nd*2+1, (l+r)/2+1, r, x);
	t[nd]=t[nd*2]+t[nd*2+1];
}

void upd1(ll nd, ll l, ll r, ll x, ll y){
	if(l==r){
		t1[nd]+=y;
		return;
	}
	if(x <= (l+r)/2)
		upd1(nd*2, l, (l+r)/2, x, y);
	else
		upd1(nd*2+1, (l+r)/2+1, r, x, y);
	t1[nd]=t1[nd*2]+t1[nd*2+1];
}

ll tap(ll nd, ll l, ll r, ll x, ll y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;
	else if(l>=x and r<=y)
		return t[nd];
	ll cep=tap(nd*2, l, (l+r)/2, x, y);
	ll sag=tap(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

ll tap1(ll nd, ll l, ll r, ll x, ll y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;

	if(l>=x and r<=y)
		return t1[nd];

	ll cep=tap1(nd*2, l, (l+r)/2, x, y);
	ll sag=tap1(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int main(){
	scanf("%d", &n);
	for(ll i=1; i<=n; i++)
		scanf("%d", &v[i]), c[i]=v[i];

	sort(c+1, c+1+n);

	for(ll i=1; i<=n; i++){
		if(c[i]==c[i-1])
			z[c[i]]=z[c[i-1]];
		else
			z[c[i]]=z[c[i-1]]+1;
	}
	for(ll i=1; i<=n; i++){
		v[i]=z[v[i]];
		upd(1, 1, n, v[i]);
		ll asd=tap(1, 1, n, v[i]+1, n);
//		cout<<asd<<' '<<v[i]<<'\n';
		upd1(1, 1, n, v[i], asd);
		if(i>2)
			ans+=tap1(1, 1, n, v[i]+1, n);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define N 1000009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll n, m, v[N], c[N], z[N], t[N], ans, t1[N];

void upd(int nd, int l, int r, int x){
	if(l==r){
		t[nd]++;
		return;
	}
	if(x <= (l+r)/2)
		upd(nd*2, l, (l+r)/2, x);
	else
		upd(nd*2+1, (l+r)/2+1, r, x);
	t[nd]=t[nd*2]+t[nd*2+1];
}

void upd1(int nd, int l, int r, int x, int y){
	if(l==r){
		t1[nd]+=y;
		return;
	}
	if(x <= (l+r)/2)
		upd1(nd*2, l, (l+r)/2, x, y);
	else
		upd1(nd*2+1, (l+r)/2+1, r, x, y);
	t1[nd]=t1[nd*2]+t1[nd*2+1];
}

int tap(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;
	else if(l>=x and r<=y)
		return t[nd];
	ll cep=tap(nd*2, l, (l+r)/2, x, y);
	ll sag=tap(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int tap1(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;

	if(l>=x and r<=y)
		return t1[nd];

	ll cep=tap1(nd*2, l, (l+r)/2, x, y);
	ll sag=tap1(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		scanf("%d", &v[i]), c[i]=v[i];

	sort(c+1, c+1+n);

	for(int i=1; i<=n; i++){
		if(c[i]==c[i-1])
			z[c[i]]=z[c[i-1]];
		else
			z[c[i]]=z[c[i-1]]+1;
	}
	for(int i=1; i<=n; i++){
		v[i]=z[v[i]];
		upd(1, 1, n, v[i]);
		ll asd=tap(1, 1, n, v[i]+1, n);
//		cout<<asd<<' '<<v[i]<<'\n';
		upd1(1, 1, n, v[i], asd);
		if(i>2)
			ans+=tap1(1, 1, n, v[i]+1, n);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define N 10000009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll n, m, v[N], c[N], z[N], t[N], ans, t1[N];

void upd(int nd, int l, int r, int x){
	if(l==r){
		t[nd]++;
		return;
	}
	if(x <= (l+r)/2)
		upd(nd*2, l, (l+r)/2, x);
	else
		upd(nd*2+1, (l+r)/2+1, r, x);
	t[nd]=t[nd*2]+t[nd*2+1];
}

void upd1(int nd, int l, int r, int x, int y){
	if(l==r){
		t1[nd]+=y;
		return;
	}
	if(x <= (l+r)/2)
		upd1(nd*2, l, (l+r)/2, x, y);
	else
		upd1(nd*2+1, (l+r)/2+1, r, x, y);
	t1[nd]=t1[nd*2]+t1[nd*2+1];
}

int tap(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;
	else if(l>=x and r<=y)
		return t[nd];
	ll cep=tap(nd*2, l, (l+r)/2, x, y);
	ll sag=tap(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int tap1(int nd, int l, int r, int x, int y){
	if((l<x and r<x) or (l>y and r>y))
		return 0;

	if(l>=x and r<=y)
		return t1[nd];

	ll cep=tap1(nd*2, l, (l+r)/2, x, y);
	ll sag=tap1(nd*2+1, (l+r)/2+1, r, x, y);
	return cep+sag;
}

int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		scanf("%d", &v[i]), c[i]=v[i];

	sort(c+1, c+1+n);

	for(int i=1; i<=n; i++){
		if(c[i]==c[i-1])
			z[c[i]]=z[c[i-1]];
		else
			z[c[i]]=z[c[i-1]]+1;
	}
	for(int i=1; i<=n; i++){
		v[i]=z[v[i]];
		upd(1, 1, n, v[i]);
		ll asd=tap(1, 1, n, v[i]+1, n);
//		cout<<asd<<' '<<v[i]<<'\n';
		upd1(1, 1, n, v[i], asd);
		if(i>2)
			ans+=tap1(1, 1, n, v[i]+1, n);
	}
	cout<<ans;
}


#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
#define maxn 1000009
ll n;
ll tree[maxn];
ll lowbit(int xx){
	return xx&(-xx);
}
void add(ll v,ll id){
	while(id<=n){
		tree[id]+=v;
		id+=lowbit(id);
	}
}
ll sum(int id){
	ll sum=0;
	for(int i=id;i;i-=lowbit(i)){
		sum+=tree[i];
	}
	return sum;
}
struct node{
	int nu,val;
	bool operator<(node b)const{
	return val<b.val;
	}
}e[maxn];

int main(){
	std::ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>e[i].val,e[i].nu=i;
	sort(e+1,e+1+n);
	int ans=0;
	for(int i=1;i<=n;i++){
		int w=sum(e[i].nu);
		ans+=(e[i].nu-w-1)*(i-w-1);
		add(1,e[i].nu);
	}
	cout<<ans<<endl;
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
#define int long long
const int maxn=1e6+1000;

int n,a[maxn],lsh[maxn],cntl[maxn],cntr[maxn],len=0,b[maxn];
long long ans=0;
int t1[maxn],t2[maxn];
int lowbit(int x)
{
	return x&(-x);
}
bool cmp(int x,int y)
{
	return x>y;
}
bool cmp2(const int &x,const int &y)
{
	return x>y;
}
signed main()
{
	scanf("%lld",&n);
	for(int i=n;i>=1;--i)
	{
		scanf("%lld",&a[i]);
		b[i]=lsh[i]=a[i];
	}
	sort(lsh+1,lsh+n+1);
	len=unique(lsh+1,lsh+n+1)-lsh-1;//-1
	for(int i=1;i<=n;++i)
	{
		a[i]=lower_bound(lsh+1,lsh+len+1,a[i])-lsh;//..不减1...
	}
	for(int i=1;i<=n;++i)//l
	{
		int x=a[i]-1;//不算自己
		while(x>0)
		{
			cntl[i]+=t1[x];
			x-=lowbit(x);
		}
		x=a[i];
		while(x<=len)
		{
			t1[x]+=1;
			x+=lowbit(x);
		}
		//printf("%d ",cntl[i]);
	}

	for(int i=1;i<=n;++i)lsh[i]=a[i]=b[i];
	sort(lsh+1,lsh+n+1,cmp);
	len=unique(lsh+1,lsh+n+1)-lsh-1;
	for(int i=1;i<=n;++i)
	{
		a[i]=lower_bound(lsh+1,lsh+len+1,a[i],cmp2)-lsh;//查找降序序列
		//printf("%d ",a[i]);
	}
	//printf("\n");
	for(int i=n;i>0;--i)
	{
		int x=a[i]-1;
		while(x>0){
			cntr[i]+=t2[x];
			x-=lowbit(x);
		}
		x=a[i];
		while(x<=len)
		{
			t2[x]+=1;
			x+=lowbit(x);
		}
		ans+=1ll*cntl[i]*cntr[i];
	//	printf("%d ",cntr[i]);
	}
	printf("%lld",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=100001;
#define ll unsigned long long
ll n,m,x,y,a[maxn],p,c,ans,s1[maxn],s2[maxn];
struct bb{
	ll w,s;
}b[maxn];
long long  sum[maxn<<2],add[maxn<<2];
bool cmp1(bb x,bb y){
	return x.s<y.s;
}
bool cmp2(bb x,bb y){
	return x.s>y.s;
}
void pushup(ll rt){
	sum[rt]=sum[rt<<1]+sum[rt<<1|1];return;
}
void build(ll l,ll r,ll rt){
	if(l==r){
		sum[rt]=a[l];
		return;
	}
     ll mi=(l+r)>>1;
	build(l,mi,rt<<1);
	build(mi+1,r,rt<<1|1);
	pushup(rt);
	return;
}
void pushdown(ll rt,ll ln,ll rn){
		if(add[rt]!=0){
		add[rt<<1]+=add[rt];
		add[rt<<1|1]+=add[rt];
		sum[rt<<1]+=add[rt]*ln;
		sum[rt<<1|1]+=add[rt]*rn;
		add[rt]=0;
	}
}
void update(ll L,ll R,ll k,ll l,ll r,ll rt){
	if(L<=l&&r<=R){
		sum[rt]+=k*(r-l+1);
		add[rt]+=k;
		return;
	}
	ll mi=(l+r)>>1;
	pushdown(rt,mi-l+1,r-mi);
	if(L<=mi)update(L,R,k,l,mi,rt<<1);
	if(R>mi) update(L,R,k,mi+1,r,rt<<1|1);
	pushup(rt);
}
ll que(ll L,ll R,ll l,ll r,ll rt){
	if(L<=l&&r<=R){
		return sum[rt];
	}
	ll mi=(l+r)>>1;
	pushdown(rt,mi-l+1,r-mi);
	long long ans=0;
	if(L<=mi)ans+=que(L,R,l,mi,rt<<1);
	if(R>mi)ans+=que(L,R,mi+1,r,rt<<1|1);
	return ans;
}
int main(){

	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&b[i].s);
		b[i].w=i;
	}
	build(1,n,1);
	sort(b+1,b+1+n,cmp1);
	for(int i=1;i<=n;i++){
			update(b[i].w,b[i].w,1,1,n,1);
			 s1[i]=(i-que(1,b[i].w,1,n,1));
	}
	memset(a,0,sizeof(0));
	build(1,n,1);
	sort(b+1,b+1+n,cmp2);
	for(int i=1;i<=n;i++){
			update(b[i].w,b[i].w,1,1,n,1);
			 s2[i]=(que(1,b[i].w,1,n,1)-1);
	}
	for(int i=1;i<=n;i++){
		ans+=s1[i]*s2[n-i+1];
	}
	cout<<ans;
	return 0;
}


// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define R register int
#define For(i , x , y) for(i = x ;  i<= y ; ++ i)
#define lowbit(x) x & -x
const int N = 1e6 + 5;
inline ll read() {
	ll s = 0 , w = 1; char ch = getchar();
	while(ch < 48 || ch > 57) {if(ch == '-') w = -1; ch = getchar();}
	while(ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48) , ch = getchar();
	return s * w;
}

ll n , cnt , a[N] , b[N] , t[N] , c[N << 1] , pre[N] , succ[N];

inline void update(ll x) {
	while(x <= cnt) ++ c[x] , x += lowbit(x);
}

inline ll query(ll x) {
	ll ans = 0;
	while(x) ans += c[x] , x-= lowbit(x);
	return ans;
}

int main() {
	R i , j;
	n = read();
	For(i , 1 , n)  b[i] = a[i] = read();
	sort(b + 1 , b + n + 1);
	cnt = unique(b + 1 , b + n + 1) - b - 1;
	For(i , 1 , n) t[i] = a[i] = lower_bound(b + 1 , b + cnt + 1 , a[i]) - b;

	For(i , 1 , n) a[i] = t[n - i + 1];
	//For(i , 1 , n) cout << a[i] << " ";
	For(i , 1 , n) {
		pre[i] = query(a[i] - 1);
		update(a[i]);
	//	cout << pre[i] << " ";
	}
	memset(c , 0  , sizeof(c));
	ll ans = 0;
	for(i = n ; i >= 1 ; -- i) {
		succ[i] = query(n) - query(a[i]);
		update(a[i]);
		ans += succ[i] * pre[i];
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) (x&-x)
using namespace std;
int n;
int c[1000005],a[1000005],h[1000005];
struct BIT
{
	int a[1000005];
	void add(int x,int v)
	{
		for(;x<=n;x+=lowbit(x))
			a[x]+=v;
	}
	int sum(int x)
	{
		int s=0;
		for(;x;x-=lowbit(x))
			s+=a[x];
		return s;
	}
}x,y;
int main()
{
	int i,len;
	long long s=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]),h[i]=a[i];
	sort(h+1,h+1+n);
	len=unique(h+1,h+1+n)-h;
	for(i=1;i<=n;i++)
		a[i]=lower_bound(h+1,h+len,a[i])-h;
	for(i=1;i<=n;i++)
		c[i]=i-x.sum(a[i])-1,x.add(a[i],1);
	for(i=n;i>=1;i--)
		s+=1ll*c[i]*y.sum(a[i]),y.add(a[i],1);
	cout<<s;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>

#define maxn 1000006

using namespace std;

int n, a[maxn], id[maxn];
long long ans = 0;

class BIT
{
public:
	int c[maxn];
	void Add(int k, int x)
	{
		while (k <= n)
		{
			c[k] += x;
			k += k & -k;
		}
	}
	int Ask(int k)
	{
		int res = 0;
		while (k)
		{
			res += c[k];
			k -= k & -k;
		}
		return res;
	}
} fr, bc;

inline int read()
{
	char ch = getchar();
	int ret = 0, f = 1;
	while (ch > '9' || ch < '0')
	{
		if (ch == '-')
			f = -f;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
		ret = ret * 10 + ch - '0', ch = getchar();
	return ret * f;
}

bool cmp(int x, int y)
{
	return a[x] < a[y];
}

int main()
{
	// freopen("test.in", "r", stdin);
	// freopen("test.out", "w", stdout);
	n = read();
	for (int i = 1; i <= n; ++i)
		a[i] = read(), id[i] = i;
	sort(id + 1, id + 1 + n, cmp);
	for (int lim = 1, i = 1; i <= n; ++lim)
	{
		int j = i + 1;
		while (a[id[j]] == a[id[i]])
		{
			a[id[j]] = lim;
			++j;
		}
		a[id[i]] = lim;
		bc.Add(lim, j - i);
		i = j;
	}
	bc.Add(a[1], -1);
	for (int i = 2; i <= n; ++i)
	{
		bc.Add(a[i], -1);
		fr.Add(a[i - 1], 1);
		ans += 1ll * (i - 1 - fr.Ask(a[i])) * bc.Ask(a[i] - 1);
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
#define fint register int
#define h 5001
#define p 4337590
using namespace std;
int n;
int ta[p],tb[p],a[p],b[p],l[p],r[p];
inline int lowbit(int x);
inline int query_a(int x);
inline int query_b(int x);
inline void adds_a(int x,int y);
inline void adds_b(int x,int y);
int main()
{
	cin>>n;
	for(fint i=1;i<=n;i++)
	cin>>a[i];
	for(fint i=1;i<=n;i++)
	b[i]=a[i];
	sort(b+1,b+n+1);
	int len=unique(b+1,b+n+1)-b-1;
	for(fint i=1;i<=n;i++)
	a[i]=lower_bound(b+1,b+len+1,a[i])-b;
//	for(fint i=1;i<=n;i++)
//	cout<<a[i]<<" ";
	for(fint i=n;i>=1;i--)
	l[i]+=query_a(a[i]-1),adds_a(a[i],1);//求比a[i]小的
	for(fint i=1;i<=n;i++)//求比a[i]大的
	r[i]+=query_b(n)-query_b(a[i]-1),adds_b(a[i],1);
	int ans=0;
	for(fint i=1;i<=n;i++)
	ans+=l[i]*r[i];
	cout<<ans;
	return 0;
}

inline int lowbit(int x)
{
	return x&(-x);
}

inline void adds_a(int x,int y)
{
	for(fint i=x;i<=n;i+=lowbit(i))
	ta[i]+=y;
	return ;
}

inline void adds_b(int x,int y)
{
	for(fint i=x;i<=n;i+=lowbit(i))
	tb[i]+=y;
	return ;
}

inline int query_a(int x)
{
	int tot=0;
	for(fint i=x;i;i-=lowbit(i))
	tot+=ta[i];
	return tot;
}

inline int query_b(int x)
{
	int tot=0;
	for(fint i=x;i;i-=lowbit(i))
	tot+=tb[i];
	return tot;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans,bit[1000009][2],qwq[1000009][2];
struct st{ll x,y;}a[1000009],p[1000009];
bool cmp(const st &a,const st &b){return a.x < b.x;}
ll lb(ll x){return x & (-x);}
void upg(ll x,bool y){while (x <= 1000000) bit[x][y] += 1,x += lb(x);}
ll calc(ll x,bool y){
	ll res = 0;
	while (x) res += bit[x][y],x -= lb(x);
	return res;
}
inline ll read(){
   ll s = 0,w = 1;
   char ch = getchar();
   while (ch < '0'|| ch > '9'){ if (ch == '-') w = -1; ch = getchar();}
   while (ch >= '0'&& ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48),ch = getchar();
   return s * w;
}
int main(){
	cin>>n;
	for (ll i = 1;i <= n;i += 1) a[i].x = read(),p[i] = {a[i].x,i};
	sort(p + 1,p + n + 1,cmp);
	for (ll i = 1;i <= n;i += 1) a[p[i].y].y = i;
	for (ll i = 1;i <= n;i += 1) qwq[i][0] += i - 1 - calc(a[i].y,0),upg(a[i].y,0);
	for (ll i = n;i > 0;i -= 1) qwq[i][1] += calc(a[i].y,1),upg(a[i].y,1);
	for (ll i = 1;i <= n;i += 1) ans += qwq[i][0] * qwq[i][1];
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline long long read(){
    long long w=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        w=(w<<3)+(w<<1)+ch-48;
        ch=getchar();
    }
    return w*f;
}
long long st[5000010],big[5000010],small[5000010],num[5000010],n;
struct node{
    long long val,pos;
}a[5000010];
int comp(node a,node b){
    return a.val<b.val;
}
inline int ls(int p){
    return p<<1;
}
inline int rs(int p){
    return p<<1|1;
}
inline void push_up(int p){
    st[p]=st[ls(p)]+st[rs(p)];
    return;
}
inline void update(int pos,int l,int r,int p){
    if(l==r&&l==pos){
        st[p]++;
        return;
    }
    int mid=(l+r)>>1;
    if(pos<=mid) update(pos,l,mid,ls(p));
    else update(pos,mid+1,r,rs(p));
    push_up(p);
    return;
}
inline long long query(int nl,int nr,int l,int r,int p){
    if(nl<=l&&nr>=r){
        return st[p];
    }
    int mid=(l+r)>>1;
    long long sum=0;
    if(nl<=mid) sum+=query(nl,nr,l,mid,ls(p));
    if(nr>mid) sum+=query(nl,nr,mid+1,r,rs(p));
    return sum;
}
int main(){
    n=read();
    int i,j,k;
    for(i=1;i<=n;i++){
        a[i].val=read();
        a[i].pos=i;
    }
    sort(a+1,a+n+1,comp);
    int cnt=0;
    for(i=1;i<=n;i++){
        if(a[i].val>a[i-1].val) cnt++;
        num[a[i].pos]=cnt;
    }
    for(i=n;i>=1;i--){
        if(num[i]>1) small[i]=query(1,num[i]-1,1,n,1);
        update(num[i],1,n,1);
    }
    memset(st,0,sizeof(st));
    for(i=1;i<=n;i++){
        if(num[i]<n) big[i]=query(num[i]+1,n,1,n,1);
        update(num[i],1,n,1);
    }
    //for(i=1;i<=n;i++){
      //  cout<<small[i]<<" ";
    //}
    unsigned long long ans=0;
    for(i=1;i<=n;i++){
        ans+=small[i]*big[i];
    }
    printf("%ulld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
#define MAXN 1000010
using namespace std;
inline int read ()
{
	int s=0,w=1;
	char ch=getchar ();
	while (ch<'0'||ch>'9'){if (ch=='-') w=-1;ch=getchar ();}
	while ('0'<=ch&&ch<='9') s=(s<<1)+(s<<3)+(ch^48),ch=getchar ();
	return s*w;
}
int n;
long long ans;
int a[MAXN],L[MAXN],R[MAXN],c[MAXN];
vector<int>v;
int lowbit (int x)
{
	return x&-x;
}
void add (int x)
{
	for (int i=x;i<=n;i+=lowbit (i)) c[i]++;
}
int query (int x)
{
	int sum=0;
	for (int i=x;i>=1;i-=lowbit (i)) sum+=c[i];
	return sum;
}
int main()
{
	n=read ();
	for (int i=1;i<=n;i++) a[i]=read (),v.push_back (a[i]);
	sort (v.begin (),v.end ());
	v.erase (unique (v.begin (),v.end ()),v.end ());
	for (int i=1;i<=n;i++) a[i]=lower_bound (v.begin (),v.end (),a[i])-v.begin ()+1;
	for (int i=1;i<=n;i++)
	{
		L[i]=query (n)-query (a[i]);
		add (a[i]);
	}
	memset (c,0,sizeof (c));
	for (int i=n;i>=1;i--)
	{
		R[i]=query (a[i]);
		add (a[i]);
	}
	for (int i=1;i<=n;i++) ans+=1ll*L[i]*R[i];
	printf ("%lld",ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 1000000 + 7;

int n;
struct str {
	int x, i, p;
} a[N];
int l[N];
int tr[N];
long long ans;

void add(int i) {
	for (; i <= n; i += i & -i)
		++tr[i];
}

int sum(int i) {
	int t = 0;
	for (; i; i -= i & -i)
		t += tr[i];
	return t;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i].x),
		a[i].i = i;

	sort(a + 1, a + n + 1, [](str a, str b) {
		return a.x < b.x;
	});
	a[1].p = 1;
	for (int i = 2; i <= n; ++i)
		a[i].p = a[i - 1].p + (a[i].x != a[i - 1].x);
	sort(a + 1, a + n + 1, [](str a, str b) {
		return a.i < b.i;
	});

	for (int i = 1; i <= n; ++i)
		l[i] = i - 1 - sum(a[i].p),
		add(a[i].p);

	memset(tr, 0, sizeof(tr));
	for (int i = n; i; --i)
		ans += 1ll * l[i] * sum(a[i].p - 1),
		add(a[i].p);

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
int n;
int a[1000005];
int b[1000005];
int c[1000005];
int r[1000005];
int LowBit(int x)
{
	return x&(-x);
}
void Add(int x,int d)
{
	while(x<=n)
	{
		c[x]+=d;
		x+=LowBit(x);
	}
}
int Query(int x)
{
	int res=0;
	while(x)
	{
		res+=c[x];
		x-=LowBit(x);
	}
	return res;
}
bool cmp(int x,int y)
{
	return b[x]<b[y];
}

signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&b[i]);
		a[i]=i;
	}
	sort(a+1,a+n+1,cmp);
	int ans=0;
	for(int i=n;i>0;--i)
	{
		r[i]=Query(a[i]-1);
		Add(a[i],1);
	}
	memset(c,0,sizeof(c));
	for(int i=1;i<=n;++i)
	{
		ans+=r[i]*(Query(n)-Query(a[i]));
		Add(a[i],1);
	}
	printf("%lld",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,ans,a[N];
int main(){
	scanf("%d",&n);
	for ( register int i=1 ; i<=n ; i++ ) scanf("%d",&a[i]);
	for ( register int i=1 ; i<=n ; i++ )
	    for ( register int j=i+1; j<=n ; j++ )
	        if( a[i] > a[j] )
	        for ( register int k=j+1 ; k<=n ; k++ )
	            if( a[k] < a[j] ) ans++;
	cout << ans << endl;
	return 0;
}


// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define R register int
#define For(i , x , y) for(i = x ;  i<= y ; ++ i)
#define lowbit(x) x & -x
const int N = 1e6 + 5;
inline ll read() {
	ll s = 0 , w = 1; char ch = getchar();
	while(ch < 48 || ch > 57) {if(ch == '-') w = -1; ch = getchar();}
	while(ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48) , ch = getchar();
	return s * w;
}

ll n , cnt , a[N] , b[N] , t[N] , c[N << 1] , prev[N] , succ[N];

inline void update(ll x) {
	while(x <= cnt) ++ c[x] , x += lowbit(x);
}

inline ll query(ll x) {
	ll ans = 0;
	while(x) ans += c[x] , x-= lowbit(x);
	return ans;
}

int main() {
	R i , j;
	n = read();
	For(i , 1 , n)  b[i] = a[i] = read();
	sort(b + 1 , b + n + 1);
	cnt = unique(b + 1 , b + n + 1) - b - 1;
	For(i , 1 , n) t[i] = a[i] = lower_bound(b + 1 , b + cnt + 1 , a[i]) - b;

	For(i , 1 , n) a[i] = t[n - i + 1];
	//For(i , 1 , n) cout << a[i] << " ";
	For(i , 1 , n) {
		prev[i] = query(a[i] - 1);
		update(a[i]);
	//	cout << prev[i] << " ";
	}
	memset(c , 0  , sizeof(c));
	ll ans = 0;
	for(i = n ; i >= 1 ; -- i) {
		succ[i] = query(n) - query(a[i]);
		update(a[i]);
		ans += succ[i] * prev[i];
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef struct no
{
	int i,j;
	long long soma;
	long long res;
	no *left,*right;
}NO;

int v[100100];
int h[100100];
int n,k,t;

long long query(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->soma;
	int somaesq = query(curr->left,a,b);
	int somadir = query(curr->right,a,b);
	return somaesq + somadir;
}

long long qurry(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->res;
	int somaesq = qurry(curr->left,a,b);
	int somadir = qurry(curr->right,a,b);
	return somaesq + somadir;
}

no *build (int i,int j){
	no *novo = new no();
	novo->i = i;
	novo->j = j;
	novo->res=0;
	novo->soma = 0;
	if(i==j)
		return novo;
	int mid = (i+j)/2;
	novo->left = build(i,mid);
	novo->right = build(mid+1,j);
	return novo;
}

void update(no * curr, int a, int b,int val,int atu){
	if(curr->j < a or curr->i > b) return;
	if(curr->i >=a && curr->j <= b){
		curr->soma=1;
		curr->res=atu;
		return;
	}
	update(curr->left,a,b,val,atu);
	update(curr->right,a,b,val,atu);

	curr->soma = curr->left->soma+curr->right->soma;
	curr->res = curr->left->res+curr->right->res;
}
map<int,int> m;
int main(){
	long long r=0;
	scanf("%d",&n);
	no* ini=build(0,100100);
	int x;
	int atu;
	for(int j=0;j<n;j++){
		scanf("%d",v+j);
		h[j]=v[j];
	}
	sort(v,v+n);
	for(int j=0;j<n;j++){
		m[v[j]]=j;
	}
	for(int j=0;j<n;j++){
		r+=qurry(ini,m[h[j]]+1,n-1);
		atu=query(ini,m[h[j]]+1,n-1);
		update(ini,m[h[j]],m[h[j]],1,atu);
	}
	printf("%lld\n",r);
}
// 1499646668367


#include <bits/stdc++.h>

using namespace std;

typedef struct no
{
	int i,j;
	long long soma;
	long long res;
	no *left,*right;
}NO;

int v[1001000];
int h[1001000];
int n,k,t;

long long query(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->soma;
	int somaesq = query(curr->left,a,b);
	int somadir = query(curr->right,a,b);
	return somaesq + somadir;
}

long long qurry(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->res;
	int somaesq = qurry(curr->left,a,b);
	int somadir = qurry(curr->right,a,b);
	return somaesq + somadir;
}

no *build (int i,int j){
	no *novo = new no();
	novo->i = i;
	novo->j = j;
	novo->res=0;
	novo->soma = 0;
	if(i==j)
		return novo;
	int mid = (i+j)/2;
	novo->left = build(i,mid);
	novo->right = build(mid+1,j);
	return novo;
}

void update(no * curr, int a, int b,int val,int atu){
	if(curr->j < a or curr->i > b) return;
	if(curr->i >=a && curr->j <= b){
		curr->soma=1;
		curr->res=atu;
		return;
	}
	update(curr->left,a,b,val,atu);
	update(curr->right,a,b,val,atu);

	curr->soma = curr->left->soma+curr->right->soma;
	curr->res = curr->left->res+curr->right->res;
}
map<int,int> m;
int main(){
	long long r=0;
	scanf("%d",&n);
	no* ini=build(0,1001000);
	int x;
	int atu;
	for(int j=0;j<n;j++){
		scanf("%d",v+j);
		h[j]=v[j];
	}
	sort(v,v+n);
	for(int j=0;j<n;j++){
		m[v[j]]=j;
	}
	for(int j=0;j<n;j++){
		r+=qurry(ini,m[h[j]]+1,n-1);
		atu=query(ini,m[h[j]]+1,n-1);
		update(ini,m[h[j]],m[h[j]],1,atu);
	}
	printf("%lld\n",r);
}
// 1499648651797


#include <bits/stdc++.h>

using namespace std;

typedef struct no
{
	int i,j;
	long long soma;
	long long res;
	no *left,*right;
}NO;

int v[100100];
int h[100100];
int n,k,t;

long long query(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->soma;
	int somaesq = query(curr->left,a,b);
	int somadir = query(curr->right,a,b);
	return somaesq + somadir;
}

long long qurry(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->res;
	int somaesq = qurry(curr->left,a,b);
	int somadir = qurry(curr->right,a,b);
	return somaesq + somadir;
}

no *build (int i,int j){
	no *novo = new no();
	novo->i = i;
	novo->j = j;
	novo->res=0;
	novo->soma = 0;
	if(i==j)
		return novo;
	int mid = (i+j)/2;
	novo->left = build(i,mid);
	novo->right = build(mid+1,j);
	return novo;
}

void update(no * curr, int a, int b,int val,int atu){
	if(curr->j < a or curr->i > b) return;
	if(curr->i >=a && curr->j <= b){
		curr->soma=1;
		curr->res=atu;
		return;
	}
	update(curr->left,a,b,val,atu);
	update(curr->right,a,b,val,atu);

	curr->soma = curr->left->soma+curr->right->soma;
	curr->res = curr->left->res+curr->right->res;
}
map<int,int> m;
int main(){
	long long r=0;
	scanf("%d",&n);
	no* ini=build(0,100100);
	int x;
	int atu;
	for(int j=0;j<n;j++){
		scanf("%d",v+j);
		h[j]=v[j];
	}
	sort(v,v+n);
	for(int j=0;j<n;j++){
		m[v[j]]=j;
	}
	for(int j=0;j<n;j++){
		r+=qurry(ini,m[h[j]]+1,n-1);
		atu=query(ini,m[h[j]]+1,n-1);
		update(ini,m[h[j]],m[h[j]],1,atu);
	}
	printf("%lld\n",r);
}
// 1499644968066


#include <bits/stdc++.h>

using namespace std;

typedef struct no
{
	int i,j;
	long long soma;
	long long res;
	no *left,*right;
}NO;

int v[1001000];
int h[1001000];
int n,k,t;

long long query(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->soma;
	int somaesq = query(curr->left,a,b);
	int somadir = query(curr->right,a,b);
	return somaesq + somadir;
}

long long qurry(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->res;
	int somaesq = qurry(curr->left,a,b);
	int somadir = qurry(curr->right,a,b);
	return somaesq + somadir;
}

no *build (int i,int j){
	no *novo = new no();
	novo->i = i;
	novo->j = j;
	novo->res=0;
	novo->soma = 0;
	if(i==j)
		return novo;
	int mid = (i+j)/2;
	novo->left = build(i,mid);
	novo->right = build(mid+1,j);
	return novo;
}

void update(no * curr, int a, int b,int val,int atu){
	if(curr->j < a or curr->i > b) return;
	if(curr->i >=a && curr->j <= b){
		curr->soma=1;
		curr->res=atu;
		return;
	}
	update(curr->left,a,b,val,atu);
	update(curr->right,a,b,val,atu);

	curr->soma = curr->left->soma+curr->right->soma;
	curr->res = curr->left->res+curr->right->res;
}
map<int,int> m;
int main(){
	long long r=0;
	scanf("%d",&n);
	no* ini=build(0,1001000);
	int x;
	int atu;
	for(int j=0;j<n;j++){
		scanf("%d",v+j);
		h[j]=v[j];
	}
	sort(v,v+n);
	for(int j=0;j<n;j++){
		m[v[j]]=j;
	}
	for(int j=0;j<n;j++){
		r+=qurry(ini,m[h[j]]+1,n-1);
		atu=query(ini,m[h[j]]+1,n-1);
		update(ini,m[h[j]],m[h[j]],1,atu);
	}
	printf("%lld\n",r);
}
// 1499645366376


#include <bits/stdc++.h>

using namespace std;

typedef struct no
{
	int i,j;
	long long soma;
	long long res;
	no *left,*right;
}NO;

int v[1001000];
int h[1001000];
int n,k,t;

long long query(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->soma;
	int somaesq = query(curr->left,a,b);
	int somadir = query(curr->right,a,b);
	return somaesq + somadir;
}

long long qurry(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->res;
	int somaesq = qurry(curr->left,a,b);
	int somadir = qurry(curr->right,a,b);
	return somaesq + somadir;
}

no *build (int i,int j){
	no *novo = new no();
	novo->i = i;
	novo->j = j;
	novo->res=0;
	novo->soma = 0;
	if(i==j)
		return novo;
	int mid = (i+j)/2;
	novo->left = build(i,mid);
	novo->right = build(mid+1,j);
	return novo;
}

void update(no * curr, int a, int b,int val,int atu){
	if(curr->j < a or curr->i > b) return;
	if(curr->i >=a && curr->j <= b){
		curr->soma=1;
		curr->res=atu;
		return;
	}
	update(curr->left,a,b,val,atu);
	update(curr->right,a,b,val,atu);

	curr->soma = curr->left->soma+curr->right->soma;
	curr->res = curr->left->res+curr->right->res;
}
map<int,int> m;
int main(){
	long long r=0;
	scanf("%d",&n);
	no* ini=build(0,1001000);
	int x;
	int atu;
	for(int j=0;j<n;j++){
		scanf("%d",v+j);
		h[j]=v[j];
	}
	sort(v,v+n);
	for(int j=0;j<n;j++){
		m[v[j]]=j;
	}
	for(int j=0;j<n;j++){
		r+=qurry(ini,m[h[j]]+1,n-1);
		atu=query(ini,m[h[j]]+1,n-1);
		update(ini,m[h[j]],m[h[j]],1,atu);
	}
	printf("%lld\n",r);
}
// 1499716976865


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int size = 1e6+100;
ll a[size], b[size], bit1[size], bit2[size];
map<int, int> comp;

void updt(int idx, int val, ll bit[]){
	while(idx > 0){
		bit[idx] += val;
		idx -= idx&(-idx);
	}
}

ll query(int idx, ll bit[]){
	ll ans = 0;
	while(idx < size){
		ans += bit[idx];
		idx += idx&(-idx);
	}
	return ans;
}

int main(){
	int n;
	scanf("%d" ,&n);
	memset(bit1, 0, sizeof bit1);
	memset(bit2, 0, sizeof bit2);
	memset(a, 0, sizeof a);
	memset(b, 0, sizeof b);
	for(int i = 1; i <= n; i++){
		scanf("%d" ,a+i);
		b[i] = a[i];
	}

	sort(b+1, b+n+1);
	for(int i = 1; i <= n; i++){
		comp[b[i]] = i;
	}

	ll ans = 0;
	for(int i = 1; i <= n; i++){
		updt(comp[a[i]], 1, bit1);
		updt(comp[a[i]], query(comp[a[i]]+1, bit1), bit2);
		ans += query(comp[a[i]]+1, bit2);
	}

	cout << ans;
	return 0;
}
// 1511896259728


#include <bits/stdc++.h>

using namespace std;

typedef struct no
{
	int i,j;
	long long soma;
	long long res;
	no *left,*right;
}NO;

int v[1001000];
int h[1001000];
int n,k,t;

long long query(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->soma;
	int somaesq = query(curr->left,a,b);
	int somadir = query(curr->right,a,b);
	return somaesq + somadir;
}

long long qurry(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->res;
	int somaesq = qurry(curr->left,a,b);
	int somadir = qurry(curr->right,a,b);
	return somaesq + somadir;
}

no *build (int i,int j){
	no *novo = new no();
	novo->i = i;
	novo->j = j;
	novo->res=0;
	novo->soma = 0;
	if(i==j)
		return novo;
	int mid = (i+j)/2;
	novo->left = build(i,mid);
	novo->right = build(mid+1,j);
	return novo;
}

void update(no * curr, int a, int b,int val,int atu){
	if(curr->j < a or curr->i > b) return;
	if(curr->i >=a && curr->j <= b){
		curr->soma=1;
		curr->res=atu;
		return;
	}
	update(curr->left,a,b,val,atu);
	update(curr->right,a,b,val,atu);

	curr->soma = curr->left->soma+curr->right->soma;
	curr->res = curr->left->res+curr->right->res;
}
map<int,int> m;
int main(){
	long long r=0;
	scanf("%d",&n);
	no* ini=build(0,1001000);
	int x;
	int atu;
	for(int j=0;j<n;j++){
		scanf("%d",v+j);
		h[j]=v[j];
	}
	sort(v,v+n);
	for(int j=0;j<n;j++){
		m[v[j]]=j;
	}
	for(int j=0;j<n;j++){
		r+=qurry(ini,m[h[j]]+1,n-1);
		atu=query(ini,m[h[j]]+1,n-1);
		update(ini,m[h[j]],m[h[j]],1,atu);
	}
	printf("%lld\n",r);
}
// 1499645821314


#include <bits/stdc++.h>

using namespace std;

typedef struct no
{
	int i,j;
	long long soma;
	long long res;
	no *left,*right;
}NO;

int v[1001000];
int h[1001000];
int n,k,t;

long long query(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->soma;
	int somaesq = query(curr->left,a,b);
	int somadir = query(curr->right,a,b);
	return somaesq + somadir;
}

long long qurry(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->res;
	int somaesq = qurry(curr->left,a,b);
	int somadir = qurry(curr->right,a,b);
	return somaesq + somadir;
}

no *build (int i,int j){
	no *novo = new no();
	novo->i = i;
	novo->j = j;
	novo->res=0;
	novo->soma = 0;
	if(i==j)
		return novo;
	int mid = (i+j)/2;
	novo->left = build(i,mid);
	novo->right = build(mid+1,j);
	return novo;
}

void update(no * curr, int a, int b,int val,int atu){
	if(curr->j < a or curr->i > b) return;
	if(curr->i >=a && curr->j <= b){
		curr->soma=1;
		curr->res=atu;
		return;
	}
	update(curr->left,a,b,val,atu);
	update(curr->right,a,b,val,atu);

	curr->soma = curr->left->soma+curr->right->soma;
	curr->res = curr->left->res+curr->right->res;
}
map<int,int> m;
int main(){
	long long r=0;
	scanf("%d",&n);
	no* ini=build(0,1001000);
	int x;
	int atu;
	for(int j=0;j<n;j++){
		scanf("%d",v+j);
		h[j]=v[j];
	}
	sort(v,v+n);
	for(int j=0;j<n;j++){
		m[v[j]]=j;
	}
	for(int j=0;j<n;j++){
		r+=qurry(ini,m[h[j]]+1,n-1);
		atu=query(ini,m[h[j]]+1,n-1);
		update(ini,m[h[j]],m[h[j]],1,atu);
	}
	printf("%lld\n",r);
}
// 1499715372235


#include <bits/stdc++.h>

using namespace std;

typedef struct no
{
	int i,j;
	long long soma;
	long long res;
	no *left,*right;
}NO;

int v[1001000];
int h[1001000];
int n,k,t;

long long query(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->soma;
	long long somaesq = query(curr->left,a,b);
	long long somadir = query(curr->right,a,b);
	return somaesq + somadir;
}

long long qurry(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->res;
	long long somaesq = qurry(curr->left,a,b);
	long long somadir = qurry(curr->right,a,b);
	return somaesq + somadir;
}

no *build (int i,int j){
	no *novo = new no();
	novo->i = i;
	novo->j = j;
	novo->res=0;
	novo->soma = 0;
	if(i==j)
		return novo;
	int mid = (i+j)/2;
	novo->left = build(i,mid);
	novo->right = build(mid+1,j);
	return novo;
}

void update(no * curr, int a, int b,int val,long long atu){
	if(curr->j < a or curr->i > b) return;
	if(curr->i >=a && curr->j <= b){
		curr->soma=1;
		curr->res=atu;
		return;
	}
	update(curr->left,a,b,val,atu);
	update(curr->right,a,b,val,atu);

	curr->soma = curr->left->soma+curr->right->soma;
	curr->res = curr->left->res+curr->right->res;
}
map<int,int> m;
int main(){
	long long r=0;
	scanf("%d",&n);
	no* ini=build(0,1001000);
	int x;
	long long atu;
	for(int j=0;j<n;j++){
		scanf("%d",v+j);
		h[j]=v[j];
	}
	sort(v,v+n);
	for(int j=0;j<n;j++){
		m[v[j]]=j;
	}
	for(int j=0;j<n;j++){
		r+=qurry(ini,m[h[j]]+1,n);
		atu=query(ini,m[h[j]]+1,n);
		update(ini,m[h[j]],m[h[j]],1,atu);
	}
	printf("%lld\n",r);
}
// 1499732621992


#include <bits/stdc++.h>

using namespace std;

typedef struct no
{
	int i,j;
	long long soma;
	long long res;
	no *left,*right;
}NO;

int v[1001000];
int h[1001000];
int n,k,t;

long long query(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->soma;
	long long somaesq = query(curr->left,a,b);
	long long somadir = query(curr->right,a,b);
	return somaesq + somadir;
}

long long qurry(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->res;
	long long somaesq = qurry(curr->left,a,b);
	long long somadir = qurry(curr->right,a,b);
	return somaesq + somadir;
}

no *build (int i,int j){
	no *novo = new no();
	novo->i = i;
	novo->j = j;
	novo->res=0;
	novo->soma = 0;
	if(i==j)
		return novo;
	int mid = (i+j)/2;
	novo->left = build(i,mid);
	novo->right = build(mid+1,j);
	return novo;
}

void update(no * curr, int a, int b,int val,long long atu){
	if(curr->j < a or curr->i > b) return;
	if(curr->i >=a && curr->j <= b){
		curr->soma=1;
		curr->res=atu;
		return;
	}
	update(curr->left,a,b,val,atu);
	update(curr->right,a,b,val,atu);

	curr->soma = curr->left->soma+curr->right->soma;
	curr->res = curr->left->res+curr->right->res;
}
map<int,int> m;
int main(){
	long long r=0;
	scanf("%d",&n);
	no* ini=build(0,1001000);
	int x;
	long long atu;
	for(int j=0;j<n;j++){
		scanf("%d",v+j);
		h[j]=v[j];
	}
	sort(v,v+n);
	for(int j=0;j<n;j++){
		m[v[j]]=j;
	}
	for(int j=0;j<n;j++){
		r+=qurry(ini,m[h[j]]+1,n);
		atu=query(ini,m[h[j]]+1,n);
		update(ini,m[h[j]],m[h[j]],1,atu);
	}
	printf("%lld\n",r);
}
// 1499731687258


#include <bits/stdc++.h>

using namespace std;

typedef struct no
{
	int i,j;
	long long soma;
	long long res;
	no *left,*right;
}NO;

int v[100100];
int h[100100];
int n,k,t;

long long query(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->soma;
	int somaesq = query(curr->left,a,b);
	int somadir = query(curr->right,a,b);
	return somaesq + somadir;
}

long long qurry(no* curr, int a, int b)
{
	if(a>curr->j or b<curr->i)
		return 0;
	if(curr->i >=a && curr->j <=b)
		return curr->res;
	int somaesq = qurry(curr->left,a,b);
	int somadir = qurry(curr->right,a,b);
	return somaesq + somadir;
}

no *build (int i,int j){
	no *novo = new no();
	novo->i = i;
	novo->j = j;
	novo->res=0;
	novo->soma = 0;
	if(i==j)
		return novo;
	int mid = (i+j)/2;
	novo->left = build(i,mid);
	novo->right = build(mid+1,j);
	return novo;
}

void update(no * curr, int a, int b,int val,int atu){
	if(curr->j < a or curr->i > b) return;
	if(curr->i >=a && curr->j <= b){
		curr->soma=1;
		curr->res=atu;
		return;
	}
	update(curr->left,a,b,val,atu);
	update(curr->right,a,b,val,atu);

	curr->soma = curr->left->soma+curr->right->soma;
	curr->res = curr->left->res+curr->right->res;
}
map<int,int> m;
int main(){
	long long r=0;
	scanf("%d",&n);
	no* ini=build(0,100100);
	int x;
	int atu;
	for(int j=0;j<n;j++){
		scanf("%d",v+j);
		h[j]=v[j];
	}
	sort(v,v+n);
	for(int j=0;j<n;j++){
		m[v[j]]=j;
	}
	for(int j=0;j<n;j++){
		r+=qurry(ini,m[h[j]]+1,n-1);
		atu=query(ini,m[h[j]]+1,n-1);
		update(ini,m[h[j]],m[h[j]],1,atu);
	}
	printf("%lld\n",r);
}
// 1499645063123


#include <bits/stdc++.h>
#define fc first
#define sc second
#define mp make_pair
#define int long long

using namespace std;

int t[10000000];
int tt[10000000];

const int MAXN = 10000000;

void inc(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        t[p] += x;
    }
}

int get(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += t[p];
    }
    return res;
}

void inc_t(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        tt[p] += x;
    }
}

int get_t(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += tt[p];
    }
    return res;
}

main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector <int> a(n);
    vector <int> srt;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        srt.push_back(a[i]);
    }
    sort(srt.begin(), srt.end());
    srt.resize(unique(srt.begin(), srt.end()) - srt.begin());
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        a[i] = lower_bound(srt.begin(), srt.end(), a[i]) - srt.begin();
    }
    for (int i = 0; i < n; i++) {
        int last = get(a[i]);
        inc(a[i] + 1, 1);
        inc_t(a[i] + 1, last);
        ans += get_t(a[i]);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define fc first
#define sc second
#define mp make_pair
#define int long long

using namespace std;

map <int, int> t;
map <int, int> tt;

const int MAXN = 1000000000 + 7;

void inc(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        t[p] += x;
    }
}

int get(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += t[p];
    }
    return res;
}

void inc_t(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        tt[p] += x;
    }
}

int get_t(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += tt[p];
    }
    return res;
}

main() {
    int n;
    cin >> n;
    vector <int> a(n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];

    }
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        int last = get(a[i]);
        inc(a[i] + 1, 1);
        inc_t(a[i] + 1, last);
        ans += get_t(a[i]);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define fc first
#define sc second
#define mp make_pair
#define int long long

using namespace std;

unordered_map <int, int> t;
unordered_map <int, int> tt;

const int MAXN = 1000000000 + 7;

void inc(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        t[p] += x;
    }
}

int get(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += t[p];
    }
    return res;
}

void inc_t(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        tt[p] += x;
    }
}

int get_t(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += tt[p];
    }
    return res;
}

main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector <int> a(n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];

    }
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        int last = get(a[i]);
        inc(a[i] + 1, 1);
        inc_t(a[i] + 1, last);
        ans += get_t(a[i]);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define fc first
#define sc second
#define mp make_pair
#define int long long

using namespace std;

map <int, int> t;
map <int, int> tt;

const int MAXN = 1000000000 + 7;

void inc(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        t[p] += x;
    }
}

int get(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += t[p];
    }
    return res;
}

void inc_t(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        tt[p] += x;
    }
}

int get_t(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += tt[p];
    }
    return res;
}

main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector <int> a(n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];

    }
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        int last = get(a[i]);
        inc(a[i] + 1, 1);
        inc_t(a[i] + 1, last);
        ans += get_t(a[i]);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define fc first
#define sc second
#define mp make_pair
#define int long long

using namespace std;

unordered_map <int, int> t;
unordered_map <int, int> tt;

const int MAXN = 1000000000 + 7;

void inc(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        t[p] += x;
    }
}

int get(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += t[p];
    }
    return res;
}

void inc_t(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        tt[p] += x;
    }
}

int get_t(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += tt[p];
    }
    return res;
}

main() {
    int n;
    cin >> n;
    vector <int> a(n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];

    }
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        int last = get(a[i]);
        inc(a[i] + 1, 1);
        inc_t(a[i] + 1, last);
        ans += get_t(a[i]);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define fc first
#define sc second
#define mp make_pair
#define int long long

using namespace std;

unordered_map <int, int> t;
unordered_map <int, int> tt;

const int MAXN = 1000000000 + 7;
int dp[1000000][4];

void inc(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        t[p] += x;
    }
}

int get(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += t[p];
    }
    return res;
}

void inc_t(int p, int x) {
    for (; p < MAXN; p += (p & -p)) {
        tt[p] += x;
    }
}

int get_t(int p) {
    int res = 0;
    for (; p > 0; p -= (p & -p)) {
        res += tt[p];
    }
    return res;
}

main() {
    int n;
    cin >> n;
    vector <int> a(n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];

    }
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        dp[i][2] = get(a[i]);
        inc(a[i] + 1, 1);
        dp[i][3] = get_t(a[i]);
        inc_t(a[i] + 1, dp[i][2]);
        ans += dp[i][3];
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int ax=1e6+666;
int v[ax],k[ax],brr[ax],crr[ax];
int n;
struct node
{
    int pos,val;
}arr[ax];
bool cmp(node a,node b)
{
    return a.val<b.val;
}
int lowbit(int x)
{
    return x&(-x);
}
void build(int x,int y)
{
    while(x<=n)
    {
        k[x]+=y;
        x+=lowbit(x);
    }
}
int updata(int x)
{
    int ans=0;
    while(x>0)
    {
        ans+=k[x];
        x-=lowbit(x);
    }
    return ans;
}
int main()
{
   cin>>n;
        memset(arr,0,sizeof arr);
        memset(v,0,sizeof v);
        memset(k,0,sizeof k);
        for(int i=1;i<=n;i++)
        {
            cin>>arr[i].val;
            arr[i].pos=i;
        }
        sort(arr+1,arr+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            v[arr[i].pos]=i;
        }
        for(int i=1;i<=n;i++)
        {
            build(v[i],1);
            crr[i]=i-updata(v[i]);
        }
        memset(k,0,sizeof k);
        for(int i=n;i>0;i--)
        {build(v[i],1);
            brr[i]=updata(v[i])-1;

        }
        ll ans=0;
        for(int i=1;i<=n;i++)
        {
            ans+=(long long)brr[i]*crr[i];
        }
        cout<<ans<<endl;
    return 0;
}
//2020-05-14 15:09:08.996


/**
┌───┐   ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
|Esc|   | F1| F2| F3| F4| | F5| F6| F7| F8| | F9|F10|F11|F12| |P/S|S L|P/B|  ┌┐    ┌┐    ┌┐
└───┘   └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘  └┘    └┘    └┘
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
|~ `|! 1|@ 2|# 3|$ 4|% 5|^ 6|& 7|* 8|( 9|) 0|_ -|+ =| BacSp | |Ins|Hom|PUp| |N L| / | * | - |
├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
| Tab | Q | W | E | R | T | Y | U | I | O | P |[ {|] }| | \ | |Del|End|PDn| | 7 | 8 | 9 |   |
├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + |
| Caps | A | S | D | F | G | H | J | K | L |; :|" '| Enter  |               | 4 | 5 | 6 |   |
├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐     ├───┼───┼───┼───┤
| Shift  | Z | X | C | V | B | N | M |< ,|> .|? /|  Shift   |     | ↑ |     | 1 | 2 | 3 |   |
├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E||
| Ctrl|Win |Alt |         Space         | Alt| Fn |    |Ctrl| | ← | ↓ | → | |   0   | . |←─┘|
└─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
**/
#include<stdio.h>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<time.h>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<iostream>
using namespace std;
#define ll long long
#define mes(x,a) memset(x,a,sizeof(x));
#define sca(a) scanf("%d",&a)
#define lowbit(x)  x & (-x)
#define fi first
#define se second
#define pii pair<int, int>
const double eps=1e-9;
const double pi=acos(-1);
const int maxn=1e6+5;
const int maxm=3e5+5;
const int inf =0x3f3f3f3f;
const int mod=1e9+7;
pii x[maxn];
int n;
int a[maxn];
ll c[maxn];
void add(int x)
{
    for(int i=x;i<=n;i+=lowbit(i))
        c[i]++;
}
ll query(int x)
{
    ll ans=0;
    for(int i=x;i>0;i-=lowbit(i))
        ans+=c[i];
    return ans;
}
int main()
{
    sca(n);
    for(int i=0;i<n;i++)
    {
        sca(x[i].fi);
        x[i].se=i;
    }
    sort(x,x+n);
    for(int i=1;i<=n;i++)
        a[x[i-1].se+1]=i;
    //for(int i=1;i<=n;i++)
    //   printf("%d ",a[i]);
    add(a[1]);
    ll ans=0;
    for(int i=2;i<=n;i++)
    {
        add(a[i]);
        ll temp=i-query(a[i]);
        ans+=temp*(temp+a[i]-i);
    }
    printf("%I64d\n",ans);
}
//2019-04-11 18:06:19.519


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int b[N],c[N];
int n,m;
struct node
{
	int v,id;
	bool friend operator<(node n1,node n2)
	{
		return n1.v<n2.v;
	}
}a[N];
int lowbit(int x)
{
	return x&(-x);
}
void updata(int i,int k)//在第i位置加k
{
	while(i<=n)  //A[i] 包含于 C[i + 2k]、C[(i + 2k) + 2k]...；
	{
		c[i]+=k;
		i+=lowbit(i);
	}
}
int getsum(int i) // 求i-1的和
{
	int res=0;
	while(i>0)
	{
		res+=c[i];
		i-=lowbit(i);
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	memset(c,0,sizeof(c));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].v);
		a[i].id=i;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		b[a[i].id]=i;
	long long sum=0;

	for(int i=1;i<=n;i++)
	{
		long long s1=getsum(n)-getsum(b[i]); //前面比他大个个数
		long long s2=b[i]-1-getsum(b[i]); // 后面比他小的个数
		sum+=s1*s2;
		updata(b[i],1);
	}
	printf("%I64d\n",sum);
	return 0;
} //2020-04-05 13:55:04.153


#include <cstdio>
#include <cstring>
#include<iostream>
#include <algorithm>
#include <iostream>
using namespace std;
#define N 1000005
long long c[N];
long long ans1[N],ans2[N];
struct node
{
    int num,val;
}a[N];
bool cmp1(const node &a,const node &b)
{
    return a.val<b.val;
}
bool cmp2(const node &a,const node &b)
{
    return a.num<b.num;
}
int lowbit(int x)
{
    return x&(-x);
}
void update(int x,long long v)
{
    while(x<N)
    {
        c[x]+=v;
        x+=lowbit(x);
    }
}
long long query(int x)
{
    long long ans=0;
    while(x>0)
    {
        ans+=c[x];
        x-=lowbit(x);
    }
    return ans;
}
main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        memset(c,0,sizeof(c));
        memset(ans1,0,sizeof(ans1));
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i].val);
            a[i].num=i;
        }
        sort(a+1,a+1+n,cmp1);
        for(int i=1;i<=n;i++)
        {
            a[i].val=i;
        }
        sort(a+1,a+1+n,cmp2);
        for(int i=1;i<=n;i++)
        {
            update(a[i].val,1);
            ans1[i]+=i-query(a[i].val);
        }
        long long sum=0;
        memset(c,0,sizeof(c));
        memset(ans2,0,sizeof(ans2));
        for(int i=1;i<=n;i++)
        {
            update(a[i].val,ans1[i]);
            sum+=ans1[i];
            ans2[i]=sum-query(a[i].val);
        }
        sum=0;
        for(int i=1;i<=n;i++)
        {
            sum+=ans2[i];
        }
        printf("%I64d\n",sum);
    }
}
//2019-08-04 11:19:37.278


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
typedef long long ll;
const ll N=1e6+5;
ll x[N],y[N],z[N],pre[N],n;
ll lowbit(ll k) {
	return k&(-k);
}
void update(ll i,ll v) {
	while(i<=n) {
		z[i]+=v;
		i+=lowbit(i);
	}
}
ll getsum(ll i) {
	ll sum=0;
	while(i>0) {
		sum+=z[i];
		i-=lowbit(i);
	}
	return sum;
}
int main() {
	ll i,m,ans=0;
	scanf("%I64d",&n);
	for(i=1; i<=n; i++) {
		scanf("%I64d",&x[i]);
		y[i]=x[i];
	}
	sort(y+1,y+n+1);
	m=unique(y+1,y+n+1)-y-1;
	for(i=1; i<=n; i++)
		x[i]=lower_bound(y+1,y+m+1,x[i])-y;
	for(i=1; i<=n; i++) {
		pre[i]=getsum(n)-getsum(x[i]);
		update(x[i],1);
	}
	memset(z,0,sizeof z);
	for(i=n; i>=1; i--) {
		ans+=getsum(x[i])*pre[i];
		update(x[i],1);
	}
	printf("%I64d",ans);
}//2020-03-16 18:02:58.6


#include<stdio.h>
#include<algorithm>
#include<string.h>
#define N 1000005
typedef long long ll;
using namespace std;

struct Node
{
    int v,id;
}a[N];
bool cmp(Node a,Node b)
{
    return a.v<b.v;
}
int n,b[N]={0},c[N]={0};

int lowbit(int x)
{
    return x&-x;
}
void updata(int i,int x)
{
    while(i<=n)
    {
        c[i]+=x;
        i+=lowbit(i);
    }
}
int getsum(int i)
{
    int res=0;
    while(i)
    {
        res+=c[i];
        i-=lowbit(i);
    }
    return res;
}

int main(void)
{
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i].v);
            a[i].id=i;
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            b[a[i].id]=i;
        }
        ll sum=0;
        memset(c,0,sizeof(c));
        for(int i=1;i<=n;i++)
        {
            ll temp1=i-1-getsum(b[i]);
            ll temp2=b[i]-1-getsum(b[i]);
            sum+=temp1*temp2;
            updata(b[i],1);
        }
        printf("%I64d\n",sum);
    }
    return 0;
}
//2020-03-30 16:23:17.342


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lowbit(x) (x)&(-x)
const int N =1e6+10;
int n;
struct node
{
    ll c[N];
    void init() {memset(c,0,sizeof(c));}
    ll sum(ll x)
    {
        ll ans=0;
        while(x<=n+10)
        {
            ans+=c[x];
            x+=lowbit(x);
        }
        return ans;
    }
    void change(ll x,ll y)
    {
        while(x)
            c[x]+=y,x-=lowbit(x);
    }
}x,y;
int haifei[10000000],panting[1000000];
int main()
{
    ll i,j;
    while(cin>>n)
    {
        ll ans=0;
        for(i=0;i<n;i++) scanf("%d",&haifei[i]),panting[i]=haifei[i];
            x.init(),y.init();
        sort(haifei,haifei+n);
        for(i=0;i<n;i++){
            ll b=(lower_bound(haifei,haifei+n,panting[i])-haifei)+1;
            ll siz=y.sum(b);
            ans+=siz;
            y.change(b,x.sum(b));
            x.change(b,1);
        }
        cout<<ans<<endl;
    }
}//2020-03-31 17:56:43.329


#include<stdio.h>
#include<algorithm>
using namespace std;
struct Node
{
    int v;
    int id;
}a[1000005];
int rank[1000005];
int c[1000005];
int f[1000005];
int d[1000005];
int n;
bool cmp(Node a,Node b)
{
    return a.v<=b.v;
}
void add(int i,int k)
{
    while(i<=n)
    {
        c[i]+=k;
        i+=(i&(-i));
    }
}
int getsum(int i)
{
    int ret=0;
    while(i>0)
    {
        ret+=c[i];
        i-=(i&(-i));
    }
    return ret;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<=n;i++)
        {
            c[i]=0,rank[i]=0,f[i]=0,d[i]=0;
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i].v);
            a[i].id=i;
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            rank[a[i].id]=i;
        }
        for(int i=1;i<=n;i++)
        {
            f[i]=getsum(n)-getsum(rank[i]);
            add(rank[i],1);
        }
        for(int i=0;i<=n;i++)
            c[i]=0;
        long long sum=0;
        for(int i=n;i>=1;i--)
        {
            d[i]=getsum(rank[i]-1);
            add(rank[i],1);
        }
        for(int i=1;i<=n;i++)
            sum+=d[i]*f[i];
        printf("%I64d\n",sum);
    }
    return 0;
}
//2020-05-14 12:05:26.486


#include<bits/stdc++.h>
using namespace std;
struct Node
{
    int v;
    int id;
}a[1000005];
int rank1[1000005];
int c[1000005];
int f[1000005];
int d[1000005];
int n;
bool cmp(Node a,Node b)
{
    return a.v<=b.v;
}
void add(int i,int k)
{
    while(i<=n)
    {
        c[i]+=k;
        i+=(i&(-i));
    }
}
int getsum(int i)
{
    int ret=0;
    while(i>0)
    {
        ret+=c[i];
        i-=(i&(-i));
    }
    return ret;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<=n;i++)
        {
            c[i]=0,rank1[i]=0,f[i]=0,d[i]=0;
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i].v);
            a[i].id=i;
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            rank1[a[i].id]=i;
        }
        for(int i=1;i<=n;i++)
        {
            f[i]=getsum(n)-getsum(rank1[i]);
            add(rank1[i],1);
        }
        for(int i=0;i<=n;i++)
            c[i]=0;
        long long sum=0;
        for(int i=n;i>=1;i--)
        {
            d[i]=getsum(rank1[i]-1);
            add(rank1[i],1);
        }
        for(int i=1;i<=n;i++)
            sum+=d[i]*f[i];
        printf("%I64d\n",sum);
    }
    return 0;
}
//2020-05-14 12:51:02.403


#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>vec;
const int maxn=1e6+5;
int str[maxn],q[maxn],h[maxn];
int c[maxn];
int n;
int lowbit(int x)
{
    return x&(-x);
}
int getsum(int x)
{
    int sum=0;
    while(x>0)
    {
        sum+=c[x];
        x-=lowbit(x);
    }
    return sum;
}
void updata(int x)
{
    while(x<=n)
    {
        c[x]++;
        x+=lowbit(x);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&str[i]),vec.push_back(str[i]);
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    for(int i=n; i>=1; i--)
    {
        int pos=lower_bound(vec.begin(),vec.end(),str[i])-vec.begin()+1;
        q[i]=getsum(pos);
        h[i]=(n-pos)-((n-i)-q[i]);
        updata(pos);
    }
    int ans=0;

    for(int i=1; i<=n; i++)
        ans+=q[i]*h[i];
    printf("%d\n",ans);
    return 0;
}
//2019-08-04 11:57:59.486


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll v[500005],k[500005],brr[500005],crr[500005];
ll n,m,a,b,c;
struct node
{
    ll pos,val;
}arr[400005];
int cmp(node a,node b)
{
    return a.val<b.val;
}
ll lowbit(ll x)
{
    return x&(-x);
}
void build(int x,int y)
{
    while(x<=n)
    {
        k[x]+=y;
        x+=lowbit(x);
    }
}
ll updata(int x)
{
    ll ans=0;
    while(x)
    {
        ans+=k[x];
        x-=lowbit(x);
    }
    return ans;
}
int main()
{
    while(~scanf("%lld",&n))
    {
        if(n==0)break;
        memset(v,0,sizeof v);
        memset(k,0,sizeof k);
        memset(brr,0,sizeof brr);
        memset(crr,0,sizeof crr);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&arr[i].val);
            arr[i].pos=i;
        }
        sort(arr+1,arr+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            v[arr[i].pos]=i;
        }
        for(int i=1;i<=n;i++)
        {
            crr[i]=i-1-updata(v[i]);
            build(v[i],1);
        }
        memset(k,0,sizeof k);
        for(int i=n;i>0;i--)
        {
            brr[i]=updata(v[i]);
            build(v[i],1);
        }
        ll ans=0;
        for(int i=1;i<=n;i++)
        {
            ans+=brr[i]*crr[i];
        }
        printf("%lld\n",ans);
    }
}
//2020-05-14 14:36:13.16


#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long
struct Node
{
    int v;
    int id;
}a[1000005];
int rank[1000005];
int c[1000005];
int f[1000005];
int d[1000005];
int n;
bool cmp(Node a,Node b)
{
    return a.v<=b.v;
}
void add(int i,int k)
{
    while(i<=n)
    {
        c[i]+=k;
        i+=(i&(-i));
    }
}
ll getsum(int i)
{
    ll ret=0;
    while(i>0)
    {
        ret+=c[i];
        i-=(i&(-i));
    }
    return ret;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<=n;i++)
        {
            c[i]=0,rank[i]=0,f[i]=0;
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i].v);
            a[i].id=i;
        }
        sort(a+1,a+n+1,cmp);
        ll s=0;
        for(int i=1;i<=n;i++)
        {
            rank[a[i].id]=i;
        }
        for(int i=1;i<=n;i++)
        {
            f[i]=getsum(n)-getsum(rank[i]);
            add(rank[i],1);
        }
        for(int i=0;i<=n;i++)
            c[i]=0;
        ll sum=0;
        for(int i=n;i>=1;i--)
        {
            d[i]=getsum(rank[i]-1);
            add(rank[i],1);
        }
        for(int i=1;i<=n;i++)
            sum+=d[i]*f[i];
        printf("%I64d\n",sum);
    }
}
//2020-05-14 10:35:50.02


#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>vec;
const int maxn=1e6+5;
long long  str[maxn],q[maxn],h[maxn];
long long  c[maxn];
int n;
int lowbit(int x)
{
    return x&(-x);
}
long long  getsum(int x)
{
    long long  sum=0;
    while(x>0)
    {
        sum+=c[x];
        x-=lowbit(x);
    }
    return sum;
}
void updata(int x)
{
    while(x<=n)
    {
        c[x]++;
        x+=lowbit(x);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%I64d",&str[i]),vec.push_back(str[i]);
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    for(int i=n; i>=1; i--)
    {
        int pos=lower_bound(vec.begin(),vec.end(),str[i])-vec.begin()+1;
        q[i]=getsum(pos);
        h[i]=(n-pos)-((n-i)-q[i]);
        updata(pos);
    }
    long long  ans=0;
    for(int i=1; i<=n; i++)
        ans+=q[i]*h[i];
    printf("%I64d\n",ans);
    return 0;
}
//2019-08-04 12:00:34.505


#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll N=1e6+5;
ll n,sum[N],l[N],r[N],f[N];
struct Node
{
    ll value,idx;
    bool operator<(const Node &tt)const
    {
        return value<tt.value;
    }
} node[N];
ll lowerbit(ll x)
{
    return x&(-x);
}
void update(ll x,ll v)
{
    while(x<=n)
    {
        sum[x]+=v;
        x+=lowerbit(x);
    }
}
ll query(ll x)
{
    ll ans=0;
    while(x>0)
    {
        ans+=sum[x];
        x-=lowerbit(x);
    }
    return ans;
}
int main()
{
    while(~scanf("%I64d",&n))
    {
        memset(sum,0,sizeof(sum));
        for(ll i=1; i<=n; i++)
        {
            scanf("%I64d",&node[i].value);
            node[i].idx=i;
        }
        sort(node+1,node+1+n);
        for(ll i=1;i<=n;i++)
        {
            f[node[i].idx]=i;
        }

        ll temp=0;

        update(f[1],1);
        for(ll i=2; i<n; i++)
        {
            l[i]=i-query(f[i])-1;
            r[i]=n-(n-f[i])-(i-l[i]);
            //printf("%I64d %I64d\n",l[i],r[i]);
            temp+=l[i]*r[i];
            update(f[i],1);
        }
        printf("%I64d\n",temp);
    }
    return 0;
}//2020-03-15 20:18:39.751


#include <bits/stdc++.h>

using namespace std;

#define LL long long

const int N = 1e6+5;

LL c1[N],c2[N];
int a[N],t[N],n;

int lowbit(int x)
{
    return x & (-x);
}

void update(LL c[],int i,int x)
{
    while(i <= n)
    {
        c[i] += x;
        i += lowbit(i);
    }
}

LL query(LL c[],int i)
{
    LL res = 0;

    while(i > 0)
    {
        res += c[i];
        i -= lowbit(i);
    }

    return res;
}

int main()
{
    int n;

    scanf("%d",&n);

    for(int i = 1;i <= n;i ++)
    {
        scanf("%d",&a[i]);
        t[i] = a[i];
    }

    sort(t + 1,t + 1 + n);
    int m = unique(t + 1,t + 1 + n) - t - 1;

    for(int i = 1;i <= n;i ++)
        a[i] = lower_bound(t + 1,t + 1 + n,a[i]) - t;

    update(c1,a[n],1);

    LL res = 0,sum = 0;

    for(int i = n - 1;i > 0;i --)
    {
        sum = query(c1,a[i] - 1);

        update(c1,a[i],1);
        update(c2,a[i],sum);

        res += query(c2,a[i] - 1);
    }

    cout << res << '\n';

    return 0;
}
//2020-03-13 18:57:22.88


#include <bits/stdc++.h>
using namespace std;
const int AX = 1e6+666;
struct Node{
	int pos;
	int val;
}node[AX];
int formerBiger[AX];
int laterSmaller[AX];
int flect[AX];
int c[AX];
	int n;
bool cmp(Node a,Node b){
	return a.val<b.val;
}
int lowbit(int x){
	return x&(-x);
}
void update(int value,int site){
	while(site<=n){
		c[site] += value;
		site += lowbit(site);
	}
}
int getsum(int i){
	int sum = 0;
	while(i>=1){
		sum += c[i];
		i -= lowbit(i);
	}
	return sum;
}
int main(){
	while(cin>>n){
	if(n==0) break;
	long long ans = 0;
	memset(node,0,sizeof(node));
	memset(flect,0,sizeof(flect));
	memset(c,0,sizeof(c));
	for(int i=1;i<=n;i++){
		cin>>node[i].val;
		node[i].pos = i;
	}
	sort(node+1,node+n+1,cmp);
	for(int i=1;i<=n;i++){
		flect[node[i].pos] = i;
	}
	for(int i=1;i<=n;i++){
		update(1,flect[i]);
		formerBiger[i] = i-getsum(flect[i]);     //一个数前面比他大的数
	}
	memset(c,0,sizeof(c));
	for(int i=n;i>=1;i--){
		update(1,flect[i]);
		laterSmaller[i] = getsum(flect[i])-1;    //一个数后面比他小的数的数量
	}

	for(int i=1;i<=n;i++){
		ans += (long long)formerBiger[i]*laterSmaller[i];  //这里强制转化一下long long，或者数组就设									//置为long long，不然会WA。
	}
	cout<<ans<<endl;
	}
	return 0;
}
//2020-05-14 14:47:32.061


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1000005],b[1000005],c[1000005],n;
ll q[1000005],h[1000005];
ll sum(ll x){

    ll ans=0;
    while(x){
     ans+=c[x];
     x-=x&(-x);
    }
    return ans;
}
void update(ll x)
{
    while(x<=n){
      c[x]++;
      x+=x&(-x);
    }
}
int main(){

    cin>>n;
    for(int i=1;i<=n;i++){
      cin>>a[i];
      b[i]=a[i];

    }
    sort(b+1,b+1+n);
    int m=unique(b+1,b+1+n)-b;
    for(int i=1;i<=n;i++){

        a[i]=lower_bound(b+1,b+1+m,a[i])-b;
        q[i]=i-1-sum(a[i]);
        update(a[i]);
        q[i]+=q[i-1];
    }
    memset(c,0,sizeof c);
    for(int i=n;i>0;i--){

        h[i]=sum(a[i]-1);
        update(a[i]);
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
        ans+=q[i]*h[i];
        cout<<ans<<endl;

}
//2019-08-04 11:50:43.582


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#define N 1000010
using namespace std;
int n,a[N],tree[N],f[N];
long long g[N],l[N];
struct node
{
    int id,data;
}s1[N];
struct Node
{
    int id,data;
}s2[N];
bool cmp1(const node &t1,const node &t2)
{
    return t1.data<t2.data;
}
bool cmp2(const Node &t1,const Node &t2)
{
    return t1.id<t2.id;
}
int lowbit(int x)
{
    return x&(-x);
}
void add(int x,int y)
{
    while(x<=N)
    {
        tree[x]+=y;
        x+=lowbit(x);
    }
}
int sum(int x)
{
    int ans=0;
    while(x>0)
    {
        ans+=tree[x];
        x-=lowbit(x);
    }
    return ans;
}
int main(void)
{
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
       scanf("%d",&s1[i].data);
       s1[i].id=i;
   }
   sort(s1+1,s1+n+1,cmp1);
   int num=1;
   for(int i=1;i<=n;i++)
   {
       s2[i].id=s1[i].id;
       s2[i].data=num++;
   }
   sort(s2+1,s2+n+1,cmp2);
   for(int i=1;i<=n;i++)
       a[i]=s2[i].data;
    memset(tree,0,sizeof(tree));
    for(int i=1;i<=n;i++)//左边几个小于的数
    {
        add(a[i],1);
        g[i]=i-sum(a[i]);
    }
    memset(tree,0,sizeof(tree));
    for(int i=n;i>0;i--)//右边几个大于的数
    {
        add(a[i],1);
        f[n-i+1]=n-i+1-sum(a[i]);
        l[n-i+1]=n-i-f[n-i+1];
    }
    long long sum=0;
    for(int i=1;i<=n;i++)//前后相乘即为结果
    {
        sum+=g[i]*l[n-i+1];
    }
    printf("%I64d\n",sum);
}
//2020-03-27 11:41:11.38


#include <bits/stdc++.h>
using namespace std;
int n;
struct node
{
    int x,y;
    bool operator<(const node a)const
    {
        return x<a.x;
    }
} aa[1000005];
int a[1000005];
int l[1000005];
int r[1000005];
int c[1000005];
int lowbit(int x)
{
    return x&(-x);
}
void update(int x,int k)
{
    while(x<=n+2)
    {
        c[x]=c[x]+k;
        x=x+lowbit(x);
    }
}
long long getsum(int x)
{
    long long res=0;
    while(x>0)
    {
        res+=c[x];
        x=x-lowbit(x);
    }
    return res;
}
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&aa[i].x);
        aa[i].y=i;
    }
    sort(aa+1,aa+1+n);
    for(int i=1; i<=n; i++)
    {
        a[aa[i].y]=i;
    }
    for(int i=1; i<=n; i++)
    {
        update(a[i],1);
        l[i]=i-getsum(a[i]);
        r[i]=getsum(a[i]-1);
    }
    long long ans=0;
    for(int i=1; i<=n; i++)
    {
        r[i]=getsum(a[i]-1)-r[i];
        ans=ans+(long long)l[i]*r[i];
    }
    printf("%I64d\n",ans);
}
//2020-04-02 10:53:17.053


#include<bits/stdc++.h>
using namespace std;
struct Node
{
    int v;
    int id;
}a[1000005];
int rank1[1000005];
int c[1000005];
int f[1000005];
int d[1000005];
int n;
bool cmp(Node a,Node b)
{
    return a.v<=b.v;
}
void add(int i,int k)
{
    while(i<=n)
    {
        c[i]+=k;
        i+=(i&(-i));
    }
}
int getsum(int i)
{
    int ret=0;
    while(i>0)
    {
        ret+=c[i];
        i-=(i&(-i));
    }
    return ret;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<=n;i++)
        {
            c[i]=0,rank1[i]=0,f[i]=0,d[i]=0;
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i].v);
            a[i].id=i;
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            rank1[a[i].id]=i;
        }
        for(int i=1;i<=n;i++)
        {
                    add(rank1[i],1);
            f[i]=i-getsum(rank1[i]);
        }
        for(int i=0;i<=n;i++)
            c[i]=0;
        long long sum=0;
        for(int i=n;i>=1;i--)
        {
            d[i]=getsum(rank1[i]);
            add(rank1[i],1);
        }
        for(int i=1;i<=n;i++)
            sum+=d[i]*f[i];
        printf("%I64d\n",sum);
    }
    return 0;
}
//2020-05-14 14:32:39.16


#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long
struct Node
{
    ll v;
    int id;
}a[1000005];
int rank[100005];
int c[1000005];
int f[1000005];
int d[1000005];
int n;
bool cmp(Node a,Node b)
{
    return a.v<=b.v;
}
void add(int i,int k)
{
    while(i<=n)
    {
        c[i]+=k;
        i+=(i&(-i));
    }
}
ll getsum(int i)
{
    ll ret=0;
    while(i>0)
    {
        ret+=c[i];
        i-=(i&(-i));
    }
    return ret;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<=n;i++)
        {
            c[i]=0,rank[i]=0,f[i]=0;
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i].v);
            a[i].id=i;
        }
        sort(a+1,a+n+1,cmp);
        ll s=0;
        for(int i=1;i<=n;i++)
        {
            rank[a[i].id]=i;
        }
        for(int i=1;i<=n;i++)
        {
            f[i]=getsum(n)-getsum(rank[i]);
            add(rank[i],1);
        }
        for(int i=0;i<=n;i++)
            c[i]=0;
        ll sum=0;
        for(int i=n;i>=1;i--)
        {
            d[i]=getsum(rank[i]-1);
            add(rank[i],1);
        }
        for(int i=1;i<=n;i++)
            sum+=d[i]*f[i];
        printf("%I64d\n",sum);
    }
}
//2020-05-14 10:01:30.694


#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,x,a,b,ans=0;
    cin >> n >> a >> b;
    for(int i=0; i<n; i++){
        cin >> x;
        if(x<=a)ans++;
    }
    if(a>b)cout << ans << endl;
    else cout << (ans+1) / 2;

}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,x,y,ans=0;
    cin >> n >> x >> y;
    int arr[n+5];
    for(int i=0; i<n; i++){
        cin >> arr[i];
    }
    for(int i=0; i<n; i++){
        int m,temp;
        m = arr[i];
        temp = m;
        if(m<=x)ans++;
        else {
            bool masih=true,habis=true;
            while(masih){
                m-=x;
                m+=y;
                if(m>=temp){
                    masih=false;
                    habis=false;
                } else if(m<=0){
                    masih=false;
                }
            }
            if(habis)ans++;
            else break;
        }
    }
    cout << ans << endl;

}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,x,a,b,ans=0;
    cin >> n >> a >> b;
    for(int i=0; i<n; i++){
        cin >> x;
        if(x<=a)ans++;
    }
    if(a>b)cout << n << '\n';
    else cout << (ans+1) / 2 << '\n';

}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,x,a,b,ans=0;
    cin >> n >> a >> b;
    for(int i=0; i<n; i++){
        cin >> x;
        if(x<=a)ans++
    }
    if(a>b)cout << ans << endl;
    else cout << (ans+1) / 2;

}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int x,y,n,i;
    cin>>n>>x>>y;
    int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    if(x>y){
        cout<<n;
        return 0;
    }
    sort(a,a+n);
    int c=0;
    for(i=0;i<n;i++)
    {
        if(a[i]<min(x,y))
        c++;
    }
    cout<<ceil(1.0*(c)/2);
        return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int x,y,n,i;
    cin>>n>>x>>y;
    int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    if(x>y){
        cout<<n;
        return 0;
    }
    sort(a,a+n);
    int count=0;
    for(i=0;i<n;i++)
    {
        if(a[i]<min(x,y))
        count++;
    }
    cout<<ceil(1.0*(count)/2);
        return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int x,y,n,i;
    cin>>n>>x>>y;
    int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    if(x>y){
        cout<<n;
        return 0;
    }
    sort(a,a+n);
    int count=0;
    for(i=0;i<n;i++)
    {
        if(a[i]<=min(x,y))
        count++;
    }
    cout<<ceil(1.0*(count)/2);
        return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int x,y,n,i;
    cin>>n>>x>>y;
    int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    if(x>y){
        cout<<n;
        return 0;
    }
    sort(a,a+n);
    int count=0;
    for(i=0;i<n;i++)
    {
        if(a[i]<=min(x,y))
        count++;
    }
    cout<<floor(1.0*(count)/2);
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ll n,x,y;
    cin>>n>>x>>y;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    if(x>y)
    {
        cout<<n;
    }

    if(x<=y)
    {
        ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]<=x)
            {
                cnt++;
            }
        }
        if(cnt>=2)
        {
            cout<<2<<endl;
        }
        if(cnt==1)
        {
            cout<<1<<endl;
        }
        if(cnt<=0)
        {
            cout<<0<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ll n,x,y;
    cin>>n>>x>>y;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    if(x>y)
    {
        cout<<n;
    }
    if(x==y)
    {
        ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]<=x)
            {
                cnt++;
            }
        }
        if(cnt&1)
        {
            cout<<cnt/2 + 1<<endl;

        }
        else
        {
            cout<<cnt/2;
        }
    }
    if(x<y)
    {
        ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]<=x)
            {
                cnt++;
            }
        }
        if(cnt>=2)
        {
            cout<<2<<endl;
        }
        if(cnt==1)
        {
            cout<<1<<endl;
        }
        if(cnt<=0)
        {
            cout<<0<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ll n,x,y;
    cin>>n>>x>>y;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    if(x>y)
    {
        cout<<n;
    }
    if(x==y)
    {
        ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]<=x)
            {
                cnt++;
            }
        }
        cout<<cnt/2<<endl;
    }
    if(x<y)
    {
        ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]<=x)
            {
                cnt++;
            }
        }
        if(cnt>=2)
        {
            cout<<2<<endl;
        }
        if(cnt==1)
        {
            cout<<1<<endl;
        }
        if(cnt<=0)
        {
            cout<<0<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ll n,x,y;
    cin>>n>>x>>y;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    if(x>y)
    {
        cout<<n;
    }
    if(x<=y)
    {
        ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]<=x)
            {
                cnt++;
            }
        }
        if(cnt&1)
        {
            cout<<cnt/2 + 1<<endl;

        }
        else
        {
            cout<<cnt/2;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,y,c=0;
    scanf("%d%d%d",&n,&x,&y);
    for(int i=0;i<n;i++)
    {
        int k;
        scanf("%d",&k);
        if(k<=x)
        c++;
    }
    if(x>y)
    printf("%d",n);
    else
    printf("%d",(c+1)/2);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,y,c=0;
    scanf("%d%d%d",&n,&x,&y);
    for(int i=0;i<n;i++)
    {
        int k;
        scanf("%d",&k);
        if(k<x)
        c++;
    }
    if(x>y)
    printf("%d",n);
    else
    printf("%d",(c+1)/2);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,y,i;
    scanf("%d%d%d",&n,&x,&y);
    int c=0;
    for(i=0;i<n;i++)
    {
        int k;
        scanf("%d",&k);
        if(k<x)
        c++;
    }
    if(x>y)
    printf("%d",n);
    else
    printf("%d",(c+1)/2);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,y;
    scanf("%d%d%d",&n,&x,&y);
    for(i=0;i<n;i++)
    {
        int k;
        scanf("%d",&k);
        if(k<x)
        c++:
    }
    if(x>y)
    printf("%d",n);
    else
    printf("%d",c+1/2);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<x)
		{
			ctr1++;
		}
		else
		{
			ctr2++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		printf("%d",(ctr1-1));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==x)
		{
			ctr1++;
		}
		else if(a[i]<x)
		{
			ctr2++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		if(x<y)
		printf("%d",(ctr2/2+1)+ctr1);
		else
		printf("%d",(ctr2/2)+ctr1);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==x)
		{
			ctr1++;
		}
		else if(a[i]<x)
		{
			ctr2++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		if(x==y)
		printf("%d",(ctr2/2+1)+ctr1);
		else
		printf("%d",(ctr2/2)+ctr1);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==x)
		{
			ctr1++;
		}
		else if(a[i]<x)
		{
			ctr2++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		if(x==y)
		printf("%d",(ctr2/2+1)+ctr1);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i,ans;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==x)
		{
			ctr1++;
		}
		else if(a[i]<x)
		{
			ctr2++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		if(x<y)
		{
			 ans=((ctr2+ctr1)/2)+1;
			printf("%d",ans);
		}
		else
		{
			ans=(ctr2+ctr1)/2;
			printf("%d",ans);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<=x)
		{
			ctr1++;
		}
		else
		{
			ctr2++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		if(x!=y)
		printf("%d",(ctr1/2+1));
		else
		printf("%d",(ctr1/2));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i,ans;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==x)
		{
			ctr1++;
		}
		else if(a[i]<x)
		{
			ctr2++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		if(x<y)
		{
			 ans=((ctr2+ctr1)/2)+1;
			printf("%d",ans);
		}
		else
		{
			ans=(ctr2+ctr1)/2;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i,ans;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<=x)
		{
			ctr1++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		ans=ceil((ctr1)/2);
		printf("%d",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i,ans;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<=x)
		{
			ctr1++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		if(ctr1%2==0)
		{
			printf("%d",ctr1/2);
		}
		else
		{
			printf("%d",ctr1/2+1);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==x)
		{
			ctr1++;
		}
		else if(a[i]<x)
		{
			ctr2++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		if(x==y)
		printf("%d",(ctr2+ctr1)/2+1);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i,ans;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<=x)
		{
			ctr1++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		ans=ceil((1.0)*(ctr1)/2);
		printf("%d",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y,ctr1=0,ctr2=0,i;
	scanf("%d%d%d",&n,&x,&y);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==x)
		{
			ctr1++;
		}
		else if(a[i]<x)
		{
			ctr2++;
		}
	}
	if(x>y)
	{
		printf("%d",n);
	}
	else
	{
		if(x<=y)
		{
			int ans=((ctr2+ctr1)/2)+1;
			printf("%d",ans);
		}
	}
	return 0;
}