stablegradients/pie-gem5-pairs huggingface dataset:
// 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.3991476153184412x):
#include "bits/stdc++.h"

using namespace std;



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

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

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



#define SZ(a) (int)a.size()

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL) INF;



const int MAX = 100100;



int A[MAX];

int B[MAX];

int C[MAX];



int main(int argc, char* argv[])

{

	//ios::sync_with_stdio(false); cin.tie(0);



	int n;

	scanf("%d", &n);



	FOR (i, 0, n)

	{

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

	}



	FOR (i, 0, n)

	{

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

	}



	FOR (i, 0, n)

	{

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

	}



	sort(A, A+n);

	sort(B, B+n);

	sort(C, C+n);



	LL res = 0;



	FOR (i, 0, n)

	{

		LL a = lower_bound(A, A+n, B[i]) - A;

		LL b = upper_bound(C, C+n, B[i]) - C;



		b = n - b;



		res += a * b;

	}



	cout<<res<<endl;





}
// 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.3216097625989898x):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using vi = vector<int>;



#define SZ(a) ((int)a.size())

#define ALL(a) a.begin(), a.end()

#define MP make_pair

#define PB push_back

#define EB emplace_back

#define fst first

#define snd second



void dout() { cerr << endl; }



template <typename Head, typename... Tail>

void dout(Head H, Tail... T) {

    cerr << H << ' ';

    dout(T...);

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int n;

    cin >> n;

    vector<ll> 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];

    }

    sort(ALL(a));

    sort(ALL(b));

    sort(ALL(c));

    ll ans = 0;

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

    {

        ll x = lower_bound(ALL(a), b[i]) - a.begin();

        ll y = c.end() - upper_bound(ALL(c), b[i]);

        ans += x * y;

    }

    cout << 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.355982728391035x):
//#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pll;

#define mp make_pair

#define f first

#define s second

#define pb push_back



const int N = 1e5 + 5;

const int OO = 2e9;



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

ll ans;



void init() {







}



int main() {



    ios_base::sync_with_stdio(false);

    cin.tie(0);



    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(c,c+n);



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



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

        int cb = n-(upper_bound(c,c+n,b[i])-c);

        ans += 1LL*ca*cb;



    }



    cout << ans << '\n';



    return 0;



}
// Slower C++ solution:
#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



*/

// Faster C++ solution for the same problem (measured speedup: 5.282172486406823x):
#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;

}
// Slower C++ solution:
#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;

}




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

#include <stdlib.h>

#include <string.h>

#include <math.h>

#include <iostream>

#include <algorithm>

#include <stack>

using namespace std;

int a[110000];

int b[110000];

int c[110000];

int main()

{

    long long sm=0,zj=0,xm=0;

    long long ff=0;

    int n;

    scanf("%d",&n);

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

    {

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

    }

    sort(a,a+n);

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

    {

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



    }

    sort(b,b+n);

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

    {

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

    }

    sort(c,c+n);

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

    {

        while(a[sm]<b[i]&&sm<n)

            sm++;

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

        {

            zj++;

        }

        ff=ff+(sm*(n-zj));

    }

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

    return 0;

}
// Slower C++ solution:
#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;

}




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

using namespace std;

typedef long long LL;



const int N = 100009;



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

LL f[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);

    LL ans = 0;



    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;







}
// Slower C++ solution:
#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;

}




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

#include <cstdio>

#include <cstdlib>

#include <algorithm>

#include <cstring>

#include <math.h>

using namespace std;

#define maxx 1000010

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

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

int main()

{

    long long t;

    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;

}
// Slower C++ solution:
#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;

}




// Faster C++ solution for the same problem (measured speedup: 3.0543076017632966x):
#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;

}
// Slower C++ solution:
#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;

}




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

using namespace std;



#define      ll     long long int



const int N = 100005;

int A[N];

int B[N];

int C[N];



int main()

{

    ll n, i, j, k, l;

    ll s = 0;

    cin >> n;

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

        cin >> A[i];

    }

    sort(A, A + n);

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

        cin >> B[i];

    }

    sort(B, B + n);

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

        cin >> C[i];

    }

    sort(C, C + n);

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

        j = B[i];

        k = (int) (lower_bound(A, A + n, j) - A);

        l = (int) (upper_bound(C, C + n, j) - C);

        l = n - l;

        //cout << j << ' ' << k << ' ' << l << '\n';

        s += (k * l);

    }

    cout << s << '\n';

    return 0;

}
// Slower C++ solution:
#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;

}




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

using namespace std;

typedef long long ll;

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int n;

    cin >> n;

    ll 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];

    }

    ll tot = 0;

    sort(a, a + n);

    sort(b, b + n);

    sort(c, c + n);

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

        ll curr = b[i];

        ll res2 = -1, res1 = -1;

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

        while (l <= r) {

            mid = (l + r) / 2;

            if (c[mid] > curr) {

                res2 = mid;

                r = mid - 1;

            }

            else {

                l = mid + 1;

            }

        }

        l = 0, r = n - 1;

        while (l <= r) {

            mid = (l + r) / 2;

            if (a[mid] < curr) {

                res1 = mid;

                l = mid + 1;

            }

            else {

                r = mid - 1;

            }

        }

        if (res1 == -1 || res2 == -1)

            continue;

        tot += (res1 + 1) * (n - res2);

    }

    cout << tot;

    return  0;

}