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

using namespace std;

int main(){

	string a;

	cin>>a;

	int l=a.length();

	string t;

	for(int i=0;i<a.length();i++){

		t+=a[i];

		//cout<<"t: "<<i<<' '<<t<<" A: "<<a<<'\n';

		if(a=="dream"||a=="erase"||a=="dreamer"||a=="eraser"){

			cout<<"YES\n";

			return 0;

		}

		if(t=="dream"){

			if(i+4<a.length()){

				if(a[i+1]=='e'&&a[i+2]=='r'&&((a[i+3]=='e'&&a[i+4]=='r')||(a[i+3]=='d'&&a[i+4]=='r'))){

					a.erase(0,t.length()+2);

					t="";

					i=-1;

				}

				else{

					a.erase(0,t.length());

					t="";

					i=-1;

				}

			}

			else{

				a.erase(0,t.length());

				t="";

				i=-1;

			}

		}

		if(t=="erase"){

			if(a[i+1]=='r'){

				a.erase(0,t.length()+1);

				t="";

				i=-1;

			}

			else{

				a.erase(0,t.length());

				t="";

				i=-1;

			}

		}

	}

	if(a.length()==0){

		cout<<"YES\n";

	}

	else{

		cout<<"NO\n";

	}

}

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

#include <cstring>



using namespace std;



int main()

{

  char s[100015];

  int len;

  char c;

  int i;

  bool begin;



  fgets(s, 100015, stdin);

  len = strlen(s) - 1;



#if 0

  printf("string is %s\n", s);

  printf("len %d\n", len);

#endif



  begin = true;

  

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

    if (begin) {

      if (s[i] == 'd') {

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'e') ||

            (s[i+3] != 'a') ||

            (s[i+4] != 'm')) {

           printf("NO\n");

           return 0;

        }

        

        if ((s[i+5] == 'e') &&

            (s[i+6] == 'r') &&

            (s[i+7] != 'a')) {

          i+=6;

        } else {

          i+=4;

        }

      } else if (s[i] == 'e') {

        if ((s[i+1] != 'r') ||

            (s[i+2] != 'a') ||

            (s[i+3] != 's') ||

            (s[i+4] != 'e')) {

           printf("NO\n");

           return 0;

        }

        if (s[i+5] == 'r') {

          i+=5;

        } else {

          i+=4;

        }



      } else {

        printf("NO\n");

        return 0;

      }

    }

  }



  printf("YES\n");



  return 0;

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

#define no {puts("No");return 0;}

#define yes {puts("Yes");return 0;}

#define nc() getchar()

using namespace std;

const int N=300010;



/*inline char nc(){

    static char buf[100000],*p1=buf,*p2=buf;

    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;

}*/

inline int read(){

    char ch=nc();int sum=0;

    while(!(ch>='0'&&ch<='9'))ch=nc();

    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();

    return sum;

}

 

int c[N],n;



void add(int x,int k){

	while(x<=n){

		c[x]+=k;

		x+=x&-x;

	}

}



int query(int x){

	int ans=0;

	while(x){

		ans+=c[x];

		x-=x&-x;

	}

	return ans;

}



int a[N],fu[N],s[N];

bool vis[N];



int main(){

	n=read();

	int s1=0,s2=0;

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

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

			int x;

			x=read();

			if(i==1){

				if(x%3==0){

					a[j]=x/3;

					

					fu[j]=1;

					if(j&1) s1++;

					

					else s2++;

				}else{

					if(x%3!=1) {no;}

					a[j]=x/3+1;

				}

				if(vis[a[j]]) {no;}

				if((j&1)^(a[j]&1)) {no;}

				vis[a[j]]=1;

			}

			else{

				if(fu[j]){

					if(x!=a[j]*3-i+1) {no;}

				}else{

			//		printf("a(%d)=%d\n",j,a[j]);

					if(x!=(a[j]-1)*3+i) {no;}

				}

			}

		}

	}

//	for(int i=1;i<=n;i++) printf("%d ",a[i]);cout<<endl;

	

	int i;

	

	if(n&1) i=n;else i=n-1;

	

	for(;i>0;i-=2){

		s2+=query(a[i]);

		add(a[i],1);

	}

	

	if(n&1) i=n-1;else i=n;

	

	memset(c,0,sizeof(c));

	

	for(;i>0;i-=2){

		s1+=query(a[i]);

		add(a[i],1);

	}

	

	

//	printf("%d %d\n",s1,s2);

	

	if(s1%2==0&&s2%2==0) {yes;}

	else {no;}

	

	return 1;

}

			

	

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

#include <cstring>

#include <cctype>

#include <cmath>

#include <algorithm>

using namespace std;

inline int read(int f = 1, int x = 0, char ch = ' ')

{

    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;

    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();

    return f*x;

}

const int N = 1e5+5;

