stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

#include<string.h>

#include<math.h>

using namespace std;

long long n;

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

int main(){

    cin>>n;

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

    	cin>>a[i];

	}

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

    	cin>>b[i];

	}

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

    	cin>>c[i];

	}

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

    long long sum=0;

    long long ai=0,ci=0;

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

        while(a[ai+1]<b[i]&&ai+1<=n){

        	ai++;

		}

        while(c[ci+1]<=b[i]&&ci+1<=n){

        	ci++;

		}

        sum+=ai*(n-ci);

    }

    cout<<sum<<endl;

    return 0;

}

/*



in:

2

1 5

2 4

3 6



out:

3



*/

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;

inline int read(){int 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;}

const int maxn=1e5+5;

int n,a[maxn],b[maxn],c[maxn];

inline void init(){

	n=read();

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

		a[i]=read();

	}

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

		b[i]=read();

	}

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

		c[i]=read();

	}

}

const int inf=1e9;

typedef long long ll;

ll s[maxn],sum[maxn];

inline void solve(){

	sort(a+1,a+1+n); a[n+1]=b[n+1]=c[n+1]=inf;

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

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

	int pos=1;

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

		while (pos<=n&&c[pos]<=b[i]){

			pos++;

		}

		s[i]=n-pos+1;

	}

	for (int i=n;i;i--){

		sum[i]=sum[i+1]+s[i];

	}

	pos=1; ll ans=0;

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

		while (pos<=n&&b[pos]<=a[i]){

			pos++;

		}

		ans+=sum[pos];

	}

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

}

int main(){

	init();

	solve();

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <iostream>

#include <stdio.h>

#include <map>

#include <math.h>



using namespace std;



int main()

{

    int x;

    while(~scanf("%d",&x))

    {

        int i,a[100100]= {0},b[100100]= {0},c[100100]= {0};

        long long d[100100]={0};

        for(i=1; i<=x; i++)

        {

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

        }

        for(i=1; i<=x; i++)

        {

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

        }

        for(i=1; i<=x; i++)

        {

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

        }

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

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

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

        for(i=1; i<=x; i++)

        {

            int l=1,r=x,mid;

            while(l<=r)

            {

                mid=l+(r-l)/2;

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

                {

                    r=mid-1;

                }

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

                {

                    l=mid+1;

                }

            }

            d[i]=d[i-1]+r;

        }

        long long sum=0;

        for(i=1; i<=x; i++)

        {

            int l=1,r=x,mid;

            while(l<=r)

            {

                mid=l+(r-l)/2;

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

                {

                    r=mid-1;

                }

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

                {

                    l=mid+1;

                }

            }

            sum=sum+d[r];

        }

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

    }

    return 0;

}




// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <algorithm>

#include <string.h>

using namespace std;



const int N = 1e5+10;;

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

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 ans = 0;

    for(int i = 0, j = 0, k = 0; i < n; i++)

    {

        while(b[i]>a[j] && j <= n-1)

        {

            j++;

        }

        while(b[i]>=c[k] && k <= n-1)

        {

            k++;

        }

        ans += (long long )j * (n-k);

    }

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

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <map>

#include <cmath>

#include <queue>

#include <numeric>

#include <climits>

#include <iterator>

#include <iomanip>

#include <stack>

#include <bitset>

#include <functional>

using namespace std;

const constexpr int INF = 1e9;

//typedef std::pair<std::string,double> P;



typedef long long ll;

typedef vector<int> VI;



#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)

#define REP(i, n) FOR(i, 0, n)



//グラフの隣接リスト

VI g[200010];

//頂点の入次数を管理

int h[100010];

ll N;



int a[200010];

int b[200010];

int c[200010];

ll sum[200010];

signed main(void) {

    cin >> N;

    REP(i, N) cin >> a[i];

    REP(i, N) cin >> b[i];

    REP(i, N) cin >> c[i];

    sort(a, a+N);

    sort(c, c+N);

    

    ll cnt=0;

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

        ll lb = lower_bound(a, a+N, b[i]) - a;

        ll ub = N - (upper_bound(c, c+N, b[i]) - c);

        cnt += lb*ub;

    }

    cout << cnt << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
// This file is a "Hello, world!" in C++ language by GCC for wandbox.

#include <iostream>

#include <cstdlib>

#include <algorithm>

using namespace std;

using ll = long long;





ll A[100010], B[100010], C[100010];

int main()

{

    int N; cin >> N;

    for(int i=0; i<N; ++i) cin >> A[i];

    for(int i=0; i<N; ++i) cin >> B[i];

    for(int i=0; i<N; ++i) cin >> C[i];

    

    sort(A, A+N);

    sort(B, B+N);

    sort(C, C+N);

    

    ll ans=0;

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

        ll smaller = lower_bound(A, A+N, B[i])-A;

        ll bigger = (C+N) - upper_bound(C, C+N, B[i]);

        

        ans += smaller*bigger;

    }

    cout << ans << endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main(void){

    int n; cin >> n;

    vector<int> a(n), b(n), c(n);

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

        cin >> a[i];

    }

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

        cin >> b[i];

    }

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

        cin >> c[i];

    }



    int dp[2][100010] = {};



    sort(a.begin(), a.end());

    sort(b.begin(), b.end());

    sort(c.begin(), c.end());



    int j = 0;

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

        while(1){

            if(a[i] < b[j]){

                dp[0][i] = n - j;

                break;

            }

            if(j == n-1){

                i = n-1;

                break;

            }

            j++;

        }

    }



    j = 0;

    long long sum = 0;

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

        while(1){

            if(b[i] < c[j]){

                dp[1][i] = n - j;

                sum += dp[1][i];

                break;

            }

            if(j == n-1){

                i = n-1;

                break;

            }

            j++;

        }

        

    }



    long long D[100010] = {};



    for(int i = n; i >= 0; i--){

        D[i] = sum;

        sum -= dp[1][n-i];

    }



    long long temp;

    long long ans = 0;

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

        ans += D[ dp[0][i] ];

    }



    /*for(int i = 0; i <= n; i++) cout << D[i] << " ";

    cout << endl;

    */

    

    cout << ans << endl;



    return 0;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;



