semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
    int n;
    int i,j,temp=0,num=0,sum1=0,sum2=0,money=0;
    int tian[1000];
    int qi[1000];
    scanf("%d",&n);
    while(n!=0)
    {
    temp=0,num=0,sum1=0,sum2=0,money=0;
    for(i=0;i<n;i++)
    scanf("%d",&tian[i]);
    for(j=0;j<n;j++)
    scanf("%d",&qi[j]);
    
    for(i=0;i<=n-2;i++)
    {
                       for(j=n-1;j>=1;j--)
                       {
                                          if(tian[j]>tian[j-1])
                                          {
                                                               temp=tian[j];
                                                               tian[j]=tian[j-1];
                                                               tian[j-1]=temp;
                                          }
                       }
    }
    
    
     for(i=0;i<=n-2;i++)
    {
                       for(j=n-1;j>=1;j--)
                       {
                                          if(qi[j]>qi[j-1])
                                          {
                                                               temp=qi[j];
                                                               qi[j]=qi[j-1];
                                                               qi[j-1]=temp;
                                          }
                       }
    }
    
    for(i=0;i<n;i++)
    {
                    num=i;
                    for(j=num;j>=0;j--)
                    {
                                       if(tian[j]>qi[i])
                                       {
                                                        sum1=sum1+1;
                                                        tian[j]=0;
                                                         qi[i]=0;
                                                         break;
                                       }          
                    }
    }
    
    for(i=0;i<n;i++)
    {
                   for(j=0;j<n;j++)
                   {
                      if(tian[i]==qi[j]&&tian[i]!=0)
                      {
                                   sum2++;
                                   break;            
                      }
                   }
    }
    
    money=200*(sum1-(n-sum1-sum2));
    printf("%d\n",money);
    scanf("%d",&n);
}
getchar();
getchar();
}
int find(int a[],int i,int j)
{
	int key=a[i],k,flag=0;
	for(k=i+1;k<=j;k++)
		if(a[k]>key)return k;
		else if(a[k]<key)return i;
	return -1;
}
int partition(int a[],int i,int j,int pivot)
{
	int ta,l=i,r=j;
	do{
		ta=a[l];
		a[l]=a[r];
		a[r]=ta;
		while(a[l]>=pivot)l++;
		while(a[r]<pivot)r--;
	}while(l<=r);
	return l;
}
void quicksort(int a[],int i,int j)
{
	int pindex,pivot,k;	
	pindex=find(a,i,j);
	if(pindex>=0)
	{
		pivot=a[pindex];
		k=partition(a,i,j,pivot);
		quicksort(a,i,k-1);
		quicksort(a,k,j);
	}
}


