semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
	int n,i,j,temp,r=0,thead,ttail,khead,ktail;
	int vtj[1100],vqw[1100];
	while(1)
	{
		r=0;
		scanf("%d",&n);
		if(n==0)
		break;
		for(i=0;i<n;i++)
			scanf("%d",&vtj[i]);
		for(i=0;i<n;i++)
			scanf("%d",&vqw[i]);
		for(i=0;i<n;i++)
			for(j=i;j<n;j++)
			{
				if(vqw[j]>vqw[i])
				{
					temp=vqw[i];
					vqw[i]=vqw[j];
					vqw[j]=temp;
				}
				if(vtj[j]>vtj[i])
				{
					temp=vtj[i];
					vtj[i]=vtj[j];
					vtj[j]=temp;
				}
			}
		ttail=ktail=n-1;
		thead=khead=0;
		while(ttail>=thead)
		{
			if(vtj[ttail]>vqw[ktail])
			{
				ttail--;
				ktail--;
				r+=200;
				continue;
			}
			else if(vtj[ttail]<vqw[ktail])
			{
				r-=200;
				ttail--;
				khead++;
				continue;
			}
			else
			{
				if(vtj[thead]>vqw[khead])
				{
					r+=200;
					thead++;
					khead++;
				}
				else if(vtj[thead]<vqw[khead])
				{
					r-=200;
					ttail--;
					khead++;
				}
				else
				{
					if(vtj[ttail]<vqw[khead])
					{
						r-=200;
						ttail--;
						khead++;
					}
					else
					{
						ttail--;
						khead++;
					}
				}
				continue;
			}
		}
	printf("%d\n",r);
	}
	getchar();
	getchar();
}
int main()
{
	int n[100],T[100][1001],Q[100][1001],i,j,k,r,t,mo,shi=0,s=0;
	for(i=0;i<100;i++)
	{
		scanf("%d",&n[i]);
		if(n[i]==0)
		{
			break;
		}
		for(j=0;j<n[i];j++)
		{
			scanf("%d",&T[i][j]);
		}
		for(j=0;j<n[i];j++)
		{
			scanf("%d",&Q[i][j]);
		}
	}
	for(j=0;j<i;j++)
	{
		for(k=0;k<n[j]-1;k++)
		{
			for(r=0;r<n[j]-1-k;r++)
			{
				if(T[j][r]<T[j][r+1])
				{
					t=T[j][r];
					T[j][r]=T[j][r+1];
					T[j][r+1]=t;
				}
				if(Q[j][r]<Q[j][r+1])
				{
					t=Q[j][r];
					Q[j][r]=Q[j][r+1];
					Q[j][r+1]=t;
				}
			}
		}
		mo=n[j]-1;
		while(mo>shi)
		{
			if(T[j][mo]>Q[j][mo])
			{
				s+=200;
				mo--;
			}
		    else
			{
				if(T[j][shi]>Q[j][shi])
				{
					s+=200;
					shi++;
				}
				else
				{
				    t=T[j][mo];
			        for(k=mo;k>shi;k--)
					{
				        T[j][k]=T[j][k-1];
					}
		            T[j][shi]=t;
					if(T[j][shi]<Q[j][shi])
					{
						s-=200;
					}
					else if(T[j][shi]>Q[j][shi])
					{
						s+=200;
					}
					shi++;
				}
			}
		}
		for(k=shi;k<=mo;k++)
		{
			if(T[j][k]>Q[j][k])
				s+=200;
			else if(T[j][k]<Q[j][k])
				s-=200;
		}
		printf("%d\n",s);
		s=0;
		shi=0;
	}
	return 0;
}
int array[100][2][2][1000];

int patition(int a[], int low, int high)
{
    int n,temp;
	int i, j;
	n = a[high];
	i = low-1;
	for (j=low; j< high; j++)
    {
        if(a[j]<=n) 
		{
			i++;
			temp=a[i];
			a[i]=a[j];
			a[j]=temp;
		}
    }
    temp=a[i+1];
	a[i+1]=a[high];
	a[high]=temp;
	return i+1;
}
void QuickSort(int a[],int low,int high)
{
	int i;
	if(low<high) 
	{
		i=patition(a,low,high);
		QuickSort(a,low,i-1);
		QuickSort (a,i+1,high); 
	}
}

