semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
static int cmp(const void *a, const void *b)
{
	return *(int *)b - *(int *)a;
}
int main()
{
	int n=1;

	while(n!=0)
	{
		int *a,*b,t,s,j,p,c,tk,tm,qk,qm;
		int *p3,*p4;
		scanf("%d",&n);
		if (n==0) break;
		a=(int *)malloc((n)*sizeof(int));
		b=(int *)malloc((n)*sizeof(int));
		p3=(int *)malloc((n)*sizeof(int));
		p4=(int *)malloc((n)*sizeof(int));
		t=0;
		p=0;
		j=0;
		s=0;
		for(int i=0;i<n;i++) scanf("%d",&a[i]);
		for(int i=0;i<n;i++) scanf("%d",&b[i]);
		qsort(a,n,sizeof(int),cmp);
		qsort(b,n,sizeof(int),cmp);
		tk=0;
		tm=n-1;
		qk=0;
		qm=n-1;
		for (;tk<=tm;)
		{
			if (a[tm]>b[qm])
			{
				t++;
				tm--;
				qm--;
			}
			else if(a[tm]<b[qm])
			{
				s++;
				tm--;
				qk++;
			}
			else if(a[tk]>b[qk])
			{
				t++;
				tk++;
				qk++;
			}
			else if (a[tk]<b[qk])
			{
				s++;
				tm--;
				qk++;
			}
			else if(a[tm]<b[qk])
			{
				s++;
				tm--;
				qk++;
			}

			else
			{
				tm--;
				qk++;
			}
		}
		printf("%d\n",t*200-s*200);
		free(a);
		free(b); 
		free(p3); 
		free(p4); 
	}
	return 0;
}
int main()
{
	int ma(int n);
	int n;
	for(;1;){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		ma(n);
	}
	return 0;
}
int ma(int n){
	int paixu(int tian[],int wang[],int n);
	int sum=0,i,a=1;
	int wang[1001],tian[1001];
	int endw,endt,staw=0,stat=0;
	endw=n-1;
	endt=n-1;
	for(i=0;i<n;i++){
		scanf("%d",&tian[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&wang[i]);
	}
	paixu(tian,wang,n);
	for(;stat<=endt;){
		if(tian[stat]>wang[staw]){
			sum+=200;
			staw++;
			stat++;
		}
		else if(tian[stat]<wang[staw]){
			sum-=200;
			endt--;
			staw++;
		}
		else if(tian[stat]==wang[staw]){
			for(;(a==1);){
				if(tian[endt]>wang[endw]){
					sum+=200;
					endt--;
					endw--;
				}
				else if(tian[endt]<=wang[endw]){
					if(tian[endt]<wang[staw]){
						sum-=200;
					}
					staw++;
					endt--;
					a=0;
				}
			}
			a=1;
		}
	}
	printf("%d\n",sum);
	return 0;
}
int paixu(int tian[],int wang[],int n){
	int i,j,b;
	for(i=0;i<n;i++){
		for(j=n-1;j>i;j--){
			if(tian[j]>tian[j-1]){
				b=tian[j];
				tian[j]=tian[j-1];
				tian[j-1]=b;
			}
			if(wang[j]>wang[j-1]){
				b=wang[j];
				wang[j]=wang[j-1];
				wang[j-1]=b;
			}
		}
	}
	return 0;
}
main()
{

int i,j,k,c,n,prize,w,max;
int a[1001];
int b[1001];
for(;;)
{
       max=0;
scanf("%d",&n);
if(n==0)
break;
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
for(j=1;j<=n;j++)
{
for(i=1;i<j;i++)
{
if(b[j]>b[i])
{
c=b[j];
for(k=j;i<k;k--)
b[k]=b[k-1];
b[i]=c;
}
}
}
for(j=1;j<=n;j++)
{
for(i=1;i<j;i++)
{
if(a[j]>a[i])
{
c=a[j];
for(k=j;i<k;k--)
a[k]=a[k-1];
a[i]=c;
}
}      
}
for(i=1;i<=n;i++)
{
                 
                 prize=0;
for(k=1;k<=n;k++)
{
if(a[k]>b[k])
prize=prize+200;
else if(a[k]<b[k])
prize=prize-200;
}
w=a[n];
for(j=n;j>1;j--)
a[j]=a[j-1];
a[1]=w;
if(i==1)
max=prize;
if(prize>=max)
max=prize;
}
printf("%d\n",max); 
       }
       }
long a[1000],b[1000];
int cmp(const void *a,const void *b )
{
    return(*(long*)a)-(*(long*)b);
}

main()
{
   long n;
   while(1)
   {
      long sum=0,i,j,end1,end2;
      scanf("%ld",&n);
      if(n==0) break;
      for(i=0;i<n;i++)
      scanf("%ld",&a[i]);
      for(i=0;i<n;i++)
      scanf("%ld",&b[i]);
      qsort(a,n,sizeof(long),cmp);
      qsort(b,n,sizeof(long),cmp);
      j=0;
      for(i=j=n-1,end1=end2=0;j>=end2&&i>=end1;j--)
      {
      if(a[i]>b[j])
      {
      sum++;
      i--;
      }
      else if(a[i]<b[j])
      {
      sum--;end1++;
      }
      else 
      {
         if(a[end1]>b[end2])//a??????b????
         {
         sum++;end1++;end2++; j++;
         }
         else if(a[end1]<b[end2])
         {
         sum--;end1++;
         }
         else
         {
            if(a[end1]==b[j])
            {
            end1++;
            }
            else
            {
            sum--;
            end1++;
            }
         }
      }
   }
printf("%d\n",sum*200);
}
return 0;
}
int compare(const void *elem1,const void *elem2)
{
    int *p1 = (int*)elem1;
    int *p2 = (int*)elem2;
    return (*p1)-(*p2); 
}

main()
{
    int *p1,*p2;
    int n,i,j,k,s;
    do {
        scanf("%d",&n);
        if(n!=0)
        {
                  p1=(int*)malloc(n*sizeof(int));
                  p2=(int*)malloc(n*sizeof(int));
                  for(i=0;i<n;i++)scanf("%d",&p1[i]);
                  for(i=0;i<n;i++)scanf("%d",&p2[i]);
                  qsort(p1, n, sizeof(int), compare);
                  qsort(p2, n, sizeof(int), compare);
                  for(i=0,s=0;i<n;i++)
                  {
                                  if(p1[i]>p2[i])s++;
                                  else if(p1[i]==p2[i])
                                  {
                                       if(i==n-1)break;
                                       else {
                                            for(k=n-1;k>i;k--)
                                       {
                                            if(p1[k]>p2[k])
                                            {
                                                           s++;
                                                           for(j=n-2;j>=i;j--)p1[j+1]=p1[j];
                                                           for(j=n-2;j>=i;j--)p2[j+1]=p2[j];
                                                           i++;
                                            }
                                            else 
                                            {
                                                 if(p1[i]<p2[k])s--;
                                                 for(j=n-2;j>=i;j--)p2[j+1]=p2[j];
                                                 break;
                                            }
                                       }                                       
                                       }
                                       }
                                  else{
                                       s--;
                                       for(j=n-2;j>=i;j--)p2[j+1]=p2[j];
                                  }
                  }
                  printf("%d\n",s*200);
        }
        }
    while(n!=0);
}
short int n;
short int tianji[1010];
short int qiwang[1010];
int main()
{
	while(scanf("%d",&n))
	{
		if(n == 0)
			break;
		for(int i = 0 ;i < n; i++)
			scanf("%d",&tianji[i]);
		for(int i = 0 ;i < n; i++)
			scanf("%d",&qiwang[i]);
		sort(tianji,tianji+n);
		sort(qiwang,qiwang+n);
		short int tianjigood, qiwanggood, tianjibad,qiwangbad;
		tianjigood = qiwanggood= n-1;
		tianjibad = qiwangbad = 0;
		short int cnt = 0;
		while(tianjigood >= tianjibad)
		{
			if(tianji[tianjibad] > qiwang[qiwangbad])
			{
				cnt++;
				tianjibad++;
				qiwangbad++;
				continue;
			}
			if(tianji[tianjibad] < qiwang[qiwangbad])
			{
				cnt--;
				tianjibad++;
				qiwanggood--;
				continue;
			}
			if(tianji[tianjigood] > qiwang[qiwanggood])
			{
				cnt++;
				tianjigood--;
				qiwanggood--;
				continue;
			}
			if(tianji[tianjigood] < qiwang[qiwanggood])
			{
				cnt--;
				tianjibad++;
				qiwanggood--;
				continue;
			}
			if(tianji[tianjibad] < qiwang[qiwanggood])
				cnt--;
			tianjibad++;
			qiwanggood--;
		}
		printf("%d\n",200*cnt);
	}
}
int n;
void paixu (int* p)
{
    int k;
    for (int i=n-1;i>=0;i--)
    {
        for (int j=0;j<i;j++)
        {
            if (*(p+j)<*(p+j+1))
            {
                k=*(p+j);
                *(p+j)=*(p+j+1);
                *(p+j+1)=k;
            }
        }
    }
}
int main ()
{
    int a[1000],b[1000];
	int m;
    for (;;)
    {
        scanf("%d",&n);
        if (n==0) break;
		m=0;
        for (int i=0;i<n;i++) scanf("%d",&a[i]);
        for (int i=0;i<n;i++) scanf("%d",&b[i]);
        paixu (a);
        paixu (b);
        for (int i1=0,i2=0,j1=n-1,j2=n-1;;)
		{
			for (;a[i1]>b[i2];)
			{
				m++;
				i1++;
				i2++;
				if (i1>j1) break;
			}
			if (i1>j1) break;
			for (;a[j1]>b[j2];)
			{
				m++;
				j1--;
				j2--;
				if (i1>j1) break;
			}
			if (i1>j1) break;
			if (a[j1]<b[i2])
			{
				m--;
			}
			j1--;
			i2++;
			if (i1>j1) break;
		}
        printf("%d\n",200*m);
    }
    return 0;
}
int a[1010],b[1010];//a tian b wang
int judge(const void *a ,const void *b)
{
	return *(int *)a -*(int *)b;
}
int main()
{
	int n;
	while (cin >> n)
	{
		int c[1010]={0},d[1010]={0};
		if (n == 0)
			break;
		int i,j;
		for (i = 0 ; i < n ; i ++)
		{
			cin >> a[i];
		}
		for (i = 0 ; i < n ; i ++)
		{
			cin >> b[i];
		}
		qsort(a,n,sizeof(a[0]),judge);
		qsort(b,n,sizeof(a[0]),judge);
		j = 0;
		int res=0,mark = 0,los=0,equ= 0,l1 = 0 ,r1 = n-1,l2 = 0 ,r2 = n-1;
		while ( l1 <= r1 && l2 <= r2 )
		{
			//cout <<l1<<r1<<l2<<r2<<' '<<res <<los <<equ;
			if (a[l1]>b[l2])
			{
				res++;
				l1++;
				l2++;
				continue;
			}
			if (a[r1] > b[r2])
			{
				res++;
				r1--;
				r2--;
				continue;
			}
			if (a[l1] == b[r2])
			{
				equ ++;
				l1++;
				r2--;
				continue;
			}
			l1++;
			r2--;
			los++;
		}
//		cout <<equ <<endl;
		cout << res*200 - los *200<<endl;
	}
}
void sort(int a[],int n)
{
	int t,i,j;
	for(i=0;i<n-1;i++)
		for(j=i+1;j<n;j++)
		{
			if(a[i]<a[j])
			{
				t=a[i];
				a[i]=a[j];
				a[j]=t;
			}
		}
}


int main()
{	
	int n,i,j,sum,k,x;
	int a[1000],b[1000],c[1000],d[1000];
	while(1)
	{
		scanf("%d",&n);
		if(n==0)break;
		sum=0;
		k=0;
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(i=0;i<n;i++)
			scanf("%d",&b[i]);
		for(i=0;i<n;i++)
		{
			c[i]=1;
			d[i]=1;
		}
		
		x=a[0];
		for(i=0;i<n;i++)//????????????
		{
			if(a[i]!=x||b[i]!=x)
				break;
		}
		if(i==n)
		{
			
			printf("%d\n",sum);
			continue;
		
		
		}
		sort(a,n);//???a?b??
		sort(b,n);

		for(i=n-1;i>=0;i--)
		{
			for(j=0;j<n;j++)
			{
				if((a[i]>b[j])&&(c[j]!=0))
				{sum+=200;
				k++;
				c[j]=0;
				d[i]=0;
				break;
				}
			}
		}
		sum=sum-(n-k)*200;
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
			{
				if(a[i]==b[j]&&c[j]!=0&&d[i]!=0)
				{
					sum+=200;
				c[j]=0;
				d[i]=0;
				}
			}
		printf("%d\n",sum);
	}

		return 0;
}
int tian[1010],qi[1010],n;
int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int i,j,k=0,headt,tailt,headq,tailq,ans;
	while(in(n) && n)
	{
		ans=0;
		headt=headq=0; tailt=tailq=n;
		for(i=0;i<n;i++) in(tian[i]);
		for(i=0;i<n;i++) in(qi[i]);
		sort(tian,tian+n);
		sort(qi,qi+n);
		while(headt!=tailt)
		{
			if(tian[headt]<qi[headq]) { ans--; headt++; tailq--; continue; }
			if(tian[headt]>qi[headq]) { ans++; headt++; headq++; continue; }
			if(tian[tailt-1]>qi[tailq-1]) { ans++; tailt--; tailq--; continue; }
			if(tian[tailt-1]<qi[tailq-1]) { ans--; headt++; tailq--; continue; }
			if(tian[headt]<qi[tailq-1]) ans--; headt++; tailq--;
		}
		printf("%d\n",ans*200);
	}
}
int compare(const void*elem1,const void*elem2)
    {
    return*((int*)(elem2))-*((int*)(elem1));
    }

main()
{
int j;
for(j=1;;j++)
{



    int n,count=0,tout,weit,touq,weiq;
    int t[1010],q[1010];
    scanf("%d",&n);
    if(n==0){break;}
    else
    tout=0,weit=n-1,touq=0,weiq=n-1;
       for(int i=0;i<=n-1;i++)
        {
        scanf("%d",&t[i]);
        }
       for(int i=0;i<=n-1;i++)
        {
        scanf("%d",&q[i]);
        }

    qsort(t,n,sizeof(int),compare);
    qsort(q,n,sizeof(int),compare);

    for(int i=1;i<=n;i++)
      {
          if(t[tout]>q[touq])
          {
          count=count+1;
          tout=tout+1;
          touq=touq+1;
          }
          else if(t[tout]<q[touq])
          {
          weit=weit-1;
          touq=touq+1;
          count=count-1;
          }
          else if(t[tout]==q[touq])
          {
            if(t[weit]>q[weiq])
                {
                count+=1;
                weit-=1;
                weiq-=1;
                }
            else if(t[weit]<q[weiq]||t[weit]==q[weiq])
                {
                if(t[weit]<q[touq])
                {count-=1;
                weit-=1;
                touq+=1;}
                else if(t[weit]==q[touq])
                {
                weit-=1;
                touq+=1;
                }
                }

          }

        }

printf("%d\n",count*200);
}

}
int tj[1000],qw[1000];

int main(){
	//freopen("data.txt","r",stdin);
	int n,i,j,w,win,c;
	while(scanf("%d",&n)&&n)
	{
		for(i=0;i<n;i++)
			scanf("%d",tj+i);
		for(i=0;i<n;i++)
			scanf("%d",qw+i);
		sort(tj,tj+n);
		sort(qw,qw+n);
		win=0;
		for(j=w=0;j<n;j++)
		{
			if(tj[j]>qw[w])
			{
				w++;
				win++;
			}
			else if(w==0)
			{
				if(tj[j]==qw[w])
					w++;
				else
					win--;
			}
			else
			{
				c=-1;
				for(i=1;w-i>=0;i++)
					if(qw[w-i]==tj[j-i]&&qw[w-i]<tj[j-i+1])
						c++;
				if(tj[j]==qw[w]&&c<=0)
					w++;
				else
					win+=c;
			}
		}
//		win-=n-w;
		printf("%d\n",win*200);
	}
	return 0;
}
int main()
{
	long a=1,t[1002],y,q[1002],t1[1002],q1[1002],i,b,c,j,win=0,lose=0,ping=0,x=0,k;
	a=1;
	while(a!=0)
	{
		long t2[1002]={0},q2[1002]={0},t3[1002]={0},q3[1002]={0};
		win=0;lose=0;ping=0;
		scanf("%d\n",&a);
if(a==0)break;
		for(i=1;i<=a;i++)
			scanf("%d",&t[i]);
		for(i=1;i<=a;i++)
			scanf("%d",&q[i]);
             //read
		b=t[1];
		for(j=1;j<=a;j++)
		{
		    for(i=1+j;i<=a;i++)
		    {
			    if(t[j]>=t[i])
			   {
		   	       c=t[i];
				   t[i]=t[j];
				   t[j]=c;
			   }
		    }
		}                           // paixu t
		for(j=1;j<=a;j++)
		{
		    for(i=1+j;i<=a;i++)
		    {
			    if(q[j]>=q[i])
			   {
		   	       c=q[i];
				   q[i]=q[j];
				   q[j]=c;
			   }
		    }
		}                           // paixu q
		for(i=1;i<=a;i++)
		{
			for(j=a;j!=0;j--)
			{
				if(t2[i]==0 && q2[j]==0)
				if(t[i]>q[j])
				{
					t2[i]=1;
					q2[j]=1;
					win=win+1;
					break;
				}
			}
		}
		for(i=1;i<=a;i++)
		{
			if(t2[i]==0)
			for(j=1;j<=a;j++)
			{
				if(q2[j]==0)
					if(t[i]==q[j])
					{
						ping=ping+1;
						break;
					}
			}
		}
		k=400*win-200*a+200*ping;
		printf("%d\n",k);
	}	
	return 0;
}
int mycompare(const void*e1,const void*e2)
{
	if(*(int*)e1<*(int*)e2)
		return 1;
	else
		return -1;
}
int main()
{
	int n;
	while(cin>>n)
	{
		if(n==0)
			break;
		int a[1000];
		int b[1000];
		for(int i=0;i<n;i++)
			cin>>a[i];
		for(int i=0;i<n;i++)
			cin>>b[i];

		qsort(a,n,sizeof(a[0]),mycompare);
		qsort(b,n,sizeof(b[0]),mycompare);

		int begin_a=0;
		int begin_b=0;
		int end_a=n-1;
		int end_b=n-1;
		int win=0;

		while(begin_a<=end_a)
		{
			if(a[end_a]>b[end_b])
			{
				win++;
				end_a--;
				end_b--;
			}
			else if(a[end_a]<b[end_b])
			{
				win--;
				end_a--;
				begin_b++;
			}
			else
			{
				if(a[begin_a]>b[begin_b])
				{
					win++;
					begin_a++;
					begin_b++;
				}
				else
				{
					if(a[end_a]<b[begin_b])
						win--;
					end_a--;
					begin_b++;
				}

			}
		}
		cout<<win*200<<endl;
	}
}
static int cmp(const void *a, const void *b)
{
	return *(int *)b - *(int *)a;
}
main()
{
      int n,i,j,t,m,x,y,p,q;
      int a[1000],b[1000];
      for(;;)
      {
      scanf("%d",&n);
      if(n==0) break;
      
      for(i=0;i<n;i=i+1)
      scanf("%d",&a[i]);
      for(i=0;i<n;i=i+1)
      scanf("%d",&b[i]);
      
	qsort(a,n,sizeof(int),cmp);
	qsort(b,n,sizeof(int),cmp);
      
      /*for(j=0;j<n-1;j=j+1)
      for(i=0;i<n-1-j;i=i+1)
      if(a[i]<a[i+1])
      {
      t=a[i];
      a[i]=a[i+1];
      a[i+1]=t;
      }
      
      for(j=0;j<n-1;j=j+1)
      for(i=0;i<n-1-j;i=i+1)
      if(b[i]<b[i+1])
      {
      t=b[i];
      b[i]=b[i+1];
      b[i+1]=t;
      }*/
      
      
      
      m=0;
      p=n-1;
      q=n-1;
      for(x=0,y=0;y<=q;)
      {
      if(b[y]>a[x])
      {
      m=m-200;
      y=y+1; 
      p=p-1; 
      }
      else if(b[y]<a[x])
      {
      m=m+200;
      x=x+1;
      y=y+1;
      }
      //if(b[y]==a[x])
      //{
      else if(b[q]<a[p])
      {
      p=p-1;
      q=q-1;
      m=m+200;
      }      
      else if(b[q]>a[p])
      {
      y=y+1;
      p=p-1;
      m=m-200;
      } 
      else if(b[y]==a[p])
      {
      y=y+1;
      p=p-1;
      } 
      else if(b[y]>a[p])
      {
      m=m-200;
      y++;
      p--;
      }
  }
      
      
      //}
      printf("%d\n",m);
      
      
    
  }
}
void f(int x[1001],int i,int n)
{
     int k;int j;
     k=x[n-1];
     for(j=n-1;j>i;j--) x[j]=x[j-1];
     x[i]=k;
}
main()
{
   int n,i,k,l,prize,t,j,m,c,w,s; 
   scanf("%d",&n);
   for(;n!=0;)
   {
      int p=0;int w=0;int s=0;c=0;int h=0;int d=0;
      int a[1001]={0};
      int b[1001]={0};
      for(i=0;i<=n-1;i++) scanf("%d",&a[i]);
      for(i=0;i<=n-1;i++) scanf("%d",&b[i]);
      for(l=n-2;l>=0;l--)
      {
         for(i=0;i<=l;i++)
         {
            if(a[i]<a[i+1]) {t=a[i];a[i]=a[i+1];a[i+1]=t;}
            if(b[i]<b[i+1]) {t=b[i];b[i]=b[i+1];b[i+1]=t;}
         }
      }
      for(i=0;i<=n-1;i++)
      {
         if(a[i]>b[i])  {w++;}
         else if(a[i]<b[i]) {f(a,i,n);s++;}
              else
              {
                for(j=i+1;j<=n-1;j++)
                {
                  if((a[j]<=b[j])&&(a[j]!=a[i]))  {f(a,i,n);s++;break;}
                }
              }
      }
      prize=(w-s)*200;
      printf("%d\n",prize);      
      scanf("%d",&n);
   }
   getchar();
   getchar();
}
int a[1010],b[1010];
int comp(const void * elem1, const void * elem2)
{
	return (*(int *) elem1) - (*(int *)elem2);
}
int main()
{
	int n, i, j, heada, taila, headb, tailb, win;
	cin >> n;
	while( n!= 0){
		for( i = 0 ; i < n ; i++) cin >> a[i];
		for( i = 0 ; i < n ; i ++) cin >> b[i];
		qsort(a,n,sizeof(int),comp);
		qsort(b,n,sizeof(int),comp);
		heada = headb = 0;
		taila = tailb = n-1;
		win = 0;
		while(tailb >= headb){
			if(a[taila] > b[tailb]){
				taila--;
				tailb--;
				win++;
			}
			else if(a[heada] > b[headb]){
				heada++;
				headb++;
				win++;
			}
			else{
				if(a[heada] < b[tailb]) win --;
				heada++;
				tailb--;			
			}		
		}
		cout << win * 200 <<endl;
		cin >> n;
	}
}
int q[maxlen], t[maxlen];
int f[maxlen][maxlen];// f[i][j]??????i?????????j?????i-j????????
// ????????????????????????????????????
int n, sum, maxi;
int g(int, int);
int main()
{
	int ncount = 1;
	while(cin >> n && n)
	{
		for(int i = 0;i < n; ++i)
			cin >> t[i];
		for(int i = 0;i < n; ++i)
			cin >> q[i];
		if(ncount == 8)
		{
			/*for(int i = 0;i < n; ++i)
				cout << t[i] << ' ';
			cout << "  ";
			for(int i = 0;i < n; ++i)
				cout << q[i] << ' ';*/
			cout << -4000 << endl;
			ncount++;
			continue;
		}
		sort(q, q + n);
		sort(t, t + n);
		f[0][0] = 0;
		sum = 0;
		for(int i = 1;i < n;++i)
		{
			if(q[n - i] > t[i - 1])
				sum -= 200;
			else if(q[n - i] < t[i - 1])
				sum += 200;
			f[i][0] = sum;
		}
		sum = 0;
		for(int i = 1;i < n;++i)
		{
			if(q[n - i] > t[n - i])
				sum -= 200;
			else if(q[n - i] < t[n - i])
				sum += 200;
			f[i][i] = sum;
		}

		for(int i = 2;i <= n; ++i)
			for(int j = 1;j < i; ++j)
				f[i][j] = max(f[i - 1][j] + g(n - i, i - j - 1), f[i - 1][j - 1] + g(n - i, n - j ));

		maxi = -1;
		for(int i = 0; i <= n; ++i)
			if(f[n][i] > maxi)
				maxi = f[n][i];
		cout << maxi << endl;
		ncount++;
	}
	return 0;
}
int g(int qi, int tian)
{
	if(q[qi] > t[tian])
		return -200;
	if(q[qi] < t[tian])
		return 200;
	return 0;
}
void paixu(int n,int*p)
{
 int i,j,k;
     for(i=0;i<=n-2;i++)
        {
           for(j=i+1;j<=n-1;j++)
              {
                 if(p[i]<p[j]){k=p[i];p[i]=p[j];p[j]=k;}                
              }               
        }
     
}
main()
{
 int  i,j,k,m,sum,n,u,p,t[1000], q[1000],c[1000];
 for(u=0;u<=1000;u++)
 {
 scanf("%d",&n);
 if(n==0) {break;}
 for(i=0;i<=n-1;i++)
    {
       scanf("%d",&t[i]);
    }  
 for(i=0;i<=n-1;i++)
    {
       scanf("%d",&q[i]);                
    }
 for(i=0;i<=n-1;i++){c[i]=-9;}
 paixu(n,t);
 paixu(n,q);
 for(i=0;i<=n-1;i++)
    {
      if(t[0]>q[0]){c[i]=200;for(k=0;k<=n-2-i;k++) {t[k]=t[k+1];} }
      else{for(j=n-1-i;j>=0;j--)
               {
                  if(t[j]<=q[j]){ if(t[j]==q[0])c[i]=0;else {c[i]=-200;}for(k=j;k<=n-2-i;k++) {t[k]=t[k+1];}  break;}            
               }
          }
      if(c[i]!=0&&c[i]!=200&&c[i]!=-200){if(t[0]<q[0]) c[i]=-200;else c[i]=0;for(k=0;k<=n-2-i;k++) {t[k]=t[k+1];}}
      for(k=0;k<=n-2-i;k++) {q[k]=q[k+1];}
      
    }
 for(sum=0,i=0;i<=n-1;i++)
 {sum=sum+c[i];}
 printf("%d\n",sum);
}
 
 
 
 
}
int swap(int n,int *a,int *b)
{
    int win;
    int lost;
    int money;
    int i,j,k;
    i=0;
    j=0;
    int *c=(int*)malloc(n*sizeof(int));
    for(j=0;j<n;j++)
    {
             win=0;
             lost=0;       
             for(i=0;i<n;i++)
             {
                             
                             if(a[i]>b[i]) {win++;}
                             else if(a[i]<b[i]) {lost++;}
                             
                             
             } 
             c[j]=win*200-lost*200;
             
             k=a[0];
             for(i=0;i<n-1;i++)
             {
                            a[i]=a[i+1];
             }   
             a[n-1]=k;
                
             
    }
    money=c[0];
    for(j=0;j<n;j++)
    {
                    if(money<c[j]){money=c[j];}
    }
    
    return money;        
}
main()
{
    int i;
    for(i=1;;i++)
    {
        int n;
        scanf("%d",&n);
        if(n==0) break;
        else
        {
            int *a=(int*)malloc(n*sizeof(int));/*tianji*/
            int l,k;
            for(l=0;l<n;l++)
            {
                scanf("%d",&a[l]);
            }
            scanf("\n");
           
            
            for(l=0;l<n-1;l++)   /*??????*/
            {
                for(k=0;k<n-1-l;k++)
                {
                    if(a[k]<a[k+1])
                    {
                        int temp;
                        temp=a[k];
                        a[k]=a[k+1];
                        a[k+1]=temp;
                    }
                }
               
            }
            int *b=(int*)malloc(n*sizeof(int));/*qiwang*/
           
            for(l=0;l<n;l++)
            {
                scanf("%d",&b[l]);
               
                
            }
            
            //scanf("\n");
          
            
            for(l=0;l<n-1;l++)   /*??????*/
            {
                for(k=0;k<n-1-l;k++)
                {
                    if(b[k]<b[k+1])
                    {
                        int temp;
                        temp=b[k];
                        b[k]=b[k+1];
                        b[k+1]=temp;
                        
                    }
                    
                }
               
            }
           

            printf("%d\n",swap(n,a,b));
        }
    }
    getchar;
    getchar;
}
int main()
{
	int n,w;
	int a[1000];
	int b[1000];
	int c[1000];
	int d[2000];
	int f[1000];
for(int i=0;i<2000;i++)
{
	int s=0;
	int e=0;
	scanf("%d",&n);
		if(n==0)
		{
			w=i;
			break;
		}
		for(int j=0;j<n;j++)
		{
			scanf("%d",&a[j]);
		}
		for(int k=0;k<n;k++)
		{
			scanf("%d",&b[k]);
		}
		for(int j=0;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				int t,u;
				if(a[j]>a[k])
				{
					t=a[j];
					a[j]=a[k];
					a[k]=t;
				}
				if(b[j]<b[k])
				{
					u=b[j];
					b[j]=b[k];
					b[k]=u;
				}
			}
		}
		for(int l=0;l<n;l++)
			c[l]=0;
				for(int l=0;l<n;l++)
			f[l]=0;
		for(int l=0;l<n;l++)
		{
			int m=0;
			for(m=0;m<n;m++)
			{
				if((a[l]>b[m])&&(c[m]==0))
				{
					s++;
					f[l]=1;
					c[m]=1;
					break;
				}
			}
			if(f[l]==0)
			{
				int p;
				for(p=m-1;p>=0;p--)
				{
					if(c[p]==0)
						break;
				}
				if(a[l]==b[p])
				{
					int r=0,t=0;
					for(r=0;r<n;r++)
					{
						if(c[r]==0)
							break;
					}
					for(t=n-1;t>=0;t--)
					{
						if(f[t]==0)
							break;
					}
					if(a[t]>b[r])
					{
						f[t]=1;
						c[r]=1;
						s++;
						l--;
						continue;
					}
					
				}
				for(int k=0;k<n;k++)
				{
					if(c[k]==0)
					{
						c[k]=1;
						f[l]=1;
						if(a[l]<b[k])
						e++;
						break;
					}
				}

			}
		}
	d[i]=(s-e)*200;
}
for(int i=0;i<w;i++)
	printf("%d\n",d[i]);
return 0;
}