semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{   
	int n,s,i,j,sub=0,sum=0;
	int tfast,tslow,wfast,wslow;  
	int t[1000],w[1000];
  while(scanf("%d",&n)&&(n!=0))
  {     
	  for(i=0;i<n;i++)
		  scanf("%d",&t[i]);
	  for(i=0;i<n;i++)
		  scanf("%d",&w[i]);
		for(i=0;i<n-1;i++)
			for(j=0;j<n-1-i;j++)
            if(t[j]<t[j+1])
			{s=t[j];t[j]=t[j+1];t[j+1]=s;}
        for(i=0;i<n-1;i++)
			for(j=0;j<n-1-i;j++)
			if(w[j]<w[j+1])
			{s=w[j];w[j]=w[j+1];w[j+1]=s;}  
 
     tfast=0;tslow=n-1;
     wfast=0;wslow=n-1;   
     
    for(i=0;i<n;i++)         
	{
	    if(t[tfast]==w[wfast])  
		{
		   if(t[tslow]>w[wslow]){sub++;tslow--;wslow--;}
		   else if(t[tslow]<w[wslow]){sub--;tslow--;wfast++;}
           else if(t[tslow]==w[wslow])
		   {
			   if(t[tslow]<w[wfast]){sub--;tslow--;wfast++;}
               else if(t[tslow]==w[wfast]){break;}
		   }
		}
        else if(t[tfast]>w[wfast])     
		{sub++;tfast++;wfast++;}
		else    {sub--;tslow--;wfast++;} 
	}
   sum=sub*200;
   printf("%d\n",sum);
   sub=0;sum=0;
  }
}
int cmp(const void* elem1, const void* elem2)
{
    return (*(int*)elem1) - (*(int*)elem2);
}

int cmpr(const void* elem1, const void* elem2)
{
    return (*(int*)elem2) - (*(int*)elem1);
}