int n, w[3][N], f[N], h[2];

int main()

{

    n = read();

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

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

            w[i][j] = read();

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

    {

        int a = w[0][i], b = w[1][i], c = w[2][i];

        if(abs(a-b) > 1||abs(b-c) > 1||b%3 != 2||(b%6&i&1)) return puts("No"), 0;

        f[i] = b/3+1, h[i&1] ^= a > c;

    }

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

        while(f[i] != i) h[i&1^1] ^= 1, swap(f[i], f[f[i]]);

    puts(h[0]||h[1]?"No":"Yes");

    return 0;

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

#include<iomanip>

#include<stack>

#include<queue>

#include<list>

#include<vector>

#include<set> 

#include<map>

#include<string>

#include<algorithm>

#include<cmath>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<ctime>

#define ll long long

#define db double

#define inf 200001

#define INF (int)1e9

#define mod (int)(1e9+7)

#define pi acos(-1)

#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}

using namespace std;



inline int Min(int a,int b,int c){

	return min(a,min(b,c));

}



int mp[inf][3];

int p[inf],pos[inf],ck[inf];

int n;



int main(){

	rd(n)

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

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

			rd(mp[j][i])

		}

	}

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

		if (mp[i][3]-mp[i][2]==mp[i][2]-mp[i][1] && mp[i][3]-mp[i][2]==1){

			p[i]=0;

		}

		else if (mp[i][2]-mp[i][3]==mp[i][1]-mp[i][2] && mp[i][2]-mp[i][3]==1){

			p[i]=1;

		}

		else{

			puts("No");

			return 0;

		}

		int minv=Min(mp[i][1],mp[i][2],mp[i][3]);

		int dis=abs(i-minv/3-1);

		if (dis&1){

			puts("No");

			return 0;

		}

		pos[minv/3+1]=i;

	}

	int cnt[2]={0,0};

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

		cnt[i&1]+=p[i];

	}

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

		if (!ck[i]){

			ck[i]=1;

			int len=0,now=pos[i];

			while (!ck[now]){

				ck[now]=1;

				now=pos[now];

				len++;

			}

			cnt[!(i&1)]+=len;

		}

	}

	if ((cnt[0]&1) || (cnt[1]&1)){

		puts("No");

		return 0;

	}

	puts("Yes");

	return 0;

}

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

#include<cctype>

#include<algorithm>

using namespace std;

int n,t[2],a[5][100010],to[100010];

char buffer[10000010],*hed,*tal;

inline char Getchar(){

	return *hed++;

}

inline int rd(){

	register int x=0;

	char c;

	do c=Getchar();

	while(!isdigit(c));

	do{

		x=(x<<1)+(x<<3)+(c^48);

		c=Getchar();

	}while(isdigit(c));

	return x;

}

inline int abs(int x){

	return x>=0?x:-x;

}

int main(){

	int len=fread(buffer,1,10000000,stdin);

	hed=buffer,tal=buffer+len;

	n=rd();

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

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

			a[i][j]=rd();

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

		to[i]=a[2][i]/3+1;

		if(!((a[1][i]-a[2][i]==-1&&a[2][i]-a[3][i]==-1&&a[1][i]%3==1)||(a[1][i]-a[2][i]==1&&a[2][i]-a[3][i]==1&&!(a[1][i]%3)))||(abs(i-to[i])&1)){

			puts("No");

			return 0;

		}

		t[i&1]^=(a[1][i]>a[2][i]);

	}

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

		while(to[i]!=i){

			t[i&1^1]^=1;

			swap(to[i],to[to[i]]);

		}

	}

	puts(t[0]||t[1]?"No":"Yes");

	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: 18.306426655508023x):
#include<cstdio>

#include<algorithm>

#define ll long long

#define For(i,x,y)  for(ll i=x;i<=y;++i)

#define FOr(i,x,y)  for(ll i=x;i>=y;--i)

#define lf else if

using namespace std;

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

inline void write(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10);   putchar(x%10+'0');  } 

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

const ll N=100100;

ll f[N],a[N],b[N],c[N],n,ans;

int main(){

	n=read();

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

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

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

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

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

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

	ll p=1;

	For(i,1,n){

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

		f[i]=max(n-p+1,0ll);

	}

	FOr(i,n,1)	f[i]+=f[i+1];

	p=1;

	For(i,1,n){

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

		ans+=f[p];

	}

	writeln(ans);

}
// 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.360014951792074x):
#include <iostream>

#include <algorithm>

using namespace std;

const int N = 100005;

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

int main()