int main(void){

    int n; cin >> n;



    vector<int> a(n);

    vector<int> b(n);

    vector<int> c(n);

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

        cin >> a[i];

    }

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

        cin >> b[i];

    }

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

        cin >> c[i];

    }



    sort(a.begin(), a.end());

    sort(b.begin(), b.end());

    sort(c.begin(), c.end());



    long long ans = 0;



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

        ans += (distance(a.begin(), lower_bound(a.begin(), a.end(), b[i])) * (distance(upper_bound(c.begin(), c.end(), b[i]), c.end())));



    }

    cout << ans << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int N = 100005;

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

ll f[N],ans;

int n;



int main(){

	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);

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

		if(b[i] >= c[n-1]) break;

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

	}

	f[0] = 0;

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

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

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

		if(a[i] >= b[n-1]) break;

		int s = upper_bound(b,b+n,a[i])-b;

		ans += f[n]-f[s];

	}

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

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<algorithm>

using namespace std;

typedef long long ll;

int a[3][100005];

int main(){

    int n;

    scanf("%d",&n);

    ll i1=0,i2=0,i3=0,sum=0;

    for(int i=0;i<3;i++){

        for(int j=0;j<n;j++){

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

        }

    }

    for(int i=0;i<3;i++){

        sort(a[i],a[i]+n);



    }



    while(i2<n){

        while(a[1][i2]>a[0][i1]&&i1<n) i1++;

        while(a[1][i2]>=a[2][i3]&&i3<n) i3++;

       // printf("%lld %lld %lld = %lld\n",i1,i2,i3,(n-i3)*i1);

        sum+=(n-i3)*i1;

        i2++;

    }

    printf("%lld",sum);





}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int N=100005;

int n,l,r,a[N],b[N],c[N],ans;

 

signed main()