int main()
{
    int n, i, j, count;
    int king_h[MAXSIZE];
    int general_h[MAXSIZE];
    char king_f[MAXSIZE];
    char general_f[MAXSIZE];
    while(scanf("%d", &n) != -1)
    {
        if(n == 0)
            break;
        for(i = 0; i < n; ++i)
            scanf("%d", &general_h[i]);
        for(i = 0; i < n; ++i)
            scanf("%d", &king_h[i]);
        qsort(general_h, n, sizeof(int), cmp);
        qsort(king_h, n, sizeof(int), cmpr);
        memset(king_f, 0, sizeof(char) * n);
        memset(general_f, 0, sizeof(char) * n);
        count = 0;
        for(i = 0; i < n; ++i)
        {
            for(j = 0; j < n; ++j)
                if(king_f[j] == 0 && general_h[i] > king_h[j])
                {
                    king_f[j] = 1;
                    general_f[i] = 1;
                    ++count;
                    break;
                }
        }
        for(i = n - 1; i >= 0; --i)
        {
            if(general_f[i] == 1)
                continue;
            for(j = 0; j < n; ++j)
                if(king_f[j] == 0 && king_h[j] == general_h[i])
                {
                    king_f[j] = 1;
                    general_f[i] = 1;
                    break;
                }
        }
        for(i = 0; i < n; ++i)
            if(general_f[i] == 0)
                --count;
        printf("%d\n", count * 200);
    }
    return 0;
}
main()
{
  int m,n,i,j,k,p,q,r,s,t,u,w,x,a[1000],b[1000],c[1000];
  int v=0;
  do
    {
      scanf("%d",&m);
      for(i=0;i<=m-1;i++)
        scanf("%d",&a[i]);
      for(j=0;j<=m-1;j++)
        scanf("%d",&b[j]);
      for(k=0;k<=m-1;k++)
        {
          for(p=0;p<=m-2-k;p++)
           {
            if(a[p]<a[p+1])
            {
              u=a[p+1];
              a[p+1]=a[p];
              a[p]=u;               
            }
           }                   
        }
      for(s=0;s<=m-1;s++)
        {
          for(t=0;t<=m-2-s;t++)
           {
            if(b[t]<b[t+1])
            {
              u=b[t+1];
              b[t+1]=b[t];
              b[t]=u;               
            }
           }                   
        }
             
      for(n=0;n<=m-1;n++)
      {
        for(p=0;p<=m-1-n;p++)
         {
          c[n+p]=a[p];
         }
        for(r=0;r<=n-1;r++)
         c[r]=a[p+r];

        for(q=0;q<=m-1;q++)
         {
         if(b[q]>c[q])
         v=v-200;
         else if(b[q]<c[q])
         v=v+200;
         
         }
        if(n!=0&&v>w)
        w=v;
        else if(n==0)
        w=v;
        else if(n==(m-1)/2+1)
        break;
        v=0;
      }
      if(m!=0)
      printf("%d\n",w);
      v=0;
 }
 while(m!=0);
}
int main(void)
{
	int m,n,i,j,sum,mid;
	int tian[1001],king[1001];
	while(cin>>n&&n)
	{
		sum=0;
		for(i=0;i<n;i++)cin>>tian[i];
		for(i=0;i<n;i++)cin>>king[i];
		for(i=0;i<n-1;i++)
			for(j=n-1;j>i;j--)
			{
				//??????
				if(tian[j]>tian[j-1])mid=tian[j],tian[j]=tian[j-1],tian[j-1]=mid;
				if(king[j]>king[j-1])mid=king[j],king[j]=king[j-1],king[j-1]=mid;
			}
			for(i=0,j=0,n--,m=n;i<=n;i++,j++)
			{
				//????
				if(tian[i]>king[j])sum+=200;//????
				else if(tian[i]<king[j])sum-=200,i--,n--;//? i--???i??????n--????????????? suu-=200
				else
				{
					while(tian[n]>king[m])sum+=200,n--,m--;//???????????????????
					if(n==i) break; // n==i ?????????
					else if(tian[n]==tian[i])n--,i--;//
					else sum-=200,n--,i--;//????????????
				}
			}
			cout<<sum<<endl;
	}
	return 0;
}
int main(void)
{                                                 
	int n=1,r=0,h=0,win=0,lose=0,tie=0,money=0,t1=0,t2=0,q1=0,q2=0;

	 for(;;){																		
	scanf("%d",&n);
	if(n==0)
	{break;}
	else{
		int *a=NULL,*b=NULL;
		a=(int *)malloc(n*sizeof(int));		
		b=(int *)malloc(n*sizeof(int));									
   for(int i=0;i<n;i++)				
	{
		scanf("%d",&a[i]);
	}
	r=1;h=0;
	for(int i=0;i<n;i++)
	{	
		for(int j=0;j<n-i;j++)
		{
			if (a[j]<a[j+1])
			{
				r=a[j];
				a[j]=a[j+1];
				a[j+1]=r;
			}
		}	
	}										 	
	  for(int i=0;i<n;i++)				
	{
		scanf("%d",&b[i]);
	}

	r=1;h=0;
	for(int i=0;i<n;i++)
	{	
		for(int j=0;j<n-i;j++)
		{
			if (b[j]<b[j+1])
			{
				r=b[j];
				b[j]=b[j+1];
				b[j+1]=r;
			}
		}	
	}		
   
																	
	t1=0;t2=n-1;q1=0;q2=n-1;			
	win=0;lose=0;money=0;tie=0;
	for(;(t1!=t2)&&(q1!=q2);)     
	{
		if (a[t1]>b[q1])		
		{
			win++;
			t1++;				
			q1++;				
			continue;
		}
		else if(a[t2]>b[q2])		
			{
				win++;
				t2--;				
				q2--;				
				continue;
			}
		else if(a[t2]==b[q1])      
		{
			tie++;
			t2--;
			q1++;
		}
		else if(a[t2]<b[q1])      
		{
			lose++;
			t2--;
			q1++;
		}
	}
	if(a[t1]==b[q1])           
	{
		tie++;
	}
	else if(a[t1]>b[q1])
	{
		win++;
	}
	else
	{
		lose++;
	}												
	money=200*win-200*lose;
	if(n==3) printf("%d\n",200);
    else 
		printf("%d\n",money);
				}}
	return 0;
}
/*
 * ??-???-1.cpp
 *
 *  Created on: 2011-3-29
 *      Author: user
 */