main()
{
	int n,i,j,k,temp,m,l,o;
    int c[100];
	int finish;
	
	for (i=0;n!=0;i++)
	{
		m =0;
		l =0;
		finish = 0;
        scanf("%d",&n);
		for (j=0;j<n;j++)
		{
			scanf("%d",&temp);
			array[i][0][0][j] = temp;
			array[i][0][1][j] = 0;
			
		}
		QuickSort(array[i][0][0],0,n-1);
		for (j=0;j<n;j++)
		{
			scanf("%d",&temp);
			array[i][1][0][j] = temp;
			array[i][1][1][j] = 0;
			
		}
		QuickSort(array[i][1][0],0,n-1);		
		while(!finish)
		{
			for (j=0;j<n;j++)
			{
				if (array[i][0][1][j] ==0)
				{
					break;
				}
			}
			for (k=0;k<n;k++)
			{
				if (array[i][1][1][k] ==0)
				{
					break;
				}
			}
			for (l=n-1;l>=0;l--)
			{
				if (array[i][0][1][l] ==0)
				{
					break;
				}
			}
			for (o=n-1;o>=0;o--)
			{
				if (array[i][1][1][o] ==0)
				{
					break;
				}
			}
			if (array[i][0][0][l] > array[i][1][0][o])
			{
				m++;
				array[i][0][1][l] = 1;
				array[i][1][1][o] = 1;
			}
			else
				if (array[i][0][0][j] > array[i][1][0][k])
				{
					m++;
					array[i][0][1][j] = 1;
					array[i][1][1][k] = 1;
				}
				else
				{
					if(array[i][1][0][o] > array[i][0][0][j] )
					{
						m--;		
					}
					array[i][0][1][j] = 1;
					array[i][1][1][o] = 1;
					
				}
				finish = 1;
				for (j=0;j<n;j++)
				{
					if (array[i][1][1][j] == 0)
					{
						finish = 0;
					}
				}
		}
		c[i] = m*200;
		
	}
	for (j=0;j<i-1;j++)
	{
		printf("%d\n",c[j]);
	}
}
int main()
{
	int i,j,k,tl,ql,m,n,ans;
	int tian[1100],qi[1100];

	while (scanf("%d",&n) && n!=0)
	{
		ans=0;
		for (i=0;i<n;i++)	scanf("%d",&tian[i]);
		for (i=0;i<n;i++)	scanf("%d",&qi[i]);

		sort(tian,tian+n);
		sort(qi,qi+n);
		i=n-1; j=n-1;
		tl=0; ql=0;
		while (i>=tl && j>=ql)
		{

			if (tian[i]>qi[j])
			{
				ans++;
				i--; 
				j--;
			}
			else if (tian[i]<qi[j])
			{
				ans--;
				tl++;
				j--;
			}
			else 
			{
				if(tian[tl]<=qi[ql])
				{
					if (tian[tl]<qi[j]) ans--;
					tl++;
					j--;
				}
				else
				{
					while (tian[tl]>qi[ql] && tl<=i && ql<=j)
					{
						tl++;
						ql++;
						ans++;
					}
					if (tl>i || ql >j) break;
				}
			}
		}
		printf("%d\n",ans*200);
	}
}
main()
{
      for(;;)
      {
      int n;
      scanf("%d",&n);
      if(n==0)
      break;
      int a[n];//b???????a?????? 
      int b[n];
      int swap;
      for(int i=0;i<n;i++)
      scanf("%d",&b[i]);
      for(int i=0;i<n;i++)
      for(int j=i;j<n;j++)
      {
              if(b[i]>b[j])
              {
                           swap=b[i];
                           b[i]=b[j];
                           b[j]=swap;
              }
      }
      for(int i=0;i<n;i++)
      scanf("%d",&a[i]);
      for(int i=0;i<n;i++)
      for(int j=i;j<n;j++)
      {
              if(a[i]>a[j])
              {
                           swap=a[i];
                           a[i]=a[j];
                           a[j]=swap;
              }
      }
      int *a1;
      int *a2;
      int *b1;
      int *b2;
      a1=&a[0];
      a2=&a[n-1];
      b1=&b[0];
      b2=&b[n-1];
      int count1=0,count0=0;
      for(;;) 
      {

             if(b1==b2+1)
            
            { break;}
             if(*(a1)<*(b1))
             {
                                  
                                  a1++;
                                  b1++;
                                  count1++;
             }
             else
             if(*a1>*b1)
             {
                 
                            
                             b1++;
                             a2--; 
     
             }
             else
             if(*a1==*b1)
             {
                    if(*a2<*b2)
                    {
                               a2--;
                               b2--;
                               count1++;
                               
                               
                    }
                    else if(*a2>*b2)
                    {
                                b1++;
                                a2--;
                                
                    }
                    else if(*a2==*b2)
                    {
                         if(*a2==*b1)
                         count0++;
                         a2--;b1++;
                         }
                    
             
             } 
            
             
           
                        /* if(*a2<*b2)
                         {
                                    count1++;
                                    a2--;
                                    b2--;
                         }
                         if(*a2>*b2)
                         {
                                a2--;
                         }
                         if(*a2==*b2)
                         {
                                     count2++;
                         }*/
             
      }
      printf("%d\n",(count1*200-(n-count0-count1)*200));
      }
}
int main ()
{
	int n,t[1005],q[1005],i,j,k,p1,p2,total,max,h1,h2,t1,t2;
	scanf("%d",&n);
	while (n!=0)
	{
		for (i=1;i<=n;i++)scanf("%d",&t[i]);             
		for (i=1;i<=n;i++)scanf("%d",&q[i]);
		//for (i=1;i<=n;i++)cout<<t[i]<<' ';cout<<endl;
		//for (i=1;i<=n;i++)cout<<q[i]<<' ';cout<<endl;
		for (i=1;i<=n;i++)                       
		{
			max=i;
			for (j=i+1;j<=n;j++)
			    if (t[j]>t[max])max=j;
			if (i==max)continue;
			t[i]=t[i]+t[max];
			t[max]=t[i]-t[max];
			t[i]=t[i]-t[max];
		}
		for (i=1;i<=n;i++)
		{
			max=i;
			for (j=i+1;j<=n;j++)
				if (q[j]>q[max])max=j;
			if (i==max)continue;
			q[i]=q[i]+q[max];
			q[max]=q[i]-q[max];
			q[i]=q[i]-q[max];
		}
		//for (i=1;i<=n;i++)cout<<t[i]<<' ';cout<<endl;
		//for (i=1;i<=n;i++)cout<<q[i]<<' ';cout<<endl;
		total=0;                         
		h1=1;h2=1;t1=n;t2=n;  
		for(h2=1;h2<=n;h2++)
        {
            if(t[h1]>q[h2])
            {
                h1++;
                total+=200;
            }
            else if(t[h1]<q[h2])
            {
                t1--;
                total-=200;
            }
            else if(t[h1]==q[h2])
            {
                for(j=t1,k=t2;j>=h1;j--,k--)
                {
                    if(t[j]>q[k])
                    {
                        total+=200;
                        t1--;
                        t2--;
                    }
                    else
                     {
                          if(t[j]<q[h2]) total-=200;
                          t1=--j;
                          t2=k;
                          break;               
                     }
                }
            }
            if(h1>t1) break;
        }
        printf("%d\n",total);
        scanf("%d",&n);
	}
}
// horse_race.cpp : ??????????????
//