{

	cin>>n;

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

		cin>>a[i];

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

		cin>>b[i];

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

		cin>>c[i];

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

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

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

	l=0;

	r=1;

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

	{

		for (;l<n&&a[l+1]<b[i];++l);

		for (;r<=n&&c[r]<=b[i];++r);

		ans+=l*(n-r+1);

	}

	cout<<ans;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<algorithm>

using namespace std;

typedef long long ll;

int a[3][100005];

int main(){

    int n;

    scanf("%d",&n);

    ll i1=0,i2=0,i3=0,sum=0;

    for(int i=0;i<3;i++){

        for(int j=0;j<n;j++){

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

        }

    }

    for(int i=0;i<3;i++){

        sort(a[i],a[i]+n);



    }



    while(i2<n){

        while(a[1][i2]>a[0][i1]&&i1<n) i1++;

        while(a[1][i2]>=a[2][i3]&&i3<n) i3++;

       // printf("%lld %lld %lld = %lld\n",i1,i2,i3,(n-i3)*i1);

        sum+=(n-i3)*i1;

        i2++;

    }

    printf("%lld",sum);





}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

const int INF=int(1e9);

const int maxn=1000020;

long long N,a[maxn],b[maxn],c[maxn];

void read(long long a[])

{

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

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

}

int main()

{

    cin>>N;

    read(a),read(b),read(c);

    sort(a+1,a+1+N),sort(b+1,b+1+N),sort(c+1,c+1+N);

    long long ans=0;

    long long ai=0,ci=0;

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

	{

        while(a[ai+1]<b[i]&&ai+1<=N) ai++;

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

        ans+=ai*(N-ci);

    }

    cout<<ans<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<algorithm>

using namespace std;

typedef long long ll;

int a[3][100005];

int main(){

    int n;

    scanf("%d",&n);

    ll i1=0,i2=0,i3=0,sum=0;

    for(int i=0;i<3;i++){

        for(int j=0;j<n;j++){

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

        }

    }

    for(int i=0;i<3;i++){

        sort(a[i],a[i]+n);



    }



    while(i2<n){

        while(a[1][i2]>a[0][i1]&&i1<n) i1++;

        while(a[1][i2]>=a[2][i3]&&i3<n) i3++;

       // printf("%lld %lld %lld = %lld\n",i1,i2,i3,(n-i3)*i1);

        sum+=(n-i3)*i1;

        i2++;

    }

    printf("%lld",sum);





}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

const int MXN = 3e5+7;

long long FT[MXN];

void add(int idx,long long amt){

	while(idx < MXN){

		FT[idx] += amt;

		idx += idx & -idx;

	}

}

long long sum(int idx){

	long long ret = 0ll;

	while(idx > 0){

		ret += FT[idx];

		idx -= idx & -idx;

	}

	return ret;

}

int main(){

	#ifdef REDIRECT_IO

	freopen("input.txt","r",stdin);

	freopen("output.txt","w",stdout);

	#endif

	int n;

	scanf("%d",&n);

	vector<int> dat1,dat2,dat3,com;

	com.push_back(-1e9);

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

		int x;

		scanf("%d",&x);

		dat1.push_back(x);

		com.push_back(x);

	}

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

		int x;

		scanf("%d",&x);

		dat2.push_back(x);

		com.push_back(x);

	}

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

		int x;

		scanf("%d",&x);

		dat3.push_back(x);

		com.push_back(x);

	}

	sort(com.begin(),com.end());

	com.resize(unique(com.begin(),com.end()) - com.begin());

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

		int x = lower_bound(com.begin(),com.end(),dat1[i]) - com.begin();

		add(x,1);

	}

	vector<pair<int,long long> > v;

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

		int x = lower_bound(com.begin(),com.end(),dat2[i]) - com.begin();

		v.emplace_back(x,sum(x-1));

	}

	memset(FT,0,sizeof(FT));

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

		add(v[i].first,v[i].second);

	}

	long long ans = 0ll;

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

		int x = lower_bound(com.begin(),com.end(),dat3[i]) - com.begin();

		ans += sum(x-1);

	}

	printf("%lld",ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<algorithm>

using namespace std;

typedef long long ll;

int a[3][100005];

int main(){

    int n;

    scanf("%d",&n);

    ll i1=0,i2=0,i3=0,sum=0;

    for(int i=0;i<3;i++){

        for(int j=0;j<n;j++){

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

        }

    }

    for(int i=0;i<3;i++){

        sort(a[i],a[i]+n);



    }



    while(i2<n){

        while(a[1][i2]>a[0][i1]&&i1<n) i1++;

        while(a[1][i2]>=a[2][i3]&&i3<n) i3++;

       // printf("%lld %lld %lld = %lld\n",i1,i2,i3,(n-i3)*i1);

        sum+=(n-i3)*i1;

        i2++;

    }

    printf("%lld",sum);





}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



#define _ cin.tie(0);ios::sync_with_stdio(false);

using namespace std;

using LL = long long;

const int N = 100000 + 5;



LL tree[N << 1];

LL read(int k){

    LL sum = 0;

    while(k){

        sum+=tree[k];

        k-= k&-k;

    }

    return sum;

}



void add(int k,LL num){

    while(k<=N){

        tree[k]+=num;

        k+=k&-k;

    }

}

vector<LL> a, b, c;

int main(){ _

    LL  n, m;

    memset(tree, 0, sizeof(tree));

    cin >> n;

    for(int i = 0; i < n; i++) { cin >> m; a.push_back(m); }

    for(int i = 0; i < n; i++) { cin >> m; b.push_back(m); }

    for(int i = 0; i < n; i++) { cin >> m; c.push_back(m); }

    sort(a.begin(), a.end()); sort(b.begin(), b.end()); sort(c.begin(), c.end());



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

        auto tmp = lower_bound(a.begin(), a.end(), b[i]);

        int num = tmp - a.begin();

        add(i + 1, num);



    }

    LL sum = 0;

    for(auto &i : c){

        auto tmp = lower_bound(b.begin(), b.end(), i);

        int cur = tmp - b.begin();

        LL num = read(cur);

        sum += num;

    }

    cout << sum << endl;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>



#define _ cin.tie(0);ios::sync_with_stdio(false);

using namespace std;



#define rep(n) for(int i = 0; i < n; i++)

#define Sort(a) sort(a.begin(), a.end())

using LL = long long;

const int N = 100000 + 5;



LL tree[N];

LL Query(int pos){

    LL sum = 0;

    while(pos > 0){

        sum += tree[pos];

        pos -= (pos & -pos);

    }

    return sum;

}



void Add(int pos,LL num){

    while(pos <= N){

        tree[pos] += num;

        pos += (pos & -pos);

    }

}

vector<LL> a, b, c;

int main(){ _

    LL  n, m;

    memset(tree, 0, sizeof(tree));

    cin >> n;

    rep(n) { cin >> m; a.push_back(m); }

    rep(n) { cin >> m; b.push_back(m); }

    rep(n) { cin >> m; c.push_back(m); }

    Sort(a), Sort(b), Sort(c);



    /*for(int i = 0; i < n; i++){

        auto tmp = lower_bound(a.begin(), a.end(), b[i]);

        int num = tmp - a.begin();

        Add(i + 1, num);



    }

    LL sum = 0;

    for(auto &i : c){

        auto tmp = lower_bound(b.begin(), b.end(), i);

        int cur = tmp - b.begin();

        LL num = Query(cur);

        sum += num;

    }

    */

    LL sum = 0;

    rep(n){

        LL A = lower_bound(a.begin(), a.end(), b[i]) - a.begin();

        LL B = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());

        sum += (A * B);

    }

    cout << sum << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



#define _ cin.tie(0);ios::sync_with_stdio(false);

using namespace std;

using LL = long long;

const int N = 100000 + 5;



LL tree[N << 1];

LL read(int k)

{

    LL sum=0;

    while(k)

    {

        sum+=tree[k];

        k-=k&-k;

    }

    return sum;

}



void add(int k,LL num)

{

    while(k<=N)

    {

        tree[k]+=num;

        k+=k&-k;

    }

}

vector<LL> a, b, c;

int main(){ _

    LL  n, m;

    memset(tree, 0, sizeof(tree));

    scanf("%lld", &n);

    for(int i = 0; i < n; i++) { scanf("%lld", &m); a.push_back(m); }

    for(int i = 0; i < n; i++) { scanf("%lld", &m); b.push_back(m); }

    for(int i = 0; i < n; i++) { scanf("%lld", &m); c.push_back(m); }

    sort(a.begin(), a.end()); sort(b.begin(), b.end()); sort(c.begin(), c.end());



   // array<LL, N> nCount;

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

        auto tmp = lower_bound(a.begin(), a.end(), b[i]);

        LL num = distance(a.begin(), tmp);

        add(i + 1, num);

    }

    LL sum = 0;

    for(auto &i : c){

        auto tmp = lower_bound(b.begin(), b.end(), i);

        LL cur = distance(b.begin(), tmp);

        sum += read(cur);

    }

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

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>



#define _ cin.tie(0);ios::sync_with_stdio(false);

using namespace std;



#define rep(n) for(int i = 0; i < n; i++)

#define Sort(a) sort(a.begin(), a.end())

using LL = long long;

const int N = 100000 + 5;



LL tree[N];

LL Query(int pos){

    LL sum = 0;

    while(pos > 0){

        sum += tree[pos];

        pos -= (pos & -pos);

    }

    return sum;

}



void Add(int pos,LL num){

    while(pos <= N){

        tree[pos] += num;

        pos += (pos & -pos);

    }

}

vector<LL> a, b, c;

int main(){ _

    LL  n, m;

    memset(tree, 0, sizeof(tree));

    cin >> n;

    rep(n) { cin >> m; a.push_back(m); }

    rep(n) { cin >> m; b.push_back(m); }

    rep(n) { cin >> m; c.push_back(m); }

    Sort(a), Sort(b), Sort(c);



    /*for(int i = 0; i < n; i++){

        auto tmp = lower_bound(a.begin(), a.end(), b[i]);

        int num = tmp - a.begin();

        Add(i + 1, num);



    }

    LL sum = 0;

    for(auto &i : c){

        auto tmp = lower_bound(b.begin(), b.end(), i);

        int cur = tmp - b.begin();

        LL num = Query(cur);

        sum += num;

    }

    */

    LL sum = 0;

    rep(n){

        LL A = lower_bound(a.begin(), a.end(), b[i]) - a.begin();

        LL B = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());

        sum += (A * B);

    }

    cout << sum << endl;

}


// Fastest known solution for this problem: