stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int N=1e5+5;

inline ll read(){ll x=0,f=1;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-48;return x*f;}

inline void write(ll x){if(x>9)write(x/10);putchar('0'+x%10);}

inline void writeln(ll x){write(x);puts("");}

ll a[N],b[N],c[N];

ll sa[N],sb[N],sc[N];

ll n;

int main()

{

	n=read();

	for(int i=1;i<=n;i++){

		a[i]=read();

		sa[i]=1;

	}

	for(int i=1;i<=n;i++)

		b[i]=read();

	for(int i=1;i<=n;i++)

		c[i]=read();

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

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

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

	for(int i=1;i<=n;i++)

		sa[i]+=sa[i-1];

	for(int i=1;i<=n;i++){

		int k=lower_bound(a+1,a+n+1,b[i])-a-1;

		sb[i]=sa[k];

	}

	for(int i=1;i<=n;i++)

		sb[i]+=sb[i-1];

	for(int i=1;i<=n;i++){

		int k=lower_bound(b+1,b+n+1,c[i])-b-1;

		sc[i]=sb[k];

	}

	for(int i=1;i<=n;i++)

		sc[i]+=sc[i-1];

	writeln(sc[n]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.127712199831413x):
#include<stdio.h>

#include<algorithm>

using namespace std;

#define MAXN 100010

int a[MAXN], b[MAXN], c[MAXN];

int main()

{

	int N;

	scanf("%d", &N);

	for (int i = 0; i < N; i++)

	{

		scanf("%d", &a[i]);

	}

	for (int i = 0; i < N; i++)

	{

		scanf("%d", &b[i]);

	}

	for (int i = 0; i < N; i++)

	{

		scanf("%d", &c[i]);

	}

	sort(a, a + N);

	sort(b, b + N);

	sort(c, c + N);

	long long ai=0, ci=0;

	long long sum = 0;

	for (int i = 0; i < N; i++)

	{

		while (a[ai] < b[i] && ai< N)

		{

			ai++;

		}

		while (c[ci] <= b[i] && ci<N)

		{

			ci++;

		}

		sum += ai*(N-ci);

	}

	printf("%lld\n", sum);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define For(i,a,b) for (int i=a;i<=b;i++)

#define Rep(i,a,b) for (int i=b;i>=a;i--)

using namespace std;

ll ans;

ll n,x,y;

int a[100100],b[100100],c[100100];

inline ll read()

{

    ll x=0,f=1;char ch=getchar();

    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();

    return x*f;

}

int main()

{

	n=read();

	For(i,1,n)a[i]=read();

	For(i,1,n)b[i]=read();

	For(i,1,n)c[i]=-read();

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

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

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

	For(i,1,n)c[i]=-c[i];

	x=0;y=n;

	For(i,1,n)

	{

		while(a[x+1]<b[i]&&x<n)x++;

		while(c[y]<=b[i]&&y>0)y--;

		ans+=(x*y);

	}

	cout<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.203790881700107x):
#include<stdio.h>

#include<algorithm>

using namespace std;

#define MAXN 100010

int a[MAXN], b[MAXN], c[MAXN];

int main()

{

	int N;

	scanf("%d", &N);

	for (int i = 0; i < N; i++)

	{

		scanf("%d", &a[i]);

	}

	for (int i = 0; i < N; i++)

	{

		scanf("%d", &b[i]);

	}

	for (int i = 0; i < N; i++)

	{

		scanf("%d", &c[i]);

	}

	sort(a, a + N);

	sort(b, b + N);

	sort(c, c + N);

	long long ai=0, ci=0;

	long long sum = 0;

	for (int i = 0; i < N; i++)

	{

		while (a[ai] < b[i] && ai< N)

		{

			ai++;

		}

		while (c[ci] <= b[i] && ci<N)

		{

			ci++;

		}

		sum += ai*(N-ci);

	}

	printf("%lld\n", sum);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define N 100005

using namespace std;

int n,tot,a[N],b[N],c[N],e[N],d[N*3];

ll ans,v[N*3];

void add(int x,ll y){

	for (;x<=tot;x+=x&(-x)) v[x]+=y;

}

ll ask(int x){

	ll s=0;

	for (;x;x-=x&(-x)) s+=v[x];

	return s; 

}

int main(){

	scanf("%d",&n);

	for (int i=1;i<=n;i++)

		scanf("%d",&a[i]),d[++tot]=a[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&b[i]),d[++tot]=b[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&c[i]),d[++tot]=c[i];

	sort(d+1,d+tot+1);

	for (int i=1;i<=n;i++){

		a[i]=lower_bound(d+1,d+tot+1,a[i])-d;

		add(a[i],1);

	}

	for (int i=1;i<=n;i++){

		b[i]=lower_bound(d+1,d+tot+1,b[i])-d;

		e[i]=ask(b[i]-1);

	}

	memset(v,0,sizeof(v));

	for (int i=1;i<=n;i++)

		add(b[i],e[i]);

	for (int i=1;i<=n;i++){

		c[i]=lower_bound(d+1,d+tot+1,c[i])-d;

		ans+=ask(c[i]-1);

	}

	printf("%lld",ans);

}

// Faster C++ solution for the same problem (measured speedup: 3.439288129103448x):
#include<algorithm>

#include<iostream>

#include<cstring>

#include<string>

#include<cstdio>

#include<vector>

#include<stack>

#include<cmath>

#include<queue>

#include<set>

#include<map>

#define N 100100

#define LL long long



using namespace std;



int a[N],b[N],c[N];

LL A[N],B[N];



int main()

{

	int n;

	scanf ("%d",&n);

	for (int i=1;i<=n;i++)

		scanf ("%d",&a[i]);

	for (int i=1;i<=n;i++)

		scanf ("%d",&b[i]);

	for (int i=1;i<=n;i++)

		scanf ("%d",&c[i]);

	

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

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

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

	

	int loc = 1;

	for (int i=1;i<=n;i++)

	{

		while (loc <= n && b[i]>a[loc])

			loc ++;

		B[i] = loc-1;

	}

	

	loc = 1;

	LL ans = 0,tmp = 0;

	for (int i=1;i<=n;i++)

	{

		while (loc <= n && c[i]>b[loc])

			tmp += B[loc++];

		ans += tmp;

	}

	

	printf ("%lld\n",ans);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define N 100005

using namespace std;

int n,tot,a[N],b[N],c[N],e[N],d[N*3];

ll ans,v[N*3];

void add(int x,ll y){

	for (;x<=tot;x+=x&(-x)) v[x]+=y;

}

ll ask(int x){

	ll s=0;

	for (;x;x-=x&(-x)) s+=v[x];

	return s; 

}

int main(){

	scanf("%d",&n);

	for (int i=1;i<=n;i++)

		scanf("%d",&a[i]),d[++tot]=a[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&b[i]),d[++tot]=b[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&c[i]),d[++tot]=c[i];

	sort(d+1,d+tot+1);

	for (int i=1;i<=n;i++){

		a[i]=lower_bound(d+1,d+tot+1,a[i])-d;

		add(a[i],1);

	}

	for (int i=1;i<=n;i++){

		b[i]=lower_bound(d+1,d+tot+1,b[i])-d;

		e[i]=ask(b[i]-1);

	}

	memset(v,0,sizeof(v));

	for (int i=1;i<=n;i++)

		add(b[i],e[i]);

	for (int i=1;i<=n;i++){

		c[i]=lower_bound(d+1,d+tot+1,c[i])-d;

		ans+=ask(c[i]-1);

	}

	printf("%lld",ans);

}

// Faster C++ solution for the same problem (measured speedup: 3.390388229725307x):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#define rep(i,l,p) for(int i=l;i<=p;i++)

using namespace std;

const int maxN = 1e5+5;





int a[maxN],b[maxN],c[maxN];

int N;

int cnt_b[maxN],cnt_c[maxN];

long long sum[maxN];

bool cmp(const int &a,const int &b){

	return a>b;

}



void input(){

	int t;

	rep(i,1,N) cin >> a[i];

	rep(i,1,N) cin >> b[i];

	rep(i,1,N) cin >> c[i]; 

	sort(a+1,a+1+N,cmp);

	sort(b+1,b+1+N,cmp);

	sort(c+1,c+1+N,cmp);

	int bt = 0,ct = 0;

	rep(i,1,N){

		

		rep(j,bt+1,N){

			if ( b[j] > a[i] ) bt++;

			else break;	

		}

		cnt_b[i] = bt;

	

		rep(j,ct+1,N){

			if ( c[j] > b[i] ) ct++;

			else break;

		}

		

		cnt_c[i] = ct;

	}

	rep(i,1,N) sum[i] = sum[i-1] + cnt_c[i];

//	rep(i,1,N) printf("cntb: %d  cntc: %d\n",cnt_b[i],cnt_c[i]);

}

void solve(){

	long long res = 0;



	rep(i,1,N){

		int a = i,b = cnt_b[i];

		res += sum[b];

	

	}

	printf("%lld\n",res);

}

int main(){

	scanf("%d",&N);

	

	input();

	solve();

	

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define N 100005

using namespace std;

int n,tot,a[N],b[N],c[N],e[N],d[N*3];

ll ans,v[N*3];

void add(int x,ll y){

	for (;x<=tot;x+=x&(-x)) v[x]+=y;

}

ll ask(int x){

	ll s=0;

	for (;x;x-=x&(-x)) s+=v[x];

	return s; 

}

int main(){

	scanf("%d",&n);

	for (int i=1;i<=n;i++)

		scanf("%d",&a[i]),d[++tot]=a[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&b[i]),d[++tot]=b[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&c[i]),d[++tot]=c[i];

	sort(d+1,d+tot+1);

	for (int i=1;i<=n;i++){

		a[i]=lower_bound(d+1,d+tot+1,a[i])-d;

		add(a[i],1);

	}

	for (int i=1;i<=n;i++){

		b[i]=lower_bound(d+1,d+tot+1,b[i])-d;

		e[i]=ask(b[i]-1);

	}

	memset(v,0,sizeof(v));

	for (int i=1;i<=n;i++)

		add(b[i],e[i]);

	for (int i=1;i<=n;i++){

		c[i]=lower_bound(d+1,d+tot+1,c[i])-d;

		ans+=ask(c[i]-1);

	}

	printf("%lld",ans);

}

// Faster C++ solution for the same problem (measured speedup: 17.748530808868704x):
#include<stdio.h>

#include<algorithm>

#define ll long long

using namespace std;



const int maxn = 1e6+20;

ll a[maxn],b[maxn],c[maxn];



int main()

{

    ll n;

    scanf("%lld",&n);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&a[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&b[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&c[i]);

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

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

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

    ll ans = 0;

    ll numa = 0,numc = 0;

    for(int i = 1 ; i <= n ; i ++)

    {

        while(a[numa+1] < b[i] && numa+1 <= n) numa ++;

        while(c[numc+1] <= b[i] && numc+1 <= n) numc ++;

        ans += numa*(n-numc);

    }

    printf("%lld\n",ans);

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;

const int N = 100005;

int a[N], b[N], c[N];

int main()

{

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	for (int i = 1; i <= n; i++)

		cin >> a[i];

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

	for (int i = 1; i <= n; i++)

		cin >> b[i];

	for (int i = 1; i <= n; i++)

		cin >> c[i];

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

	long long ans = 0;

	for (int i = 1; i <= n; i++)

		ans += 1ll * (lower_bound(a + 1, a + n + 1, b[i]) - a - 1) * (n - (upper_bound(c + 1, c + n + 1, b[i]) - c) + 1);

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.282277330165591x):
#include<stdio.h>

#include<algorithm>

#define ll long long

using namespace std;



const int maxn = 1e6+20;

ll a[maxn],b[maxn],c[maxn];



int main()

{

    ll n;

    scanf("%lld",&n);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&a[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&b[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&c[i]);

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

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

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

    ll ans = 0;

    ll numa = 0,numc = 0;

    for(int i = 1 ; i <= n ; i ++)

    {

        while(a[numa+1] < b[i] && numa+1 <= n) numa ++;

        while(c[numc+1] <= b[i] && numc+1 <= n) numc ++;

        ans += numa*(n-numc);

    }

    printf("%lld\n",ans);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int N=1e5+5;

inline ll read(){ll x=0,f=1;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-48;return x*f;}

inline void write(ll x){if(x>9)write(x/10);putchar('0'+x%10);}

inline void writeln(ll x){write(x);puts("");}

ll a[N],b[N],c[N];

ll sa[N],sb[N],sc[N];

ll n;

int main()

{

	n=read();

	for(int i=1;i<=n;i++){

		a[i]=read();

		sa[i]=1;

	}

	for(int i=1;i<=n;i++)

		b[i]=read();

	for(int i=1;i<=n;i++)

		c[i]=read();

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

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

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

	for(int i=1;i<=n;i++)

		sa[i]+=sa[i-1];

	for(int i=1;i<=n;i++){

		int k=lower_bound(a+1,a+n+1,b[i])-a-1;

		sb[i]=sa[k];

	}

	for(int i=1;i<=n;i++)

		sb[i]+=sb[i-1];

	for(int i=1;i<=n;i++){

		int k=lower_bound(b+1,b+n+1,c[i])-b-1;

		sc[i]=sb[k];

	}

	for(int i=1;i<=n;i++)

		sc[i]+=sc[i-1];

	writeln(sc[n]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.131131966709523x):
#include<stdio.h>

#include<algorithm>

#define ll long long

using namespace std;



const int maxn = 1e6+20;

ll a[maxn],b[maxn],c[maxn];



int main()

{

    ll n;

    scanf("%lld",&n);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&a[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&b[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&c[i]);

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

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

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

    ll ans = 0;

    ll numa = 0,numc = 0;

    for(int i = 1 ; i <= n ; i ++)

    {

        while(a[numa+1] < b[i] && numa+1 <= n) numa ++;

        while(c[numc+1] <= b[i] && numc+1 <= n) numc ++;

        ans += numa*(n-numc);

    }

    printf("%lld\n",ans);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define For(i,a,b) for (int i=a;i<=b;i++)

#define Rep(i,a,b) for (int i=b;i>=a;i--)

using namespace std;

ll ans;

ll n,x,y;

int a[100100],b[100100],c[100100];

inline ll read()

{

    ll x=0,f=1;char ch=getchar();

    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();

    return x*f;

}

int main()

{

	n=read();

	For(i,1,n)a[i]=read();

	For(i,1,n)b[i]=read();

	For(i,1,n)c[i]=-read();

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

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

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

	For(i,1,n)c[i]=-c[i];

	x=0;y=n;

	For(i,1,n)

	{

		while(a[x+1]<b[i]&&x<n)x++;

		while(c[y]<=b[i]&&y>0)y--;

		ans+=(x*y);

	}

	cout<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.207261386869729x):
#include<stdio.h>

#include<algorithm>

#define ll long long

using namespace std;



const int maxn = 1e6+20;

ll a[maxn],b[maxn],c[maxn];



int main()

{

    ll n;

    scanf("%lld",&n);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&a[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&b[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&c[i]);

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

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

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

    ll ans = 0;

    ll numa = 0,numc = 0;

    for(int i = 1 ; i <= n ; i ++)

    {

        while(a[numa+1] < b[i] && numa+1 <= n) numa ++;

        while(c[numc+1] <= b[i] && numc+1 <= n) numc ++;

        ans += numa*(n-numc);

    }

    printf("%lld\n",ans);

    return 0;

}
// Slower C++ solution:
#include<algorithm>

#include<iostream>

#include<cstring>

#include<string>

#include<cstdio>

#include<vector>

#include<stack>

#include<cmath>

#include<queue>

#include<set>

#include<map>

#define N 100100

#define LL long long



using namespace std;



int a[N],b[N],c[N];

LL A[N],B[N];



int main()

{

	int n;

	scanf ("%d",&n);

	for (int i=1;i<=n;i++)

		scanf ("%d",&a[i]);

	for (int i=1;i<=n;i++)

		scanf ("%d",&b[i]);

	for (int i=1;i<=n;i++)

		scanf ("%d",&c[i]);

	

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

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

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

	

	int loc = 1;

	for (int i=1;i<=n;i++)

	{

		while (loc <= n && b[i]>a[loc])

			loc ++;

		B[i] = loc-1;

	}

	

	loc = 1;

	LL ans = 0,tmp = 0;

	for (int i=1;i<=n;i++)

	{

		while (loc <= n && c[i]>b[loc])

			tmp += B[loc++];

		ans += tmp;

	}

	

	printf ("%lld\n",ans);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.160524545378925x):
#include<stdio.h>

#include<algorithm>

#define ll long long

using namespace std;



const int maxn = 1e6+20;

ll a[maxn],b[maxn],c[maxn];



int main()

{

    ll n;

    scanf("%lld",&n);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&a[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&b[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&c[i]);

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

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

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

    ll ans = 0;

    ll numa = 0,numc = 0;

    for(int i = 1 ; i <= n ; i ++)

    {

        while(a[numa+1] < b[i] && numa+1 <= n) numa ++;

        while(c[numc+1] <= b[i] && numc+1 <= n) numc ++;

        ans += numa*(n-numc);

    }

    printf("%lld\n",ans);

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#define rep(i,l,p) for(int i=l;i<=p;i++)

using namespace std;

const int maxN = 1e5+5;





int a[maxN],b[maxN],c[maxN];

int N;

int cnt_b[maxN],cnt_c[maxN];

long long sum[maxN];

bool cmp(const int &a,const int &b){

	return a>b;

}



void input(){

	int t;

	rep(i,1,N) cin >> a[i];

	rep(i,1,N) cin >> b[i];

	rep(i,1,N) cin >> c[i]; 

	sort(a+1,a+1+N,cmp);

	sort(b+1,b+1+N,cmp);

	sort(c+1,c+1+N,cmp);

	int bt = 0,ct = 0;

	rep(i,1,N){

		

		rep(j,bt+1,N){

			if ( b[j] > a[i] ) bt++;

			else break;	

		}

		cnt_b[i] = bt;

	

		rep(j,ct+1,N){

			if ( c[j] > b[i] ) ct++;

			else break;

		}

		

		cnt_c[i] = ct;

	}

	rep(i,1,N) sum[i] = sum[i-1] + cnt_c[i];

//	rep(i,1,N) printf("cntb: %d  cntc: %d\n",cnt_b[i],cnt_c[i]);

}

void solve(){

	long long res = 0;



	rep(i,1,N){

		int a = i,b = cnt_b[i];

		res += sum[b];

	

	}

	printf("%lld\n",res);

}

int main(){

	scanf("%d",&N);

	

	input();

	solve();

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.234955293101259x):
#include<stdio.h>

#include<algorithm>

#define ll long long

using namespace std;



const int maxn = 1e6+20;

ll a[maxn],b[maxn],c[maxn];



int main()

{

    ll n;

    scanf("%lld",&n);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&a[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&b[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&c[i]);

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

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

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

    ll ans = 0;

    ll numa = 0,numc = 0;

    for(int i = 1 ; i <= n ; i ++)

    {

        while(a[numa+1] < b[i] && numa+1 <= n) numa ++;

        while(c[numc+1] <= b[i] && numc+1 <= n) numc ++;

        ans += numa*(n-numc);

    }

    printf("%lld\n",ans);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define N 100005

using namespace std;

int n,tot,a[N],b[N],c[N],e[N],d[N*3];

ll ans,v[N*3];

void add(int x,ll y){

	for (;x<=tot;x+=x&(-x)) v[x]+=y;

}

ll ask(int x){

	ll s=0;

	for (;x;x-=x&(-x)) s+=v[x];

	return s; 

}

int main(){

	scanf("%d",&n);

	for (int i=1;i<=n;i++)

		scanf("%d",&a[i]),d[++tot]=a[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&b[i]),d[++tot]=b[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&c[i]),d[++tot]=c[i];

	sort(d+1,d+tot+1);

	for (int i=1;i<=n;i++){

		a[i]=lower_bound(d+1,d+tot+1,a[i])-d;

		add(a[i],1);

	}

	for (int i=1;i<=n;i++){

		b[i]=lower_bound(d+1,d+tot+1,b[i])-d;

		e[i]=ask(b[i]-1);

	}

	memset(v,0,sizeof(v));

	for (int i=1;i<=n;i++)

		add(b[i],e[i]);

	for (int i=1;i<=n;i++){

		c[i]=lower_bound(d+1,d+tot+1,c[i])-d;

		ans+=ask(c[i]-1);

	}

	printf("%lld",ans);

}

// Faster C++ solution for the same problem (measured speedup: 3.437952304642415x):
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<iostream>

using namespace std;

#define maxn 1000000

//sort(a,a+n);a数组排列,长度n;升序

//sort(a,a+n,greater<int>());int是数组类型;降序

//mid=l+(r-l)/2;避免越界

long long n,i,j,l1,r1,l2,r2,num,a[maxn+10],b[maxn+10],c[maxn+10],mid;

int main()

{

    while(~scanf("%lld",&n))

    {

        num=0;

        for(i=0; i<n; i++)

            scanf("%lld",&a[i]);

        for(i=0; i<n; i++)

            scanf("%lld",&b[i]);

        for(i=0; i<n; i++)

            scanf("%lld",&c[i]);

        sort(a,a+n);

        sort(b,b+n);

        sort(c,c+n);

        for(i=0; i<n; i++)

        {

            l1=0;

            r1=n-1;

            while(l1<=r1)

            {

                mid=l1+(r1-l1)/2;

                if(a[mid]<b[i])

                    l1=mid+1;

                else

                    r1=mid-1;

            }

            l2=0;

            r2=n-1;

            while(l2<=r2)

            {

                mid=l2+(r2-l2)/2;

                if(c[mid]<=b[i])

                    l2=mid+1;

                else

                    r2=mid-1;

            }

            num+=l1*(n-l2);

        }

        printf("%lld\n",num);

    }

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define N 100005

using namespace std;

int n,tot,a[N],b[N],c[N],e[N],d[N*3];

ll ans,v[N*3];

void add(int x,ll y){

	for (;x<=tot;x+=x&(-x)) v[x]+=y;

}

ll ask(int x){

	ll s=0;

	for (;x;x-=x&(-x)) s+=v[x];

	return s; 

}

int main(){

	scanf("%d",&n);

	for (int i=1;i<=n;i++)

		scanf("%d",&a[i]),d[++tot]=a[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&b[i]),d[++tot]=b[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&c[i]),d[++tot]=c[i];

	sort(d+1,d+tot+1);

	for (int i=1;i<=n;i++){

		a[i]=lower_bound(d+1,d+tot+1,a[i])-d;

		add(a[i],1);

	}

	for (int i=1;i<=n;i++){

		b[i]=lower_bound(d+1,d+tot+1,b[i])-d;

		e[i]=ask(b[i]-1);

	}

	memset(v,0,sizeof(v));

	for (int i=1;i<=n;i++)

		add(b[i],e[i]);

	for (int i=1;i<=n;i++){

		c[i]=lower_bound(d+1,d+tot+1,c[i])-d;

		ans+=ask(c[i]-1);

	}

	printf("%lld",ans);

}

// Faster C++ solution for the same problem (measured speedup: 3.4397861690967906x):
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

#include<cstdlib>

#include<cmath>

#include<queue>

#include<stack>

using namespace std;

long long a[100010],b[100010],c[100010];

int main()

{

    long long  n,i,j,sum=0;

    scanf("%lld",&n);

    for(i=0; i<n; ++i)

        scanf("%lld",&a[i]);

    for(i=0; i<n; ++i)

        scanf("%lld",&b[i]);

    for(i=0; i<n; ++i)

        scanf("%lld",&c[i]);

        sort(a,a+n);

        sort(b,b+n);

        sort(c,c+n);

        for(i=0;i<n;++i)

        {long long ans;

            long long l=0,r=n-1,mid;

            while(r>=l)

            {

                mid=(r+l)/2;

                if(a[mid]>=b[i])

                {

                    r=mid-1;

                }

                else if(a[mid]<b[i])

                {

                    l=mid+1;

                }

            }

            ans=r+1;

            l=0,r=n-1,mid;

            while(r>=l)

            {

                mid=(r+l)/2;

                if(c[mid]>b[i])

                {

                    r=mid-1;

                }

                else if(c[mid]<=b[i])

                {

                    l=mid+1;

                }

            }

            ans*=(n-l);

            sum+=ans;

        }

        printf("%lld\n",sum);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define N 100005

using namespace std;

int n,tot,a[N],b[N],c[N],e[N],d[N*3];

ll ans,v[N*3];

void add(int x,ll y){

	for (;x<=tot;x+=x&(-x)) v[x]+=y;

}

ll ask(int x){

	ll s=0;

	for (;x;x-=x&(-x)) s+=v[x];

	return s; 

}

int main(){

	scanf("%d",&n);

	for (int i=1;i<=n;i++)

		scanf("%d",&a[i]),d[++tot]=a[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&b[i]),d[++tot]=b[i];

	for (int i=1;i<=n;i++)

		scanf("%d",&c[i]),d[++tot]=c[i];

	sort(d+1,d+tot+1);

	for (int i=1;i<=n;i++){

		a[i]=lower_bound(d+1,d+tot+1,a[i])-d;

		add(a[i],1);

	}

	for (int i=1;i<=n;i++){

		b[i]=lower_bound(d+1,d+tot+1,b[i])-d;

		e[i]=ask(b[i]-1);

	}

	memset(v,0,sizeof(v));

	for (int i=1;i<=n;i++)

		add(b[i],e[i]);

	for (int i=1;i<=n;i++){

		c[i]=lower_bound(d+1,d+tot+1,c[i])-d;

		ans+=ask(c[i]-1);

	}

	printf("%lld",ans);

}

// Faster C++ solution for the same problem (measured speedup: 3.4375315502217347x):
#include<stdio.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<iostream>

using namespace std;

#define maxx 1000010

long long l1,r1,l2,r2,num,mid;

long long a[maxx],b[maxx],c[maxx];

int main()

{

    long long t;

    while(~scanf("%lld",&t))

    {

        num=0;

        for(long long i=0; i<t; i++)

            scanf("%lld",&a[i]);

        for(long long i=0; i<t; i++)

            scanf("%lld",&b[i]);

        for(long long i=0; i<t; i++)

            scanf("%lld",&c[i]);

        sort(a,a+t);

        sort(b,b+t);

        sort(c,c+t);

        for(long long i=0; i<t; i++)

        {

            l1=0;

            r1=t-1;

            while(l1<=r1)

            {

                mid=l1+(r1-l1)/2;

                if(a[mid]<b[i])

                    l1=mid+1;

                else

                    r1=mid-1;

            }

            l2=0;

            r2=t-1;

            while(l2<=r2)

            {

                mid=l2+(r2-l2)/2;

                if(c[mid]<=b[i])

                    l2=mid+1;

                else

                    r2=mid-1;

            }

            num=num+(l1*(t-l2));

        }

        printf("%lld\n",num);

    }

    return 0;

}