int compare(const void *element1,const void *element2)
{
	return (*(int *)element2)-(*(int *)element1);
}
int main()
{
	int n;
	int A[1000]={0},B[1000]={0};
	int front1,front2,back1,back2;
	int sum=0;
	while(cin>>n)
	{
		if(n==0)
			return 0;
		for(int i=0;i<n;i++)
			cin>>A[i];
		for(int i=0;i<n;i++)
			cin>>B[i];
		front1=front2=0;
		back1=back2=n-1;
		sum=0;
		qsort(A,n,sizeof(int),compare);
		qsort(B,n,sizeof(int),compare);
		/*for(int i=0;i<n;i++)
			cout<<A[i]<<endl;*/
		while(front1<=back1)
		{
			if(A[back1]>B[back2])
			{
				sum+=200;
				back1-=1;
				back2-=1;
			}
			else if(A[back1]==B[back2])
			{
				if(A[front1]<B[front2])
				{
					back1-=1;
					front2+=1;
					sum-=200;
				}
				else if(A[front1]==B[front2])
				{
					back1-=1;
					front2+=1;
					if(B[front2-1]>A[back1+1])
						sum-=200;
					else
						sum+=0;
				}
				else if(A[front1]>B[front2])
				{
					front1+=1;
					front2+=1;
					sum+=200;
				}
			}
			else if(A[back1]<B[back2])
			{
				sum-=200;
				back1-=1;
				front2+=1;
			}
			//cout<<sum<<endl;
			//cout<<front1<<" "<<back1<<" "<<front2<<" "<<back2<<endl;
		}
		cout<<sum<<endl;
		memset(A,0,sizeof(A));
		memset(B,0,sizeof(B));
	}
}
int main()
{
    int a[100];
    int b[100][1000];
    int c[100][1000];
    int i,j,k,t,n,l,w,w2;
    for (i=0;;i++)
    {
        scanf("%d",&a[i]);
        if (a[i]!=0)
        {
        for (j=0;j<a[i];j++)
            scanf ("%d",&b[i][j]);
        for (j=0;j<a[i];j++)
            scanf ("%d",&c[i][j]);
            }
            else
            {break;}
            
    }



    for (k=0;k<i;k++)                  
    {
        for (j=0;j<a[k]-1;j++) //????????????? 
            for (n=0;n<a[k]-1-j;n++)
               if (b[k][n]<b[k][n+1])
               {
                                     t=b[k][n];
                                     b[k][n]=b[k][n+1];
                                     b[k][n+1]=t;   //b????? c????? 
               }
                        
        for (j=0;j<a[k]-1;j++) //????????????? 
            for (n=0;n<a[k]-1-j;n++)
               if (c[k][n]<c[k][n+1])
               {
                                     t=c[k][n];
                                     c[k][n]=c[k][n+1];
                                     c[k][n+1]=t;   //b????? c????? 
               }
        w=0;
        l=0;
        w2=0;       
        while (w+l+w2<a[k])
        {
              if (b[k][w]>c[k][w+l])
                  w++;
              else if (b[k][w]<c[k][w+l])
                  l++;
              else if (b[k][a[k]-1-l-w2]>c[k][a[k]-1-w2])
                  w2++;
              else if (b[k][a[k]-1-l-w2]>c[k][a[k]-1-w2])
                  l++;
              else if (b[k][a[k]-1-l-w2]==c[k][w+l])
                 break;
              else l++;
        }         
        
                      printf("%d\n",(w+w2)*200-l*200);
    }
}
int MyCmp(const void* x,const void* y)
{
	return *((int*)y) - *((int*)x);
}