int tian[1001],king[1001];
int horses;
int f[1001][1001];
void init()
{
 int i;
 memset(f,0xff,sizeof(f));
    for(i=0;i<horses;i++)
  cin>>tian[i];
    for(i=0;i<horses;i++)
  cin>>king[i];
 sort(tian,tian+horses);
 sort(king,king+horses);       
}
int getf(int x,int y)
{
    if(f[x][y]!=-1)
  return f[x][y];
    if(x>=horses||y>=horses)
  return f[x][y]=0;
    if(tian[x]>king[y])
  return f[x][y]=getf(x+1,y+1)+200;
    if(tian[x]<king[y]) 
  return f[x][y]=getf(x+1,y)-200;                    
    if(tian[x]==king[y]) 
  return f[x][y]=max(getf(x+1,y+1),getf(x+1,y)-200);
    return 0;
}
int main()
{
 while(cin>>horses)
    {
		if(horses == 0)
			break;
    init();
       cout<<getf(0,0)<<endl;
    } 
    return 0;
}
const int maxn=1005;

int tj[maxn], qw[maxn];

int main()
{
    int n, i, res, max1, max2, min1, min2, cnt;
    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);

        res=0;
        max1=max2=n-1;
        min1=min2=0;
        cnt=0;
        while((cnt++)<n)
        {
            if(tj[max1]>qw[max2])
            {
                res += 200;
                max1--;
                max2--;
            }
            else if(tj[max1]<qw[max2])
            {
                res -= 200;
                min1++;
                max2--;
            }
            else
            {
                if(tj[min1]>qw[min2])
                {
                    res += 200;
                    min1++;
                    min2++;
                }
                else
                {
                    if(tj[min1]<qw[max2]) res -= 200;
                    min1++;
                    max2--;
                }
            }
        }
        printf("%d\n", res);
    }
    return 0;
}
main()
{
      int n,i,j,t,tian[1000],qi[1000],vic=0;
      scanf("%d",&n);
      while(n!=0)
      {
           int head1=0,head2=0,end1=n-1,end2=n-1;
           for(i=0;i<n;i++) scanf("%d",&tian[i]);
           for(i=0;i<n;i++) scanf("%d",&qi[i]);
           for(i=0;i<n-1;i++) for(j=i;j<n;j++) {if(tian[i]<tian[j]) {t=tian[i];tian[i]=tian[j];tian[j]=t;} if(qi[i]<qi[j]) {t=qi[i];qi[i]=qi[j];qi[j]=t;}}
           for(i=0;i<n;i++)
           {
                if(tian[head1]>qi[head2]) {vic++;head1++;head2++;}
                else if(tian[end1]>qi[end2]) {vic++;end1--;end2--;}
                else if(tian[head1]<=qi[head2]) { if(tian[end1]<qi[head2]) {vic--;end1--;head2++;} else {end1--;head2++;} }
                else if(tian[end1]<=qi[end2]) {vic--;end1--;head2++;}    
           }
           printf("%d\n",vic*200);
           scanf("%d",&n);
           vic=0;
      }
}
int Compare(const void* e1,const void* e2)
{
    return *(int*)e1 - *(int*)e2; 
}
int main()
{
	int n;
	while(cin>>n)
	{
		if(n==0)
			break;
		else
		{
	    	int qi[1100],tian[1100];
	     	int qhead=1,qtail=n,thead=1,ttail=n,i,num=0;
	    	for(i=1;i<=n;i++)
			{
		    	cin>>tian[i];
			}
	    	for(i=1;i<=n;i++)
			{
		    	cin>>qi[i];
			}
	    	qsort(tian+1,n,sizeof(int),Compare);
	    	qsort(qi+1,n,sizeof(int),Compare);
	    	while(thead<=ttail)
			{
				if(tian[thead]>qi[qhead])
				{
					num+=200;
					thead++;
					qhead++;
				}
				else if(tian[thead]<qi[qhead])
				{
				    num-=200;
				   	thead++;
				   	qtail--;
				}
				else
				{
					if(tian[ttail]>qi[qtail])
					{
						ttail--;
					    qtail--;
						num+=200;
					}
					else if(tian[ttail]==qi[qtail])
					{
						if(tian[thead]==qi[qtail])
						{
							thead++;
					        qtail--;
						}
						else if(tian[thead]<qi[qtail])
						{
							num-=200;
				     	    thead++;
				        	qtail--;
						}
					}
					else
					{
							num-=200;
				        	thead++;
				            qtail--;
						
					}
				}
			}
			cout<<num<<endl;
		}
	}
	return 0;
}
int getcmp(int a,int b){
	if(a>b)return 1;
	else if(a<b)return -1;
	else return 0;
}
int cmp(const void *a, const void *b){
	return *(int*)b - *(int*)a;
}