int main()
{
	int n,i,j,k,t_max,t_min,q[1000],t[1000],win,loss;
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
			return 0;
		for(i=0;i<n;i++)
		{
			scanf("%d",&t[i]);
		}
		for(i=0;i<n;i++)
		{
			scanf("%d",&q[i]);
		}
		quicksort(t,0,n-1);
		quicksort(q,0,n-1);
		t_max=0;
		t_min=n-1;
		win=loss=0;
		for(i=0;i<n;i++)
		{
			if(t[t_max]>q[i])
			{
				win++;
				t_max++;
			}
			else if(t[t_max]<q[i])
			{
				loss++;
				t_min--;
			}
			else if(t[t_max]==q[i])
			{
				for(j=i+1,k=t_max+1;j<n;j++,k++)
				{
					if(t[k]<=q[j]&&t[t_max]>q[j])
						break;
				}
				if(j<n)
				{
					if(t[t_min]<q[i])
						loss++;
					t_min--;
				}
				else t_max++;
			}
		}
		printf("%d\n",200*(win-loss));
	}
}
int main(){
    int n, i, j, s, k;
    int a[1001], b[1001];
    while(scanf("%d", &n), n){
        for(i = 0; i < n; i++){
            scanf("%d", &a[i]);
            for(j = i-1; j >= 0; j--){
                if(a[j] < a[j+1]){
                    a[j] += a[j+1];
                    a[j+1] = a[j]-a[j+1];
                    a[j] -= a[j+1];
                }
            }
        }
        for(i = 0; i < n; i++){
            scanf("%d", &b[i]);
            for(j = i-1; j >= 0; j--){
                if(b[j] < b[j+1]){
                    b[j] += b[j+1];
                    b[j+1] = b[j]-b[j+1];
                    b[j] -= b[j+1];
                }
            }
        }
        j = 0;
        s = 0;
        k = n-1;
        for(i = 0; i < n && j <= k;){
            if(a[j] < b[i]){
                s--;
                k--;
                i++;
            }
            else if(a[j] == b[i] ){
                if(a[k] < b[n-1]){
                    s--;
                    i++;
                    k--;
                }
                else if(a[k] > b[n-1]){
                    s++;
                    n--;
                    k--;
                }
                else if(a[k] == b[n-1]){
                    if(a[k] != b[i]){
                        s--;
                        i++;
                        k--;
                    }
                    else break;
                }
            }
            else{
                s++;
                i++;
                j++;
            }
        }
        printf("%d\n", s*200);
    }
    return 0;
}
int main()
{
    int saima(int n,int qiwang[1000],int tianji[1000]);
    int n,i,j;
    int tianji[1000]={0},qiwang[1000]={0};
    scanf("%d",&n);
    for (i=0;n!=0;i++){
        for (j=0;j<n;j++){
            scanf("%d",&tianji[j]);
            }
        for (j=0;j<n;j++){
            scanf("%d",&qiwang[j]);
            }
        printf("%d\n",saima(n,qiwang,tianji));
        scanf("%d",&n);
        }
    return 0;
}
int saima(int n,int qiwang[1000],int tianji[1000])
{
    void seq(int n,int a[1000]);
    void del(int i, int n, int a[1000]);
    int i,win;
    seq(n,tianji);
    seq(n,qiwang);
    win=0;
    while (n>0){
         if ((tianji[n-1]!=qiwang[n-1])&&(n>0)){
            if (tianji[n-1]>qiwang[n-1]){
                win=win+200;
                del(n-1,n,tianji);
                del(n-1,n,qiwang);
                n=n-1;
                }
            else{
                 win=win-200;
                 del(n-1,n,tianji);
                 del(0,n,qiwang);
                 n=n-1;                    
                 }
            }
        if ((tianji[0]!=qiwang[0])&&(n>0)){
            if (tianji[0]>qiwang[0]){
                win=win+200;
                del(0,n,tianji);
                del(0,n,qiwang);
                n=n-1;
                }
            else{
                 win=win-200;
                 del(n-1,n,tianji);
                 del(0,n,qiwang);
                 n=n-1;
                 }
            }
        if ((tianji[0]==qiwang[0])&&(tianji[n-1]==qiwang[n-1])&&(n>0)){
            if (tianji[n-1]<qiwang[0]){
                win=win-200;
                }
            del(n-1,n,tianji);
            del(0,n,qiwang);
            n=n-1;              
            }

        }
        return(win);    
}
void seq(int n,int a[1000])
{
       int i,j,temp;
       for (i=0;i<n;i++){
        for (j=0;j<n-1-i;j++){
            if (a[j]<a[j+1]){
                             temp=a[j];
                             a[j]=a[j+1];
                             a[j+1]=temp;
                             }
            }
        }
     }
void del(int i,int n,int a[1000])
{
     int j;
     for (j=i;j<n;j++){
         a[j]=a[j+1];
         }
     }
int a[2000],b[2000];
int i,j,k,n,x,y,p,q,ans;

int main()
{
	while (scanf("%d",&n),n)
	{
		for (i=0;i<n;++i)
			scanf("%d",&a[i]);
		for (i=0;i<n;++i)
			scanf("%d",&b[i]);
		sort(a,a+n);
		sort(b,b+n);
		x=0;
		y=n-1;
		p=0;
		q=n-1;
		ans=0;
		while (x<=y)
		{
			while (x<=y&&a[x]>b[p])
			{
				++ans;
				++x;
				++p;
			}
			while (x<=y&&a[y]>b[q])
			{
				++ans;
				--y;
				--q;
			}
			if (x<=y)
			{
				if (a[x]<b[q])
					--ans;
				++x;
				--q;
			}
		}
		cout<<ans*200<<endl;
	}
	return 0;
}
int cmp(const void *elem1, const void *elem2){
  int *e1 = (int *)elem1;
  int *e2 = (int *)elem2;
  return *e2-*e1;
}