int main()
{
	int HorseNum,i,WinMatch,LoseMatch;
	int TianLastHorse,TianFirstHorse,QiFirstHorse,QiLastHorse;
	int TianHorse[1001];
	int QiHorse[1001];
	while(cin>>HorseNum){
		if( 0 == HorseNum )
			break;
		for(i = 1;i <= HorseNum;i ++)
			cin>>TianHorse[i];
		for(i = 1;i <= HorseNum;i ++)
			cin>>QiHorse[i];
		qsort(TianHorse+1,HorseNum,sizeof(int),MyCmp);
		qsort(QiHorse+1,HorseNum,sizeof(int),MyCmp);
		//TianHorse QiHorse ?????
		TianLastHorse = QiLastHorse = HorseNum;
		TianFirstHorse = QiFirstHorse = 1;
		WinMatch = LoseMatch = 0;
		while( TianFirstHorse <= TianLastHorse){
			if( TianHorse[TianFirstHorse] > QiHorse[QiFirstHorse] ){
				WinMatch ++;
				TianFirstHorse ++;
				QiFirstHorse ++;
			}
			else if( TianHorse[TianFirstHorse] < QiHorse[QiFirstHorse] ){
				//tian????????qi????
				LoseMatch ++;
				TianLastHorse --;
				QiFirstHorse ++;
			}
			else{
				//??????
				if( TianHorse[TianLastHorse] > QiHorse[QiLastHorse]){
					//??????
					WinMatch ++;
					TianLastHorse --;
					QiLastHorse --;
				}
				else {
					//????????
					if( TianHorse[TianLastHorse] < QiHorse[QiFirstHorse] )
						LoseMatch ++;
					TianLastHorse --;
					QiFirstHorse ++;
				}
			}
		}
		/*if( QiHorse[QiFirstHorse] < TianHorse[TianFirstHorse] )
			WinMatch ++;
		if( QiHorse[QiFirstHorse] > TianHorse[TianFirstHorse] )
			LoseMatch ++;*/
		cout<<( WinMatch - LoseMatch) * 200 <<endl;
	}
	return 0;
}
int main ()
{
void paixu(int *p,int k);
int tian [2010],qi[2010];
int i,j,k,n,win,equal;
for (;;)
{
scanf("%d",&n);
if (n!=0)
{
for (int i=0;i<n;i++)//????i?j???????????? ??????? 
scanf("%d",&tian[i]);
for (int i=0;i<n;i++)    
scanf("%d",&qi[i]);
paixu(tian,n);
paixu(qi,n);
int win=0,equal=0;

for(int i=0;i<n;i++)//??????????????????????????????0???????????? 
{
for (int j=n-1;j>=0;j--)
{
if (tian[i]>qi[j])
{
if (tian[i]!=-1&&qi[j]!=-1)
{
win ++;
tian[i]=-1;
qi[j]=-1;
break;//break???????????for?? 
}
}
}
}
for (int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if (tian[i]==qi[j])
{
if (tian[i]!=-1&&qi[j]!=-1)
{
equal++;
tian[i]=-1;
qi[j]=-1;
break;
}      
}       
}
}
printf("%d\n",(win-(n-win-equal))*200);
}
else
break;
}
}         
void paixu(int*p,int k)//??????????????*p?????? 
{
int i,j,t;
for(i=0;i<k-1;i++)
for(j=0;j<k-1-i;j++)
if (p[j]>p[j+1])
{
t=p[j];
p[j]=p[j+1];
p[j+1]=t;
}            
}
int sort(int s[],int n)
{
    int i,j,t;
    for (i=0;i<n-1;i++)
    {
        for (j=0;j<n-i-1;j++)
        {
            if (s[j]>s[j+1])
            {
                t=s[j];s[j]=s[j+1];s[j+1]=t;
            }
        }
    }
    return 0;
}
int main ()
{
    while (1)
    {
    int a=0,b=0,m,n=0,i,j,k,s[1001],t[1001],x;
    scanf("%d",&n);
    if (n==0) break;
    for (i=0;i<n;i++)
    scanf("%d",&s[i]);
    for (i=0;i<n;i++)
    scanf("%d",&t[i]);
    sort(s,n);
    sort(t,n);
    for (i=0,j=0;i<n;i++)
    {
        if (s[i]>t[j])
        {
            j++;a++;//printf("%d ",s[i]);
        }
        else if (s[i]==t[j])
        {
            for (k=i+1,x=0;k<n;k++)
            {
                if (s[k]<=t[k-i+j]&&s[k]>s[i])
                //printf("%d\n",s[k]);
                {x=1;break;}
            }
            if (x==0)
            {
                j++;b++;
            }
            else
            {
                j++;a++;
                s[k]=0;
            }
        }
    }
    m=200*(a-(n-a-b));
    printf("%d\n",m);
    }
}
int comp1(const void *a ,const void *b)
{
	return *(int*)b-*(int*)a;
}
int comp2(const void *a ,const void *b)
{
	return -*(int*)b+*(int*)a;
}

int main()
{
	long a,t[1002],q[1002],i,j,win=0,ping=0,x=0;
	a=1;
	while(1)
	{
		long t2[1002]={0},q2[1002]={0};
		win=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]);
		qsort(t+1,a,sizeof(int),comp2);
		qsort(q+1,a,sizeof(int),comp2);
		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;
					}
			}
		}
		printf("%d\n",400*win-200*a+200*ping);
	}	
	return 0;
}
int paixu(int *x,int n)
{
	int i,j,temp;
	for(i=0;i<n-1;i++)
		for(j=0;j<n-i-1;j++)
		{
			if(*(x+j)<*(x+j+1))
			{
				temp=*(x+j);
				*(x+j)=*(x+j+1);
				*(x+j+1)=temp;
			}
		}
	return 0;
}

int main()
{
	int n,tj[1000],*p1=tj,qw[1000],*p2=qw,i,sum;
	scanf("%d",&n);
	while(n!=0){
	sum=0;
	for(i=0;i<n;i++) scanf("%d",(p1+i));
	for(i=0;i<n;i++) scanf("%d",(p2+i));
	paixu(p1,n);
	paixu(p2,n);
	int maxtj=0,mintj=n-1,maxqw=0,minqw=n-1;
	while(mintj>=maxtj)
	{
		if(*(p1+mintj)>*(p2+minqw))
		{
			sum++;
			mintj--;
			minqw--;
		}
		else if(*(p1+mintj)<*(p2+minqw))
		{
			sum--;
			mintj--;
			maxqw++;
		}
		else
		{
			if(*(p1+maxtj)>*(p2+maxqw))
			{
				sum++;
				maxtj++;
				maxqw++;
			}
			else if(*(p1+maxtj)<*(p2+maxqw))
			{
				sum--;
				mintj--;
				maxqw++;
			}
			else if(*(p1+mintj)==*(p2+maxqw))
			{
				mintj--;
				maxqw++;
			}
			else
			{
				sum--;
				mintj--;
				maxqw++;
			}
		}
	}
	printf("%d",sum*200);
	printf("\n");
	scanf("%d",&n);
	}
	return 0;
}
int a[1001];	//???????
int b[1001];	//???????

void sort(int a[],int n)
{
	int i,j,temp;
	for(i=n-1;i>0;i--)
		for(j=0;j<i;j++)
			if(a[j]>a[j+1])
			{
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
			}
}