int main(){
    int n,i,temp,khorse[1000],thorse[1000],profit,profitold,k;
    for(;;){
		profitold=-1000000;
		k=0;
        memset(khorse,0,sizeof(khorse));
        memset(thorse,0,sizeof(thorse)); 
        scanf("%d",&n);
        if(n==0){break;}
        for(i=0;i<n;++i)
           scanf("%d",&thorse[i]);
        for(i=0;i<n;++i)
           scanf("%d",&khorse[i]);
        qsort(thorse,n,sizeof(thorse[0]),cmp);
		qsort(khorse,n,sizeof(khorse[0]),cmp);
        for(;k<=n;){
			profit=0;
			for(i=0;i<k;++i)
			    profit+=getcmp(thorse[n-1-i],khorse[i])*200;
			for(i=0;i<n-k;++i)
				profit+=getcmp(thorse[i],khorse[i+k])*200;
			if(profit<profitold)
				break;
			profitold=profit;
			k++;
        }
        printf("%d\n",profitold); 
    } 
}
void sort(int sz[], int n)
{
	int k,e,i;
	for(k=1;k<n;k++){
		for(i=0;i<n-k;i++){
			if(sz[i]<sz[i+1]){
				e=sz[i+1];
				sz[i+1]=sz[i];
				sz[i]=e;
			}
		}
	}
}
int main()
{
	while(1){
	int n,i,j;
	scanf("%d",&n);
	if(n==0) break;
	int *tian=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		scanf("%d",&tian[i]);
	}
	int *king=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		scanf("%d",&king[i]);
	}
	sort(tian,n);
	sort(king,n);
	int win=0,twin=0,even=0,teven=0,lose=10000,tlose=0;
	int temp;
	for(i=0;i<n; i++)
    {
        temp=i;
        i=0;
        for(j=temp;j<n;j++,i++)
        {
            if(tian[i]>king[j])
            {
                twin++;
            }
            else if(tian[i]<king[j])
            {
                tlose++;
            }
            else
            {
                teven++;
            }
        }
        tlose+=temp;
        if((twin-tlose)>(win-lose))
        {
            win=twin;
            lose=tlose;
            even=teven;
        }
        i=temp;
        twin=0;
        tlose=0;
        teven=0;
    }
	printf("%d\n",200*(win-lose));
	free(tian);
	free(king);
	}
	return 0;
}
int cmp(const void*a, const void*b)
{
	return *(int*)b - *(int*)a;
}

int main()
{
	int n;
	int i;
	while (cin >> n, n > 0){
	int t[1000], q[1000];
	for (i = 0;i < n;i++)
		cin >> t[i];
	for (i = 0;i < n;i++)
		cin >> q[i];
	qsort(t,n,sizeof(int),cmp);
	qsort(q,n,sizeof(int),cmp);
	int t1 = 0, t2 = n-1;
	int q1 = 0, q2 = n-1;
	int cnt = 0;
	for (i = 0;i < n;i++)
	{
		if (t[t1] > q[q1])
		{
			t1++;
			q1++;
			cnt += 200;
		}
		else
		{
			if (t[t2] > q[q2])
			{
				t2--;
				q2--;
				cnt += 200;
			}
			else
			{
				if (t[t2] < q[q1])
					cnt -= 200;
				t2--;
				q1++;
			}
		}
	}
	cout << cnt << endl;
	}
	return 0;
}
const int MAXN = 1010;

int n, a[MAXN], b[MAXN], f[MAXN][MAXN];

void init()
{
	int i;
	
	for (i=1; i<=n; i++)
		scanf("%d", &a[i]);
	for (i=1; i<=n; i++)
		scanf("%d", &b[i]);
	sort(a+1, a+n+1);
	sort(b+1, b+n+1);	
}

int game(int x, int y)
{
	if (x>y) return 200; else
	if (x<y) return -200; else return 0;	
}

void work()
{
	int i, j, k;
	
	for (i=1; i<=n; i++)
		f[i][i]=game(a[i], b[1]);
	for (k=1; k<n; k++)
		for (i=1; i<=n-k; i++){
			j=i+k;
			f[i][j]=max(f[i][j-1]+game(a[j], b[j-i+1]), f[i+1][j]+game(a[i], b[j-i+1]));	
		}
	printf("%d\n", f[1][n]);
}