int main(){
  int n;
  int data1[1005];
  int data2[1005];
  int i;
  int i1, i2, j1, j2;
  int result;
  while(true){
    cin>>n;
    if(n==0) break;
    for(i=0; i<n; i++)
      cin>>data1[i];
    for(i=0; i<n; i++)
      cin>>data2[i];
    qsort(data1, n, sizeof(int), cmp);
    qsort(data2, n, sizeof(int), cmp);
    i1=0;
    j1=0;
    i2=n-1;
    j2=n-1;
    result=0;
    while(i1!=i2+1){
      while(data1[i1]!=data2[j1] && i1!=i2+1){
	if(data1[i1]<data2[j1]){
	  i2--;
	  j1++;
	  result-=200;
	}
	else if(data1[i1]>data2[j1]){
	  i1++;
	  j1++;
	  result+=200;
	}
	else break;
      }
      while(data1[i2]!=data2[j2] && i1!=i2+1){
	if(data1[i2]<data2[j2]){
	  j1++;
	  i2--;
	  result-=200;
	}
	else if(data1[i2]>data2[j2]){
	  i2--;
	  j2--;
	  result+=200;
	}
	else break;
      }
      if(data1[i1]==data2[j1] && data1[i2]==data2[j2] && i1!=i2+1){
	if(data1[i2]!=data2[j1])
	  result-=200;
	i2--;
	j1++;
      }
    }
    cout<<result<<endl;
  }
  return 0;
}
//??????????
//?????????????????????????????

//????????????????????????????

//?????????????????????????????????



int mycompare(const void* a ,const void *b);
int main()
{
	int n,i,j,s,t,m,k;
	int tian[1001],qi[1001];
	while(cin>>n)
	{
		if(n==0)  break;
		for(i=0;i<n;i++)
			cin>>tian[i];
		for(i=0;i<n;i++)
			cin>>qi[i];
		qsort(tian,n,sizeof(int),mycompare);
		qsort(qi,n,sizeof(int),mycompare);
		s=0;
		for(i=0,m=0,j=n-1,k=n-1;i<=k;)
		{
			if(tian[m]>qi[i])
			{
				s++;
				m++;i++;
			}
			else if(tian[j]>qi[k]) { s++;j--;k--;}
			else 
			{
				if(tian[j]<qi[i])  s--;
				j--;i++;

			}
		}
		cout<<s*200<<endl;
	}
	return 0;

}
int mycompare(const void* a ,const void *b)
{
	return *(int*)b- *(int*)a;
}
int n;
int a[1001];
int b[1001];


int mycompare(const void *p1,const void *p2)
{
	int *a1,*a2;
	a1 = (int *)p1;
	a2 = (int *)p2;
	return *a2 - *a1;
}

