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

using namespace std;

int a,b,c,i,j,k;

int x[100005],y[100005],z[100005];

long long more[100005];

long long ans;

main()

{

	scanf("%d",&a);

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

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

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

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

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

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

	sort(x,x+a);

	sort(y,y+a);

	sort(z,z+a);

	j=a-1;

	int now=0;

/*	for(i=0;i<a;i++)

	{

		printf("%4d %4d %4d\n",x[i],y[i],z[i]);

	}*/

	for(i=a-1;i>=0;i--)

	{

		while(y[i]<z[j]&&j>=0)

		{

			now++;

			j--;

		}

		more[i]=now+more[i+1];

	}

	now=0;

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

	{

		while(y[now]<=x[i]&&now<a)

		{

			now++;

		}

		if(now>=a)

			break;

	//	printf("%d ",more[now]);

		ans+=more[now];

	}

	printf("%lld",ans);

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

namespace chtholly{

typedef long long ll;

#define re0 register int

#define rec register char

#define rel register ll

#define gc getchar

#define pc putchar

#define p32 pc(' ')

#define pl puts("")

/*By Citrus*/

inline int read(){

  int x=0,f=1;char c=gc();

  for (;!isdigit(c);c=gc()) f^=c=='-';

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return f?x:-x;

  }

template <typename mitsuha>

inline bool read(mitsuha &x){

  x=0;int f=1;char c=gc();

  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';

  if (!~c) return 0;

  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');

  return x=f?x:-x,1;

  }

template <typename mitsuha>

inline int write(mitsuha x){

  if (!x) return 0&pc(48);

  if (x<0) x=-x,pc('-');

  int bit[20],i,p=0;

  for (;x;x/=10) bit[++p]=x%10;

  for (i=p;i;--i) pc(bit[i]+48);

  return 0;

  }

inline char fuhao(){

  char c=gc();

  for (;isspace(c);c=gc());

  return c;

  }

}using namespace chtholly;

using namespace std;

const int yuzu=1e5;

typedef int fuko[yuzu|10];

fuko a,b,c;

int main(){

int i,n=read();

for (i=1;i<=n;++i) a[i]=read();

for (i=1;i<=n;++i) b[i]=read();

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

ll llx=0;

#define lb lower_bound

#define ub upper_bound

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

  int p1=lb(a+1,a+n+1,b[i])-a-1,p2=n-(ub(c+1,c+n+1,b[i])-c)+1;

  llx+=1ll*p1*p2;

  }write(llx);

}
// 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: 3.417440639332199x):


#include<cstdio>



#include<cstring>



#include<iostream>



#include<algorithm>



using namespace std;



typedef long long ll;



const int N=1e6+10;



int n,m,a[4][N];



ll ans,cnt[N];



 



 



int main()



{



//	freopen("in.in","r",stdin);



//	freopen("out.out","w",stdout);



	scanf("%d",&n);



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



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



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



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



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



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



	{



		while(a[1][i]<a[2][j]&&i<=n) i++;



		cnt[j]=i-1;



	}



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



//		printf("cnt=%d\n",cnt[i]);



//改用前缀和（dp思想） 



	for(int i=1;i<=n-1;i++) cnt[i+1]=cnt[i]+cnt[i+1]; 



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



	{



		while(a[2][i]<a[3][j]&&i<=n) i++;



//		for(int m=1;m<=i-1;m++)



//			ans+=cnt[m] ;



		ans+=cnt[i-1];



	 	



	 } 



 



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



	return 0;



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

using namespace std;



//#pragma GCC optimize("O3")

//#pragma GCC target("sse4")



#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 pair<int, int> PII;



const double PI = acos(-1.0);

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

const LL LINF = (LL)INF * INF;



const int MAX = 1 << 17;



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



int main()

{

	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;

	cin >> n;

	FOR(i, 0, n)

		cin >> a[i];

	FOR(i, 0, n)

		cin >> b[i];

	FOR(i, 0, n)

		cin >> c[i];

	sort(a, a + n);

	sort(b, b + n);

	sort(c, c + n);

	int ptr1 = 0, ptr2 = 0;

	LL ans = 0;

	FOR(i, 0, n)

	{

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

			ptr1++;

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

			ptr2++;

		ans += (LL)ptr1 * (n - ptr2);

	}

	cout << ans << "\n";

	return 0;

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

#define ll long long

#define ld long double

#define f first

#define s second

using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;



ordered_set< pair<ll,ll> > up , dw;

const int N = 2e5+5;

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



int main()

{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);



    cin >> n;

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

    {

        cin >> a[i];

        up.insert({a[i] , i});

    }

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

        cin >> b[i];

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

    {

        cin >> c[i];

        dw.insert({c[i] , i});

    }



    ll ans=0 , u , d;

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

    {

        u = up.order_of_key({b[i] , -1e9});

        d = dw.order_of_key({b[i] , 1e9});

        d = dw.size() - d;

        ans += (u*d);

    }



    cout << ans << '\n';



    return 0;

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

using namespace std;

#define ll long long

#define pb push_back

#define F first

#define S second

const int mod = 1e9+7, A = 1e3+5;



int main()

{

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int n;

	cin >> n;

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

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

	for (int i = 0; i < n; cin >> b[i++]);

	for (int i = 0; i < n; cin >> c[i++]);

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

	ll acc[n];

	int low = 0, high, mid, val;

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

	{

		low = 0, high = n - 1, val = n;

		while(low <= high)

		{

			mid = (low + high) / 2;

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

				high = mid - 1, val = mid;

			else

				low = mid + 1;

		}

		acc[i] = n - val;

	}

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

		acc[i] += acc[i + 1];

	ll ans = 0;

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

	{

		low = 0, high = n - 1, val = -1;

		while(low <= high)

		{

			mid = (low + high) / 2;

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

				high = mid - 1, val = mid;

			else

				low = mid + 1;

		}

		if (~val)

			ans += acc[val];

	}

	cout << ans;

	return 0;

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

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

#define ll long long

#define ld long double

using namespace std;

const ll  mod = 998244353;



    int frq[200001];



int main()

{

    H

    int n;

    cin >> n;

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

    ll sum[n];

    for (int i = 0; i < n; i++) cin >> c[i];

    for (int i = 0; i < n; i++) cin >> b[i];

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

    sort(b, b + n);

    sort(c, c + n);

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

        auto x = lower_bound(c, c + n, b[i]);

        sum[i] = x - c;

        if (i) sum[i] += sum[i - 1];

        //cout << x - c << '\n';

    }

    ll ans = 0;

    int idx;

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

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

        if (idx >= 0) {

            ans += sum[idx];

            //cout << idx << ' ' << sum[idx] << '\n';

        }

    }

    cout << ans;

    return 0 ;

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

}


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

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

}


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

}