int main()
{
	while (scanf("%d", &n), n!=0){
		init();
		work();
	}
	
	return 0;
}
void main ()
{
	int jud(int x[1000],int y[1000],int m);
	int n,a[1000],b[1000],c[1000],i=0,j,re;
	scanf ("%d",&n);
	while (n!=0)
	{
		for (j=0;j<n;j++)
		scanf ("%d",&a[j]);
		for (j=0;j<n;j++)
		scanf ("%d",&b[j]);
		c[i]= jud (b,a,n);
		i++;
		scanf ("%d",&n);
	}
	for (j=0;j<i;j++)
	{
		 printf ("%d\n",c[j]);
	}
	
}

int jud (int x[1000],int y[1000],int m)
{
	int s,i,j;
	void  arrange (int p[1000],int k);
	int result (int a[1000],int b[1000],int n,int i);
	arrange (x,m);
	arrange (y,m);
	s=result (x,y,m,0);
	for (i=1;i<m;i++)
	{
		j=result (x,y,m,i);
		if (s<j) s=j;
	}
	return (s);
}

void arrange (int p[1000],int k)
{
	int i,j,mid;
	for (i=0;i<k;i++)
	   for (j=i+1;j<k;j++)
	   {
	   	   if (p[i]<p[j]) 
	   	   {
	   	   	mid=p[i];
	   	   	p[i]=p[j];
	   	   	p[j]=mid;
			  }
	   }
}

int result (int a[1000],int b[1000],int n,int i)
{   
    int p,q,s=0;
    for (p=0;p<n;p++)
      {
      	    q=p+i;
			if (q>=n) q=q-n;
			if (a[p]>b[q]) s=s-200;
			 else if (a[p]<b[q]) s=s+200;   
	  	  }
 	  return (s);
}
int main()
{  	int n,i,j,k,e,total,sum,afast,bfast,aslow,bslow;
         int a[1000],b[1000];
	while(1)
	{
	  scanf("%d",&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]);
	  for(k=1;k<n;k++){
             for(i=0;i<n-k;i++){
               if(a[i]<=a[i+1]){
                 e=a[i+1];
                 a[i+1]=a[i];
                 a[i]=e;}
	           if(b[i]<=b[i+1]){
                 e=b[i+1];
                 b[i+1]=b[i];
                 b[i]=e;}
	  }}
	    sum=0;
	    total=0;
	    afast=0;
	    bfast=0;
	    aslow=n-1;
	    bslow=n-1;
	    for(;;)
		   {
		      if(a[aslow]>b[bslow]){
		        sum+=200;
	                 total++;
		        aslow--;
		        bslow--;
		      }else if(a[aslow]<b[bslow]){
		     	sum-=200;
		    	total++;
			aslow--;
			bfast++;
		     }else if(a[aslow]==b[bslow]){
		         if(a[afast]>b[bfast]){
			   sum+=200;
	                     total++;
		            afast++;
		            bfast++;
			}else if(a[afast]<b[bfast]){
			   sum-=200;
		            total++;
			   aslow--; 
			   bfast++;
		        }else if(a[aslow]==b[bfast]){
			   sum+=0;
			   total++;
			   aslow--; 
			   bfast++;
	                 }else if(a[aslow]<b[bfast]){
			   sum-=200;
			   total++;
			   aslow--; 
			   bfast++;
		       }
	            }
	    if(total==n)
	     break;  
	}
    	printf("%d\n",sum);
	}
 return 0;
}
int tianji[1000];
int qiwang[1000];