int main()
{
	int i,j,k1,k2;
	int la,lb,ra,rb;
	int total;

	while(true)
	{
		cin >> n;
		if (n == 0) break;

		for (i = 0;i < n;i ++) scanf("%d",&a[i]);
		for (i = 0;i < n;i ++) scanf("%d",&b[i]);

		qsort(a,n,sizeof(int),mycompare);
		qsort(b,n,sizeof(int),mycompare);

		total = 0;
		la = 0; lb = 0;
		ra = n - 1; rb = n - 1;

		while (la <= ra)
		{
			if (a[la] > b[lb])
			{
				total = total + 200;
				la ++;
				lb ++;
			}
			else
			{
				if (a[la] < b[lb])
				{
					total = total - 200;
					lb ++;
					ra --;
				}
				else
				{

					for (k1 = ra,k2 = rb;la <= k1; k1 --,k2 --)
					{
						if (a[k1] > b[k2])
						{
							total = total + 200;
							ra --;
							rb --;
						}
						else
						{
							if (a[k1] < b[lb]) total = total - 200;
							ra = k1;
							rb = k2;
							ra --;
							lb ++;
							break;
						}
					}
				}
			}
		}
		cout << total << endl;
	}
	return 0;
}
int main()
{
	while(1)
	{
		int i,n;
		scanf("%d",&n);
		if(n==0)
			break;
		int t[1000]={0},q[1000]={0};
		for(i=0;i<n;i++)
			scanf("%d",&t[i]);
		for(i=0;i<n;i++)
			scanf("%d",&q[i]);
		for(i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(t[j]>t[i])
				{
					int temp=t[j];
					t[j]=t[i];
					t[i]=temp;
				}
			}
		}
		for(i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(q[j]>q[i])
				{
					int temp=q[j];
					q[j]=q[i];
					q[i]=temp;
				}
			}
		}
		int i1=n-1,i2=n-1,j1=0,j2=0;
		int win=0,lose=0;
		while(i1>=j1&&i2>=j2)
		{
			if(t[i1]>q[i2])
			{
				win++;
				i1--;i2--;
				continue;
			}
			if(t[i1]<q[i2])
			{
				lose++;
				i1--;j2++;
				continue;
			}
			if(t[i1]==q[i2])
			{
				if(t[j1]>q[j2])
				{
					win++;
					j1++;j2++;
					continue;
				}
				if(t[i1]<q[j2])
				{
					lose++;
					i1--;j2++;
					continue;
				}
				else
				{
					break;
				}
			}
		}
		printf("%d\n",(win-lose)*200);
	}
}
int a[1010],b[1010];
int main()
{
    int n;
    while(scanf("%d",&n),n)
    {
        for(int i=1; i<=n; i++)  scanf("%d",&a[i]);
        for(int i=1; i<=n; i++)  scanf("%d",&b[i]);
        sort(a+1,a+1+n);
        sort(b+1,b+1+n);
        int tl=1,tr=n,ql=1,qr=n;
        int sum=0;
        while(tl<=tr)
        {
            if(a[tl]<b[ql])
            {
                qr--;
                tl++;
                sum=sum-200;
            }
            else if(a[tl]==b[ql])
            {
                while(tl<=tr&&ql<=qr)
                {
                    if(a[tr]>b[qr])
                    {
                        sum+=200;
                        tr--;
                        qr--;
                    }
                    else
                    {
                        if(a[tl]<b[qr])  sum-=200;
                        tl++;
                        qr--;
                        break;
                    }
                }
            }
            else
            {
                tl++;
                ql++;
                sum=sum+200;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}
main()
{
      int a,b,t,i,j,j1,j2,k=0,m1,m2,q1,q2,q,n[100],tj[100][1000],qw[100][1000];
      for(i=0;;i++){
      scanf("%d",&n[i]);
      if(n[i]==0)break;
      else{
      for(j=0;j<n[i];j++){scanf("%d",&tj[i][j]);}
      for(j=0;j<n[i];j++){scanf("%d",&qw[i][j]);}
      }k++;}
      for(i=0;i<k;i++){
      for(a=0;a<(n[i]-1);a++){
      for(b=0;b<(n[i]-a-1);b++){
      if(tj[i][b]<tj[i][b+1]){
      t=tj[i][b];
      tj[i][b]=tj[i][b+1];
      tj[i][b+1]=t;}
      if(qw[i][b]<qw[i][b+1]){
      t=qw[i][b];
      qw[i][b]=qw[i][b+1];
      qw[i][b+1]=t;}
      }}
      q1=0;q2=0;q=0;j1=0;j2=0;m1=0;m2=0;
      for(;;){
      if((j1+j2)==(n[i]-1)){
      if(tj[i][j1]>qw[i][m1]){q1++;}
      if(tj[i][j1]==qw[i][m1]){q2++;}
      break;}
      if(tj[i][n[i]-j2-1]>qw[i][n[i]-m2-1]){q1++;j2++;m2++;}
      else{
      if(tj[i][n[i]-j2-1]<qw[i][n[i]-m2-1]){m1++;j2++;}
      else{
      if((tj[i][n[i]-j2-1]==qw[i][n[i]-m2-1])&&(tj[i][j1]>qw[i][m1])){q1++;m1++;j1++;}
      else{
      if((tj[i][n[i]-j2-1]==qw[i][n[i]-m2-1])&&(tj[i][j1]<qw[i][m1])){m1++;j2++;}
      else{
      if((tj[i][n[i]-j2-1]==qw[i][n[i]-m2-1])&&(tj[i][j1]==qw[i][m1])){
      if(qw[i][m1]>tj[i][n[i]-j2-1]){m1++;j2++;}
      else{m1++;j2++;q2++;}}}}}}
      }
      q=q1*200-(n[i]-q1-q2)*200;
      printf("%d\n",q);}
}
int n,a[2000],b[2000],ans;

int main() {
	int i,j,k;
	while (cin>>n && n!=0) {
		for (i=0;i<n;i++) cin>>a[i];
		for (i=0;i<n;i++) cin>>b[i];
		sort(a,a+n);
		sort(b,b+n);
		ans=-200*n;
		for (j=0;j<n;j++) {
			k=0;
			for(i=0;i<n;i++) {
				if(a[i]>b[(i+j)%n]) k+=200;
				if(a[i]<b[(i+j)%n]) k-=200;
			}
			if(k>ans) ans=k;
		}
		cout<<ans<<endl;
	}
	return 0;
}
int mycompare(const void *q1,const void *q2);


int t[1000],q[1000];
int n;

int main()
{
	int i,j;
    while(cin>>n)
	{
		if(n==0) return 0;
    for(i=0;i<n;i++)
    {
		cin>>t[i];
	}
    for(i=0;i<n;i++)
    {
		cin>>q[i];
	}
    qsort(t,n,sizeof(int),mycompare);
	qsort(q,n,sizeof(int),mycompare);
    int ans=0;
	int tf=0,tl=n-1,qf=0,ql=n-1;
	while(qf<=ql)
	{
      if(t[tf]>q[qf])
      {
		  ans++;
		  tf++;
		  qf++;
      }
	  else if(t[tl]>q[ql])
	  {
		  ans++;
		  tl--;
		  ql--;
	  }
	  else
	  {
		  if(t[tf]>q[ql])
		    ans++;
		  else if(t[tf]<q[ql])
			  ans--;
		  tf++;
		  ql--;
	  }
	}
	cout<<ans*200<<endl;
	}
	return 0;
}

int mycompare(const void *q1,const void *q2)
{
	int * p1=(int *)q1;
	int * p2=(int *)q2;
	return *p1-*p2;
}
int main()
{
int n[1000],a[100][2000],b[100][1000],i,j,k,l,c,q[1000],d;
for(i=0;;i++)
{
scanf("%d",&n[i]);
if(n[i]==0)
break;
for(j=0;j<n[i];j++)
scanf("%d",&a[i][j]);
for(j=0;j<n[i];j++)
scanf("%d",&b[i][j]);
}
for(k=0;k<i;k++)
{
for(j=0;j<n[k];j++)
q[j]=0;
for(l=0;l<n[k];l++)
for(j=0;j<n[k]-1;j++)
if(a[k][j]<a[k][j+1])
{
c=a[k][j];a[k][j]=a[k][j+1];a[k][j+1]=c;
}
for(l=0;l<n[k];l++)
for(j=0;j<n[k]-1;j++)
if(b[k][j]<b[k][j+1])
{
c=b[k][j];b[k][j]=b[k][j+1];b[k][j+1]=c;
}
for(j=n[k];j<n[k]*2;j++)
a[k][j]=a[k][j-n[k]];
for(l=0;l<n[k];l++)
{q[l]=0;
for(j=l;j<l+n[k];j++)
if(a[k][j]>b[k][j-l])
q[l]+=200;
else if(a[k][j]<b[k][j-l])
q[l]-=200;}
d=q[0];
for(j=1;j<n[k];j++)
if(q[j]>=d)
d=q[j];
printf("%d\n",d);
}
}
int main(int argc, char *argv[])
{
  int n;
  while(1)
  {
    scanf("%d",&n);
    if(!n)
      break;
    int i=0,s=0,j=n-1,t=n-1,k,r,a[1010],b[1010],m=0;
    for(k=0;k<n;k++)
      scanf("%d",&a[k]);
    for(k=0;k<n;k++)
      scanf("%d",&b[k]);
    
    for(k=n-1;k>0;k--)
    {
      for(r=0;r<k;r++)
      {
        int e;
        if(a[r]<a[r+1])
        {e=a[r];a[r]=a[r+1];a[r+1]=e;}
        if(b[r]<b[r+1])
        {e=b[r];b[r]=b[r+1];b[r+1]=e;}
      }
    }
    
    while(n--)
    {
      if(a[i]>b[s])
      {
        m+=200;
        i++;s++;
      }
      else if(a[j]>b[t])
      {
        m+=200;
        j--;t--;
      }
      else if(a[j]>b[s])
      {
        m+=200;
        j--;s++;
      }
      else if(a[j]<b[s])
      {
        m-=200;
        j--;s++;
      }
      else if(a[j]=b[s])
      {
        j--;s++;
      }
    }
    printf("%d\n",m);
  }
  return 0;
}
int N;
int TJ[MAX];
int QW[MAX];
int main()
{
	int i, j, lt, rt, lq, rq;
	while( scanf("%d",&N) )
	{
		if( N == 0 )  break;
		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);
		lt = 0; rt = N-1; lq = 0; rq = N-1; j = 0;
		while( lt <= rt )
		{
			if( TJ[lt] > QW[lq] )
			{
				j += 200;
				lq++;
				lt++;
			}
			else if( TJ[rt] > QW[rq] )
			{
				j += 200;
				rt--;
				rq--;
			}
			else
			{
				if( TJ[lt] < QW[rq] )  j -= 200;
				lt++;
				rq--;
			}
		}
		printf("%d\n",j);
	}
}
const int MAXN=1005;
main()
{    
     int n;    
     int t[MAXN], k[MAXN];    
     while(cin>>n, n)   
      {       
               int i;        
               for(i=0; i<n; i++) cin>>t[i];        
               for(i=0; i<n; i++) cin>>k[i];        
               sort(t, t+n); sort(k, k+n);        
               int fastT=n-1, slowT=0, fastK=n-1, slowK=0;        
               int total=0;        
               while(slowK<=fastK)        
               {            
                            if(t[fastT] > k[fastK])            
                            {                
                                             total += 200;                
                                             fastT--; 
                                             fastK--;            
                            }            
                            else if(t[fastT] < k[fastK])            
                            {                
                                             total -= 200;                
                                             slowT++; 
                                             fastK--;            
                            }           
                            else            
                            {                
                                             while(slowK<=fastK)                
                                             {                    
                                                                  if(t[slowT] > k[slowK])                    
                                                                  {                        
                                                                                           total += 200;                        
                                                                                           slowT++; 
                                                                                           slowK++;                    
                                                                  }                    
                                                                  else                    
                                                                  {                        
                                                                                           if(t[slowT] < k[fastK]) total -= 200;                        
                                                                                           slowT++; 
                                                                                           fastK--;                        
                                                                                           break;                    
                                                                  }               
                                             }            
                            }        
               }        
               cout<<total<<endl;    
      }    
      return 0;
}
int s[1001][1000];

int MAX(int a, int b)
{
	if(a > b)
		return a;
	else
		return b;
}

int comp(int a, int b)
{
	if(a > b)
		return 200;
	else if(a < b)
		return -200;
	else
		return 0;
}

void main()
{
	int n;
	int i, j;
	int tmp;
	int a[1000], b[1000];

	for(scanf("%d", &n); n > 0; scanf("%d", &n))
	{
		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 - 1; ++i)
			for(j = 0; j < n - i - 1; ++j)
				if(a[j] < a[j + 1])
				{
					tmp = a[j];
					a[j] = a[j + 1];
					a[j + 1] = tmp;
				}
		for(i = 0; i < n - 1; ++i)
			for(j = 0; j < n - i - 1; ++j)
				if(b[j] < b[j + 1])
				{
					tmp = b[j];
					b[j] = b[j + 1];
					b[j + 1] = tmp;
				}
		for(i = 0; i < n; ++i)
			s[0][i] = 0;
		for(i = 1; i <= n; ++i)
			for(j = 0; j <= n - i; ++j)
				s[i][j] = MAX(s[i - 1][j] + comp(a[i - 1], b[j + i - 1]), s[i - 1][j + 1] + comp(a[i - 1], b[j]));
		printf("%d\n", s[n][0]);
	}
}
void main()
{int n,*tian,*lord;
	int i,j,x[500]={0},t,sumnum=0,sum;
	int ta,tb,la,lb;

	scanf("%d",&n);
	while(n!=0)
	{
	tian=(int *)malloc(n*sizeof(int));
	lord=(int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++) scanf("%d",tian+i);
	for(i=0;i<n;i++) scanf("%d",lord+i);
	for(j=0;j<n-1;j++)
		for(i=0;i<n-1-j;i++)
			if(*(tian+i)<*(tian+i+1))
			{
				t=*(tian+i);
				*(tian+i)=*(tian+i+1);
				*(tian+i+1)=t;
			}

	for(j=0;j<n-1;j++)
		for(i=0;i<n-1-j;i++)
			if(*(lord+i)<*(lord+i+1))
			{
				t=*(lord+i);
				*(lord+i)=*(lord+i+1);
				*(lord+i+1)=t;
			}
			ta=0,la=0,tb=n-1,lb=n-1;sum=0;
			while(ta!=tb)
			{
				if(*(tian+tb)<*(lord+lb)) {tb--;la++;sum--;}
				else if(*(tian+tb)>*(lord+lb)) {tb--;lb--;sum++;}
				else if(*(tian+ta)<*(lord+la)) {tb--;la++;sum--;}
				else if(*(tian+ta)>*(lord+la)) {ta++;la++;sum++;}
				else if(*(tian+tb)<*(lord+la)) {tb--;la++;sum--;}
				else if(*(tian+tb)>*(lord+la)) {tb--;la++;sum++;}
				else {tb--;la++;}
			}
			if(*(tian+ta)>*(lord+la)) sum++;
			else if(*(tian+ta)<*(lord+la))sum--;

	x[sumnum]=sum;
	sumnum++;
	scanf("%d",&n);
	}

	for(i=0;i<sumnum;i++)
	printf("%d\n",x[i]*200);
}
int n=0,cnt=0;
int visit[2000][2000];
int dp[2000][2000];
int a[2000];
int b[2000];
void qsort(int i,int j,int *a)
{
  int l=i,r=j,mid=a[(i+j)/2];
  while (l<=r)
  {
    while (a[l]>mid) l++;
    while (a[r]<mid) r--;
    if (l<=r)
    {
      int temp=a[l]; a[l]=a[r]; a[r]=temp;
      l++; r--;
    }
  }
  if (l<j) qsort(l,j,a);
  if (i<r) qsort(i,r,a);
}
int f(int i,int j)
{
  if (visit[i][j]!=cnt)
  {
    visit[i][j]=cnt;
    if (j>n) dp[i][j]=0;
    else
    {
      int a1=0;
      if (a[i]>b[j]) a1=200; else if (a[i]==b[j]) a1=0; else a1=-200;
      int k1=f(i+1,j+1)+a1;
      int a2=0;
      if (a[n-(j-i)]>b[j]) a2=200; else if (a[n-(j-i)]==b[j]) a2=0; else a2=-200;
      int k2=f(i,j+1)+a2;
      dp[i][j]=k1;
      if (k2>k1) dp[i][j]=k2;
    }
  }
  return dp[i][j];
}
int main()
{
    //freopen("zozo.in","r",stdin);
    //freopen("zozo.out","w",stdout);
    scanf("%d",&n);
    while (n!=0)
    {
      for (int i=1; i<=n; i++) scanf("%d",&a[i]);
      for (int i=1; i<=n; i++) scanf("%d",&b[i]);
      qsort(1,n,a);
      qsort(1,n,b);
      cnt++;
      int ans=f(1,1);
      printf("%d\n",ans);
      scanf("%d",&n);
    }
}