{

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

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

		cin >> a[i];

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

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

		cin >> b[i];

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

		cin >> c[i];

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

	long long ans = 0;

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

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

	cout << ans << endl;

	return 0;

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

#define ll long long

using namespace std;

const int N=1e5+5;

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

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

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

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

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

ll n;

int main()

{

	n=read();

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

		a[i]=read();

		sa[i]=1;

	}

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

		b[i]=read();

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

		c[i]=read();

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

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

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

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

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

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

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

		sb[i]=sa[k];

	}

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

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

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

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

		sc[i]=sb[k];

	}

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

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

	writeln(sc[n]);

	return 0;

}
// 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: 18.048585068761696x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

#define N 100005

#define inf (1ll<<60)

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

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

	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;

}

ll n,ans,sum[N],a[N],b[N],c[N];

int main(){

	n=read();

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

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

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

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

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

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

	rep(i,1,n){

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

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

	}

	per(i,n,1) sum[i]+=sum[i+1];

	rep(i,1,n){

		ll pos=upper_bound(b+1,b+1+n,a[i])-b;

		if (pos<=n) ans+=sum[pos];

	}

	printf("%lld",ans);

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

#include <algorithm>

using namespace std;

const int N = 100005;

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

int main()

{

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

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

		cin >> a[i];

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

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

		cin >> b[i];

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

		cin >> c[i];

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

	long long ans = 0;

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

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

	cout << ans << endl;

	return 0;

}

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

#include<cstring>

#include<algorithm>

#define ll long long

#define N 100005

#define inf (1ll<<60)

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

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

	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;

}

ll n,ans,sum[N],a[N],b[N],c[N];

int main(){

	n=read();

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

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

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

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

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

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

	rep(i,1,n){

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

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

	}

	per(i,n,1) sum[i]+=sum[i+1];

	rep(i,1,n){

		ll pos=upper_bound(b+1,b+1+n,a[i])-b;

		if (pos<=n) ans+=sum[pos];

	}

	printf("%lld",ans);

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

#define ll long long

using namespace std;

const int N=1e5+5;

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

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

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

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

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

ll n;

int main()

{

	n=read();

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

		a[i]=read();

		sa[i]=1;

	}

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

		b[i]=read();

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

		c[i]=read();

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

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

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

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

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

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

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

		sb[i]=sa[k];

	}

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

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

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

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

		sc[i]=sb[k];

	}

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

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

	writeln(sc[n]);

	return 0;

}

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

#include<cstring>

#include<algorithm>

#define ll long long

#define N 100005

#define inf (1ll<<60)

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

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

	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;

}

ll n,ans,sum[N],a[N],b[N],c[N];

int main(){

	n=read();

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

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

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

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

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

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

	rep(i,1,n){

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

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

	}

	per(i,n,1) sum[i]+=sum[i+1];

	rep(i,1,n){

		ll pos=upper_bound(b+1,b+1+n,a[i])-b;

		if (pos<=n) ans+=sum[pos];

	}

	printf("%lld",ans);

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

#define ll long long

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

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

using namespace std;

ll ans;

ll n,x,y;

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

inline ll read()

{

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

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

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

    return x*f;

}

int main()

{

	n=read();

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

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

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

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

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

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

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

	x=0;y=n;

	For(i,1,n)

	{

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

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

		ans+=(x*y);

	}

	cout<<ans<<endl;

	return 0;

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

#define ll long long

#define N 100005

using namespace std;

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

ll ans,v[N*3];

void add(int x,ll y){

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

}

ll ask(int x){

	ll s=0;

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

	return s; 

}

int main(){

	scanf("%d",&n);

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

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

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

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

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

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

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

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

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

		add(a[i],1);

	}

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

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

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

	}

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

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

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

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

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

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

	}

	printf("%lld",ans);

}

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

#include<algorithm>

using namespace std;

#define MAXN 100010

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

int main()

{

	int N;

	scanf("%d", &N);

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

	{

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

	}

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

	{

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

	}

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

	{

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

	}

	sort(a, a + N);

	sort(b, b + N);

	sort(c, c + N);

	long long ai=0, ci=0;

	long long sum = 0;

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

	{

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

		{

			ai++;

		}

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

		{

			ci++;

		}

		sum += ai*(N-ci);

	}

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

	return 0;

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

#include <algorithm>

using namespace std;

const int N = 100005;

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

int main()

{

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

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

		cin >> a[i];

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

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

		cin >> b[i];

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

		cin >> c[i];

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

	long long ans = 0;

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

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

	cout << ans << endl;

	return 0;

}

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

#include<algorithm>

using namespace std;

#define MAXN 100010

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

int main()

{

	int N;

	scanf("%d", &N);

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

	{

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

	}

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

	{

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

	}

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

	{

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

	}

	sort(a, a + N);

	sort(b, b + N);

	sort(c, c + N);

	long long ai=0, ci=0;

	long long sum = 0;

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

	{

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

		{

			ai++;

		}

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

		{

			ci++;

		}

		sum += ai*(N-ci);

	}

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

	return 0;

}