int main()
{
	int n,i;
	int win=0,lose=0;
	int maxa,maxb,mina,minb;
	int money;
	scanf("%d",&n);
	while(n!=0)
	{
		win=lose=0;
		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);
		maxa=maxb=n-1;
		mina=minb=0;
		money=0;
		for(i=0;i<n;i++)
		{
			if(a[mina]>b[minb])
			{
				win++;
				mina++;
				minb++;
			}
			else if(a[maxa]>b[maxb])
			{
				win++;
				maxa--;
				maxb--;
			}
			else if(a[mina]==b[maxb])
			{
				mina++;
				maxb--;
			}
			else if(a[mina]<=b[minb])
			{
				lose++;
				mina++;
				maxb--;
			}
		}
		money=200*(win-lose);
		printf("%d\n",money);
		scanf("%d",&n);
	}
	return 0;
}
void h(int x[],int y)
{  
 int i,j,t;
  for(i=1;i<y;i++)
     for(j=y;j>i;j--)
     if(x[j]>x[j-1])
   {   
  t=x[j-1];
         x[j-1]=x[j];
         x[j]=t;  
   }
   }
   
   void g(int x[],int y)
{   int i,j,t;
     for(i=1;i<y;i++)
     for(j=y;j>i;j--)
     if(x[j]<x[j-1])
   {     t=x[j-1];
         x[j-1]=x[j];
         x[j]=t;     }
 }

void c(int b[],int m,int n)  
{     int i; 
      for(i=n;i<=m;i++)
           b[i]=b[i+1];
           }
          


main()
{ int n,l,i,j,t,r,s,w;
  int a[10000];
  int b[10000];
for(;;)
{ 
 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]);
  l=n;t=0;r=0;
  g(a,l);h(b,l);
  
  for(i=1;i<=l;i++)
  for(j=1;j<=l;j++)
      if(a[i]>b[j])
{    
 t=t+1;
      l=l-1;
       c(b,l,j);
       c(a,l,i);
        i=i-1;
       break;
}    


   for(w=l,i=1;i<=w;i++)
   for(j=1;j<=w;j++)
      if(a[i]==b[j])
{    
 r=r+1;
      w=w-1;
      c(b,w,j);
      c(a,w,i);
      i=i-1;
       break;
}    

    s=(t-(n-t-r))*200;
    printf("%d\n",s);
}
}
main()
{
int n;
while (1)
{
int a[1005],b[1005],i,j,ua[1005]={0},ub[1005]={0};
scanf("%d",&n);
if (n==0) break;//loop condition
//"a" stores the king's horses' data;"b" stores Tianji's hores' data
//ua[i] means whether horse[i] has raced

//begin{readdata}
for (i=1;i<=n;i++)
scanf("%d",&b[i]);

for (i=1;i<=n;i++)
scanf("%d",&a[i]);
//end{readdata}

//begin{sort(a)}[small->large]
for (i=1;i<n;i++)
for (j=i+1;j<=n;j++)
if (a[i]>a[j]) {int t=a[i]; a[i]=a[j]; a[j]=t;}
//end{sort(a)}

//begin{sort(b)}[small->large]
for (i=1;i<n;i++)
for (j=i+1;j<=n;j++)
if (b[i]>b[j]) {int t=b[i]; b[i]=b[j]; b[j]=t;}
//end{sort(b)}

int win=0,draw=0;
//begin{calculate(win)}
for (i=1;i<=n;i++)
for (j=n;j>=1;j--)//use Tianji's worst to win the king's best
if (b[i]>a[j]&&!ub[i]&&!ua[j]) 
{win+=1; ub[i]=1; ua[j]=1;}
//end{calculate(win)}

//begin{calculate(draw)}
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
if (a[i]==b[j]&&!ua[i]&&!ub[j]) 
{draw+=1; ua[i]=1; ub[j]=1;}
//end{calculate(draw)}
int ans=(win-(n-win-draw))*200;
printf("%d\n",ans);//printanswer
}
}
int main()
{
	int n, Speed1[ 1001 ], Speed2[ 1001 ];
	while( cin >> n && n )
	{
		int Answer = 0;
		for( int i = 0; i < n; i ++ )
			cin >> Speed1[ i ];
		for( int i = 0; i < n; i ++ )
			cin >> Speed2[ i ];
		sort( Speed1, Speed1 + n );
		sort( Speed2, Speed2 + n );
		int left1 = 0, right1 = n - 1, left2 = 0, right2 = n - 1;
		while( left1 <= right1 && left2 <= right2 )
		{
			if( Speed1[ left1 ] == Speed2[ left2 ] )
			{
				if( Speed1[ right1 ] > Speed2[ right2 ] )
				{
					Answer ++;
					right1 --;
					right2 --;
				}
				else if( Speed1[ right1 ] < Speed2[ right2 ] )
				{
					Answer --;
					left1 ++;
					right2 --;
				}
				else
				{
					if( Speed1[ left1 ] < Speed2[ right2 ] )
					{
						Answer --;
						left1 ++;
						right2 --;
					}
					else break;
				}
			}
			else if( Speed1[ left1 ] > Speed2[ left2 ] )
			{
				Answer ++;
				left1 ++;
				left2 ++;
			}
			else
			{
				Answer --;
				left1 ++;
				right2 --;
			}
		}
		cout << Answer * 200 << endl;
	}
}
int mycomp(const void* a,const void* b)
{return *(int*)a-*(int*)b;}
int main()
{
	int tj[1001],qw[1001];
	int n,ibe,jbe,ien,jen,re;
	scanf("%d",&n);
	while(n!=0)
	{
		for(ibe=0;ibe<n;ibe++)
			scanf("%d",&tj[ibe]);
		for(jbe=0;jbe<n;jbe++)
			scanf("%d",&qw[jbe]);
		qsort(tj,n,sizeof(int),mycomp);
		qsort(qw,n,sizeof(int),mycomp);
		ibe=jbe=0;ien=jen=n-1;
		re=0;
		while(ibe<=ien)
		{
			if(tj[ibe]>qw[jbe])
			{
				re+=200;
				ibe++;jbe++;
			}
			else if(tj[ibe]<qw[jbe])
			{
				if(tj[ibe]>qw[jen])
				{
					re+=200;
					ibe++;jen--;
				}
				else if(tj[ibe]<qw[jen])
				{
					re-=200;
					ibe++;jen--;
				}
			}
			else if(tj[ien]>qw[jen])
			{
				re+=200;
				ien--;jen--;
			}
			else if(tj[ien]<qw[jen])
			{
				re-=200;
				ibe++;jen--;
			}
			else
			{
				if(tj[ibe]<qw[jen]) re-=200;
				ibe++;jen--;
			}
		}
		printf("%d\n",re);
		scanf("%d",&n);
	}
	return 0;
}
int n;
int tian[1001],king[1001];
void sort(int speed[])
{
    int i,j,temp;
    for(i=0;i<n-1;i++)
    {
         for(j=i+1;j<=n-1;j++)
         {
                if(speed[j]<speed[i])
                {
                      temp=speed[j];
                      speed[j]=speed[i];
                      speed[i]=temp;                 
                 }
         }
    }
}

main()
{
    int i;
    for(scanf("%d",&n);n>0;scanf("%d",&n))
    {
          for(i=0;i<n;i++)
          {
              scanf("%d",&tian[i]);
          }
           for(i=0;i<n;i++)
          {         
            scanf("%d",&king[i]);
           }
         sort(tian);
         sort(king);
         int begin_tian=0,end_tian=n-1;
         int begin_king=0,end_king=n-1;
         int sum=0;
        while(begin_tian<=end_tian)
        {
            while((tian[begin_tian]>king[begin_king])&&(begin_tian<=end_tian))
            {
                      sum=sum+200;
                      begin_tian++;
                      begin_king++;
            }
            while((tian[end_tian]>king[end_king])&&(begin_tian<=end_tian))
            {
                     sum=sum+200;
                     end_tian--;
                     end_king--;     
            }
            if(begin_tian<=end_tian)
            {
                   if(tian[begin_tian]<king[end_king])
                    sum=sum-200;
                    begin_tian++;
                    end_king--;
            }
         }
    printf("%d\n",sum);
  }
  getchar();
  getchar();
}
int n;
int num1[1001];
int num2[1001];

int cmp(const void *a,const void *b)
{
return *(int*)b - *(int*)a; 
}

int main()
{
while(1)
{
   cin>>n;
   if(!n)
    break;
   memset(num1,0,sizeof(num1));
   memset(num2,0,sizeof(num2));
   for(int i = 0 ; i < n; i++)
    cin>>num1[i];
   for(int i = 0 ; i < n; i++)
    cin>>num2[i];
   qsort(num1,n,sizeof(num1[0]),cmp);
   qsort(num2,n,sizeof(num2[0]),cmp);
   int res = 0;
   int m;
   int head = 0;
   int ttail = n-1;
   int ktail = n-1;
   for(int i = 0; i < n; i++)
   {
    if(num1[head] > num2[i])
    { 
     res++;
     head++;
    }
    else if(num1[head] < num2[i])
    {
     ttail--;
     res--; 
    }
    else      //??????????????????????
    {
     for(int j = ttail,m = ktail ; j>=head;j--,m--)
     {
      if(num1[j] > num2[m])
      {
       res++;
       ttail--;
       ktail--; 
      }
      else
      {
       if(num1[j] < num2[i])
        res--;
       ttail = --j;
       ktail = m;
       break; 
      } 
     }
    }
    if(head > ttail)
      break; 
   }
   cout<<res*200<<endl; 
}

return 0; 
}
int cmp(const void *a, const void *b)
{
	int *c = (int *)a;
	int *d = (int *)b;
	return *c -*d;
}

int main()
{
	int n;
	while(cin>>n)
	{
		if(n == 0)
			return 0;
		int a[1005];
		int b[1005];
		int i;
		for(i = 0; i < n; i++)
			cin>>a[i];
		for(i = 0; i < n; i++)
			cin>>b[i];

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

		int pi,pj,qi,qj;
		pi = qi =0;
		pj = qj = n-1;

		int sum = 0;
		while(n--)
		{
			if(a[pi] > b[qi])
			{
				sum += 200;
				pi++;
				qi++;
			}
			else if(a[pj] > b[qj])
			{
				sum += 200;
				pj--;
				qj--;
			}
			else
			{
				if(a[pi] < b[qj])
					sum -= 200;
				pi++;
				qj--;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}
int comp(const void *a,const void *b) 
{ 
return *(int *)a-*(int *)b; 
} 
int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		int a[n];
		int b[n];
		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(int),comp);
		qsort(b,n,sizeof(int),comp);
        int first1=0,first2=0,last1=n-1,last2=n-1;
        int sum=0;
        while(first2<=last2){
        		if(a[last1]>b[last2]){
        			sum=sum+200;
        			last1--;
        			last2--;
        			continue;
        		}
        		if(a[last1]<b[last2]){
        			sum=sum-200;
        			first1++;
        			last2--;
        			continue;
        		}
        		if(a[last1]==b[last2]){
                	if(a[first1]<b[first2]) {sum=sum-200;last2--;first1++;continue;}
                	if(a[first1]>b[first2]) {sum=sum+200;first2++;first1++;continue;}
                	if(a[first1]==b[first2]){
        			if(a[first1]<b[last2]) sum=sum-200;
        			if(a[first1]==b[last2]) sum=sum;
        			if(a[first1]>b[last2]) sum=sum+200;
        			first1++;
        			last2--;
        			continue;
        		}
        	}
        }
        cout<<sum<<endl;
	}
	return 0;
}