stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<iostream>

#include<stdio.h>

#include<string.h>

int main()

{

	using namespace std;

    char d[10]="dream";

    char e[10]="erase";

    char str[100000];

    int test=1,len=0;

    scanf("%s",&str);

    len=strlen(str);

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

    {

        if(str[i]=='d')

        {



            int j;

            for(j=i;j<i+5;j++)

            {

                //cout<<j<<endl;

                if(j>=len||str[j]!=d[j-i])

                {

                    test=0;

                    break;

                }



            }

            if(j==i+5)

                {

                    //cout<<"!"<<endl;

                    i=j-1;

                    if(str[i+1]=='e'&&str[i+2]=='r'&&str[i+3]!='a')

                    {

                        i=j+1;

                    }

                }

        }

        else if(str[i]=='e')

        {

            int j;

            for(j=i;j<i+5;j++)

            {

                //cout<<j<<endl;

                if(j>=len||str[j]!=e[j-i])

                {

                    test=0;

                    break;

                }



            }

            if(j==i+5)

                {

                    i=j-1;

                    if(str[j]=='r')

                    {

                        i=j;

                    }

                    else

                    {

                        i=j-1;

                    }

                }

        }

        else

        {

            test=0;

        }

        //cout<<i<<endl;

    }

    if(test==0)

        {

            cout<<"NO"<<endl;

        }

        else

        {

            cout<<"YES"<<endl;

        }



    return 0;

}


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

}


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

using namespace std;



int main() {

	string s, t = "";

	cin >> s;

	int n = s.size();

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

		t += s[i];

		if (t == "erase") {

			if (i + 1 < n && s[i + 1] == 'r') {

				i += 1;

			}

			t = "";

		}

		else if (t == "dream") {

			if (i + 2 < n && s[i + 1] == 'e' && s[i + 2] == 'r') {

				if (i + 3 < n && s[i + 3] == 'a') {

					t = "era";

					i += 3;

				}

				else {

					t = "";

					i += 2;

				}

			}

			else {

				t = "";

			}

		}

	}

	if (t == "") {

		cout << "YES";

	}

	else {

		cout << "NO";

	}

	return 0;

}

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

}


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

#include <cstdio>

#include <cstdlib>

using namespace std;

int siz;

string s;

string dream, dreamer, erase, eraser;



void dfs(int st){

	//cout<<st<<endl;

	if(st == siz){

		puts("YES");

		exit(0);

	}

	

	bool flag = 1; // dream

	if(st + 4 <= siz){ 

		//cout<<st<<" "<<"dream"<<endl;

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

			if(s[st+i] != dream[i]){

				flag = 0;

				break;

			}

		}

		if(flag == 1) dfs(st+5);

	} 

	

	if(st + 6 <= siz){

		//cout<<st<<" "<<"dreamer"<<endl;

		flag = 1; // dreamer

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

			if(s[st+i] != dreamer[i]){

				flag = 0;

				break;

			}

		}

		if(flag == 1) dfs(st+7);

	}

	

	if(st + 4 <= siz){

		//cout<<st<<" "<<"erase"<<endl;

		flag = 1; // erase

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

			if(s[st+i] != erase[i]){

				flag = 0;

				break;

			}

		}

		//cout<<flag<<endl;

		if(flag == 1) dfs(st+5);

	}

	

	if(st + 5 <= siz){

		//cout<<st<<" "<<"eraser"<<endl;

		flag = 1; // eraser

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

			if(s[st+i] != eraser[i]){

				flag = 0;

				break;

			}

		}

		if(flag == 1) dfs(st+6);

	}

}



int main(){

	cin>>s; siz = s.size();

	dream = "dream";

	dreamer = "dreamer";

	erase = "erase";

	eraser = "eraser";

	dfs(0);

	puts("NO");

} 

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

}


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

#define YY "YES\n"

#define NN "NO\n"

#define f first

#define s second

#define LL long long

using namespace std;



string s,s1,s2,s3,s4,tmp;

int a,b,c,d,n,aa,bb,cc,dd;

int main(){

	cin>>s;

	n=s.length();

	s1="dream";

	s2="dreamer";

	s3="erase";

	s4="eraser";

	bool ok=true;

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

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

			int j;

			for (j=i;j<=i+4;j++){

				if (j>=n || s[j]!=s1[j-i]){

					ok=false;

					break;

				}

			}

			if(j==i+5) {

	            if(s[j]=='e' && s[j+1]=='r' && s[j+2]!='a') i=j+1;

	            else i=j-1;

	        }

		}

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

			int j;

			for (j=i;j<=i+4;j++){

				if (j>=n || s[j]!=s3[j-i]){

					ok=false;

					break;

				}

			}

			if(j==i+5) {

	            if(s[j]=='r')i=j;

	            else i=j-1;

	        }

		}

		else ok=false;

	}	

	cout<<(ok==true? YY:NN);

}


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

}


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

	}

}

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

}


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

}

			

	

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

}

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

#include<algorithm>

#define ll long long

using namespace std;



const int maxn = 1e6+20;

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



int main()

{

    ll n;

    scanf("%lld",&n);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&a[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&b[i]);

    for(int i = 1 ; i <= n ; i ++) scanf("%lld",&c[i]);

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

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

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

    ll ans = 0;

    ll numa = 0,numc = 0;

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

    {

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

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

        ans += numa*(n-numc);

    }

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

    return 0;

}


// Fastest known solution for this problem: