stablegradients/pie-gem5-pairs huggingface dataset:
// 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.971931142565051x):
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define ordered_set tree<int, null_type, less_equal<int>,rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;

using namespace __gnu_pbds;

using namespace std;

const int N = 2e5 + 5;

int n , a[N];

ll ans;

ordered_set st1 , st2;

int main() {

    abdelrahman010

    cin >> n;

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

        int x;

        cin >> x;

        st1.insert(x);

    }

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

        cin >> a[i];

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

        int x;

        cin >> x;

        st2.insert(-x);

    }

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

        ans += 1ll * st1.order_of_key(a[i]) * st2.order_of_key(-a[i]);

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

using namespace std;

#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define ll long long

#define endl '\n'

const int N = 1e5 + 5;

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

ll finall = 0;

int main()

{

    Hello

    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 + n + 1);

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

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

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

    {

        int low = 1, high = n, mid, ans = n + 1;

        ///first idx > b[i]

        while(low <= high)

        {

            mid = (low + high)/2;

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

                low = mid + 1;

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

            {

                high = mid - 1;

                ans = mid;

            }

        }

        biggerThanB[i] += biggerThanB[i - 1] + (n - ans + 1);

    }

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

    {

        int low = 1, high = n, mid, ans = n + 1;

        while(low <= high)

        {

            mid = (low + high)/2;

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

                low = mid + 1;

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

            {

                high = mid - 1;

                ans = mid;

            }

        }

        finall += (biggerThanB[n] - biggerThanB[ans - 1]);

    }

    cout << finall;

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

#define all(x) begin(x), end(x)

#define _ << ' ' <<

using namespace std;

using ll = long long;



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

ll d[100000];



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

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

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

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

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



    ll sol = 0;

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

    {

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

        if (k != n)

            sol += d[k];

    }

    cout << sol;

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

}


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

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

}


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

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

}


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

	return 0;

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

}

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

#include<string.h>

#include<algorithm>

using namespace std;

#define N 100010

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

int main()

{

    int i,j,k,n,l,r,mid,p1,p2;

    long long s;

    scanf("%d",&n);

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

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

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

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

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

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

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

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

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

    s=0;

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

    {

        if(b[i]<=a[1])

        continue;

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

        continue;

        p1=1;

        l=1;

        r=n;

        while(l<=r)

        {

            mid=(l+r)/2;

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

            {

                p1=max(p1,mid);

                l=mid+1;

            }

            else

            r=mid-1;

        }

        p2=n;

        l=1;

        r=n;

        while(l<=r)

        {

            mid=(l+r)/2;

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

            {

                p2=min(p2,mid);

                r=mid-1;

            }

            else

            l=mid+1;

        }

        s=s+(long long)p1*(n-p2+1);

    }

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

    return 0;

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

}

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

#include<string.h>

#include<algorithm>

using namespace std;

#define N 100010

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

int main()

{

    int i,j,k,n,l,r,mid,p1,p2;

    long long s;

    scanf("%d",&n);

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

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

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

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

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

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

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

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

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

    s=0;

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

    {

        if(b[i]<=a[1])

        continue;

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

        continue;

        p1=1;

        l=1;

        r=n;

        while(l<=r)

        {

            mid=(l+r)/2;

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

            {

                p1=max(p1,mid);

                l=mid+1;

            }

            else

            r=mid-1;

        }

        p2=n;

        l=1;

        r=n;

        while(l<=r)

        {

            mid=(l+r)/2;

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

            {

                p2=min(p2,mid);

                r=mid-1;

            }

            else

            l=mid+1;

        }

        s=s+(long long)p1*(n-p2+1);

    }

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

    return 0;

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

}

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





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

}

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





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

}

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





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

}

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





}