int main(){
	int n;
	while(cin>>n && n != 0){
		int i,j;
		for(i = 0;i < n;i++)

			cin>>tianji[i];
		for(i = 0;i < n;i++)
			cin>>qiwang[i];
		sort(tianji,tianji + n);
		sort(qiwang,qiwang + n);
		int money = 0;
		i = 0,j = n - 1;
		int k = i,l = j;
		while(true){
			while(tianji[i] > qiwang[k] && i <= j){
				money += 200;
				i++;
				k++;
			}
			while(tianji[j] > qiwang[l] && j >= i){
				money += 200;
				j--;
				l--;
			}
			if(i > j)
				break;
			else{
				if(tianji[i] != qiwang[l])
					money -= 200;
				i++;
				l--;
			}
		}
		cout<<money<<endl;
	}
	return 0;
}
main()
{
      int n;
      scanf("%d",&n);
      while(n!=0)
      {
                     int a[1002],b[1002],u=0,k=0;
      for(int i=1;i<=n;i++)
      {
              scanf("%d",&a[i-1]);
      }
      for(int i=1;i<=n;i++)
      {
              scanf("%d",&b[i-1]);
      }
      b[n]=1000001;
      a[n]=-1;
      for(int i=n-2;i>=0;i--)
      {
              for(int j=0;j<=i;j++)
              {
                      if(a[j+1]<=a[j])
                      {
                                      int x=0;
                                      x=a[j+1];
                                      a[j+1]=a[j];
                                      a[j]=x;
                      }
              }
      }
      for(int i=n-2;i>=0;i--)
      {
              for(int j=0;j<=i;j++)
              {
                      if(b[j+1]<=b[j])
                      {
                                      int x=0;
                                      x=b[j+1];
                                      b[j+1]=b[j];
                                      b[j]=x;
                      }
              }
      }
      int i,j;
      for(i=0;i<=n-1;i++)
      {
              int l,c=-1;
              for(l=0;l<=n-1;l++)
              {
                           while(b[l]==1000000)
                           {
                                             l++;
                           }
                           if(a[i]<=b[l])
                           break;
                           else
                           c=l;
              }
              if(c!=-1)
              {
                      k++;
                      b[c]=1000000;
                      a[i]=-1;
              }
      }
      for(i=0;i<=n-1;i++)
      {
                         for(j=0;j<=n-1;j++)
                         {
                                            if(a[i]==b[j])
                                            {
                                                          u++;
                                                          a[i]=-1;
                                                          b[j]=1000000;
                                            }
                         }
      }
      n=-200*n+400*k+200*u;
      printf("%d\n",n);
      scanf("%d",&n);
      }
}
void sort(int a[],int n)
{ int i,j,t;
  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;}
  return;
}
int main()
{
   int a[1000],b[1000];int i,h,k,ans,t,s,n,j,m;
   for(k=1;k<=1000;k++)
{ scanf("%d",&n);
    if(n==0)break;
    else
   {
     t=n-1;s=n-1;
     for(i=0;i<n;i++)
      scanf("%d",&a[i]);
    sort(a,n);
   for(i=0;i<n;i++)
    scanf("%d",&b[i]);
    sort(b,n);
    h=0;ans=0;
   for(i=0;i<n;i++)
    { 
    if(a[h]>b[i])
     {
        ans+=200;
        h++;
     }
     else if(a[h]<b[i])
     {
          t--;
          ans-=200;
     }
     else if(a[h]==b[i])
     {    
          for(j=t,m=s;j>=h;j--,m--)
            { 
                  if(a[j]>b[m])
                      {
                         ans+=200;
                          t--;
                          s--;
                      } 
                  else
                  { if(a[j]<b[i]) 
                          ans-=200;
                           t=--j;
                           s=m;
                           break;
                  }
           }   
     }  
    if(h>t)
      break; 
   } 
  }
   printf("%d\n",ans);
}
   getchar();getchar();                     
}
int T[1010], Q[1010];
int main()
{
	int n;
	while(cin >> n && n)
	{
		int ret = 0;
		for (int i = 0; i< n; i++)
			cin >> T[i];
		for (int i = 0; i< n; i++)
			cin >> Q[i];
		sort(T, T + n);
		sort(Q, Q + n);
		int T_begin = 0, Q_begin = 0;
		int T_end = n - 1, Q_end = n - 1;
		while (T_begin <= T_end && Q_begin <= Q_end)
		{
			if (T[T_end] > Q[Q_end])
			{
				T_end--;
				Q_end--;
				ret++;
			}
			else if (T[T_begin] > Q[Q_begin])
			{
				T_begin++;
				Q_begin++;
				ret++;
			}
			else
			{
				if (T[T_begin] < Q[Q_end])
					ret--;
				T_begin++;
				Q_end--;
			}

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