semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int Compare(const void* elem1,const void* elem2)
{
    int *p1,*p2;
    p1=(int*) elem1;
    p2=(int*) elem2;
    return (*p2)-(*p1);
}
main()
{
    int n,i=0,j=0,k=0,m=0,r=0;
    int a[1100];
    int b[1100];
    int c[1100]={0};
    int d[1100];
    scanf("%d",&n);
   while (n!=0)
   {
       for(i=0;i<=n-1;i++)
       {
           scanf("%d",&a[i]);
       }
       for(j=0;j<=n-1;j++)
       {
           scanf("%d",&b[j]);
       }
       qsort(a,n,sizeof(int),Compare);
       qsort(b,n,sizeof(int),Compare);
       for(i=0;i<=n-1;i++)
       {
           for(k=0;k<=n-1;k++)
           {
               if(a[k]>b[k])
               {
                  m=m+1;
               }
               if(a[k]==b[k])
               {
                  m=m+0;
               }
               if(a[k]<b[k])
               {
                  m=m-1;
               }
           }
           c[i]=m;
           m=0;
           for(j=n-1;j>=0;j--)
           {
               a[j+1]=a[j];
           }
           a[0]=a[n];
       }
       qsort(c,n,sizeof(int),Compare);
       d[r]=c[0]*200;
       r++;
       scanf("%d",&n);
   }
   for(i=0;i<=r-1;i++)
   {
       printf("%d\n",d[i]);
   }
}
void line(int n,int *p);
int main()
{
    int n,n1,i,j,k,t,l,sum,s,win,w,lose,money,flag,flag2;
    int a[1000],b[1000];
    for(l=0;;l++)
    {
                    scanf("%d",&n1);
                    if(n1==0)break;
                    lose=0;win=0;
                    i=j=0;k=l=n1-1;
                    memset(a,0,1000*sizeof(int));
                    memset(b,0,1000*sizeof(int));
                   line(n1,a);
                   line(n1,b);
                   while(j<=k&&i<=l)
                   {
                     if(b[j]<a[i])
                     {
                                  win++;i++;j++;
                     }
                     else if(b[j]>a[i])
                     {
                          lose++;i++;k--;
                     }
                     else
                     {
                         if(b[k]<a[l])
                         {
                                      win++;k--;l--;
                         }
                         else if(b[k]>a[i])
                         {
                              lose++;k--;i++;
                         }
                         else 
                         {
                              k--;i++;
                         }
                     }
                   }        
                  money=200*win-200*lose;
                  printf("%d\n",money);
    }
    return 0;
}

void line(int n,int p[])
{
     int i,j,k;
     for(i=0;i<n;i++)scanf("%d",&p[i]);
     for(i=0;i<n-1;i++)
     {
                     for(j=0;j<n-1-i;j++)
                     {
                                       if(p[j]>p[j+1])
                                       {
                                                      k=p[j];
                                                      p[j]=p[j+1];
                                                      p[j+1]=k;
                                       }
                     }
     }
}
int main()
{
      int t[1010],w[1010];
      int n,i,j,k,m,ans,w1,w2,head,tailt,tailw;
      
      
      while (1)
      {
            scanf("%d",&n);
            ans=0;
            if (n==0)
                break;
            for (i=1;i<=n;i++)
                scanf("%d",&t[i]);
            for (i=1;i<=n;i++)
                scanf("%d",&w[i]);
            for (i=1;i<n;i++)
                for (j=i+1;j<=n;j++)
                {
                    if (t[i]<t[j])
                    {
                        k=t[i]; t[i]=t[j]; t[j]=k;
                    }
                    if (w[i]<w[j])
                    {
                        k=w[i]; w[i]=w[j]; w[j]=k;
                    }
                }
            head=1;
tailt=n;
tailw=n;
for (i=1;i<=n;i++)
{
if (t[head]>w[i])
{
head++;
ans+=200;
}
else if (t[head]<w[i])
{
tailt--;
ans-=200;
}
else if (t[head]==w[i])
{
for (j=tailt,m=tailw;j>=head;)
{
if (t[j]>w[m])
{
ans+=200;
tailt--;
tailw--;
j--;
m--;
}
else
{
if (t[j]<w[i])
ans-=200; 
tailt--;
j--;
break;
}
}
}
if (head>tailt)
break;
}

printf("%d\n",ans);
}
getchar();
getchar();
getchar();
getchar();
getchar();
getchar();
}
const int MAX_N = 1000;
int n, w[MAX_N], t[MAX_N];

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

int main()
{
	while (scanf("%d", &n), n)
	{
		for (int i = 0; i < n; ++i)
			scanf("%d", t + i);
		for (int i = 0; i < n; ++i)
			scanf("%d", w + i);
		qsort(t, n, sizeof(int), cmpInt);
		qsort(w, n, sizeof(int), cmpInt);

		int win = INT_MIN;
		for (int i = 0; i < n; ++i)
		{
			int twin = 0;
			for (int j = 0; j < n; ++j)
				if (t[j] > w[(i + j) % n])
					twin += 200;
				else if (t[j] < w[(i + j) % n])
					twin -= 200;
			if (twin > win)
				win = twin;
		}
		printf("%d\n", win);
	}
	return 0;
}
void main()
{int n,*tian,*lord;
	int i,j,m=0,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));
	//sum=(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);

	//maopao1;maopao2;
	for(j=0;j<n-1;j++)
		for(i=0;i<n-1-j;i++)
			if(*(tian+i)<*(tian+i+1))
			{m++;
				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))
			{m++;
				t=*(lord+i);
				*(lord+i)=*(lord+i+1);
				*(lord+i+1)=t;
			}

/*	for(i=0;i<n;i++)//i???
	{
			*(sum+i)=0;
			for(j=0;j<n;j++)
			{m++;
			if(*(tian+j)>*(lord+(i+j)%n)) (*(sum+i))++;
			else if(*(tian+j)<*(lord+(i+j)%n)) (*(sum+i))--;
			}printf("*(sum+%d)=%d\n",i,*(sum+i));	
			if(i!=0&&*(sum+i)<*(sum+i-1)) {m=i-1;break;}
			else if(i==n-1) m=n-1;
	}*/
			//ta,tb,la,lb:tian's tail,lord's head/tail
			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--;
	//maxsum
	//x[sumnum]=*sum;
	x[sumnum]=sum;
	//for(i=0;i<n;i++)
	//	x[sumnum]=(x[sumnum]>*(sum+i))?x[sumnum]:*(sum+i);
	sumnum++;
	scanf("%d",&n);
	}
	for(i=0;i<sumnum;i++)
	printf("%d\n",x[i]*200);
	//printf("%d",m);
}
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
					{
						if(tian[thead]<qi[qtail])
						{
							num-=200;
				        	thead++;
				            qtail--;
						}
					}
				}
			}
			cout<<num<<endl;
		}
	}
	return 0;
}
main()
{
      int n[100]={0},t[100][1005]={0},q[100][1005]={0};
      int i,j,k,z=0;
      for (i=0;;i++)
      {
          scanf ("%d",&n[i]);
          if (n[i]==0) { z=i;break;}
          for (j=0;j<=n[i]-1;j++)
          { scanf ("%d",&t[i][j]); }
          for (j=0;j<=n[i]-1;j++)
          { scanf ("%d",&q[i][j]); }
      }
      for (i=0;i<=z-1;i++)
      {
          int change=0;
          for (j=0;j<=n[i]-1;j++)
          {   for (k=j+1;k<=n[i];k++)
              {  if (t[i][j]<t[i][k])
                 {
                   change=t[i][k];
                   t[i][k]=t[i][j];
                   t[i][j]=change;
                 }
                 if (q[i][j]<q[i][k])
                 {
                   change=q[i][k];
                   q[i][k]=q[i][j];
                   q[i][j]=change;
                 }
              }
          }
          int ft=0,fq=0,st=n[i]-1,sq=n[i]-1,money=0;
          for (j=ft;j<=st;j++)
          {
              for (k=fq;k<=sq;k++)
              {
                 if (t[i][j]>q[i][k])
                 { money = money +200; fq=fq+1; break; }
                 else if (t[i][st]>q[i][sq])
                 { money = money +200; st=st-1; sq=sq-1;j=j-1; break; }
                 else if (t[i][st]==q[i][fq])
                 {  break; }
                 else { money =money-200; fq=fq+1;st=st-1; j=j-1; break; }
              }
          }
          printf ("%d\n",money);
      }
}
main()
{
    int a[1000],b[1000],m,n,i,j,k1,k2,sum;
    for(;;)
    {
        sum=0;
        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(i=0;i<n-1;i++)
        {
            for(j=0;j<n-1-i;j++)
            {
                if(a[j]<a[j+1])
                {
                    m=a[j+1];
                    a[j+1]=a[j];
                    a[j]=m;
                }
            }
        }
        for(i=0;i<n-1;i++)
        {
            for(j=0;j<n-1-i;j++)
            {
                if(b[j]<b[j+1])
                {
                    m=b[j+1];
                    b[j+1]=b[j];
                    b[j]=m;
                }
            }
        }
        i=0;
        j=0;
        k1=n-1;
        k2=n-1;
        for(;i<=k1&&j<=k2;j++)
        {
            if(a[i]>b[j])
            {
                i++;
                sum++;
            }
            else if(a[i]<b[j])
            {
                k1--;
                sum--;
            }
            else
            {
                if(a[k1]<b[k2])
                {
                    k1--;
                    sum--;
                }
                else if(a[k1]>b[k2])
                {
                    j--;
                    k1--;
                    k2--;
                    sum++;
                }
                else
                {
                    if (a[k1]==b[j])
                    {
                        k1--;
                    }
                    else
                    {
                        k1--;
                        sum--;
                    }
                }
            }
        }
        sum=sum*200;
        printf("%d\n",sum);
    }
}
int Compare(const void *a, const void *b);
int WinCount(int *Q, int *T, int n);
int max(int a, int b);

// infoSource = Keyboard(0) or File(1)


// reference from http://zhidao.baidu.com/question/38869821.html
/*
??????????????????a?????????????b??
???????????????????????????????????? 
???????????????? 
????????????????????? 
?????????????????????????????????????? 
??????l(i?j)??????i?????j?????????j????????????????
*/

int main()
{
	int n;
	int TianJi[1000];
	int QiWang[1000];
	int i, j;
	int *pwin[1000];
//	int win[100][100];

/*
win[i][j]??????i??????i?j???j+1?????????j+1????????????????
*(pwin[i]+j) = win[i][j];
?????l[i][0]??????i??????????????? 
*/

	FILE *fp;
	fp = fopen("horse.txt", "r");

	for(i=0; i<1000; i++){
		if((pwin[i]=(int *)malloc(sizeof(int)*1000))==NULL){
			printf("Error: memory out!");
		return 1;
		}
	}

	while(1){
		fscanf(fp, "%d", &n);
		scanf("%d", &n);
		if(n==0)
			break;


		for(i=0; i<n; i++){
			fscanf(fp, "%d", &TianJi[i]);
			scanf("%d", &TianJi[i]);
		}
		for(i=0; i<n; i++){
			fscanf(fp, "%d", &QiWang[i]);
			scanf("%d", &QiWang[i]);
		}


		qsort((void*)&TianJi[0], n, sizeof(int), Compare);
		qsort((void*)&QiWang[0], n, sizeof(int), Compare);


		for(i=0; i<n; i++){
			if(TianJi[0]>QiWang[i])
				*(pwin[i]+0) = 1;
			else if(TianJi[0]<QiWang[i])
				*(pwin[i]+0) = -1;
			else
				*(pwin[i]+0) = 0;
		}

//		for(i=n-2;i>=0;i--){
//			for(j=1;j<n-i;j++){

		for(j=1; j<n; j++){
			for(i=n-1-j; i>=0; i--){

				//	Calculate win[i][j]
				if (TianJi[j]>QiWang[i+j])
					*(pwin[i]+j) = *(pwin[i]+j-1) + 1;
				else if(TianJi[j]<QiWang[i+j])
					*(pwin[i]+j) = *(pwin[i+1]+j-1) - 1;
				else
					*(pwin[i]+j) = max(*(pwin[i]+j-1), *(pwin[i+1]+j-1)-1);
			}
		}

//	download and modified from http://zhidao.baidu.com/question/38869821.html
/*
		for(i=n-2;i>=0;i--)
			for(j=1;j<n-i;j++)
				if(QiWang[i+j]<TianJi[j])
					*(pwin[i]+j)=*(pwin[i]+j-1)+1;
				else if(QiWang[i+j]>TianJi[j])
					*(pwin[i]+j)=*(pwin[i+1]+j-1)-1;
				else
					*(pwin[i]+j)=max(*(pwin[i+1]+j-1)-1,*(pwin[i]+j-1));
*/

		printf("%d\n", *(pwin[0]+n-1)*200);


	}
	fclose(fp);


	return 0;
}

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

int max(int a, int b)
{
	return (a>b)? a: b;
}
int n;
int cmp(const void *x,const void *y)
{
	return *(int *)y - *(int *)x;//
}
int pk(int a[],int b[])
{
	int i=0,j=0,k=n-1,l=n-1;
	int sum=0;
	int w=0,lose=0;
	while(i<=k)
	{

		if(a[k]>b[l])
		{
			sum+=200;
			w++;
			k--;
			l--;
		}
		else if(a[k]<b[l])
		{
			sum-=200;
			lose++;
			k--;
			j++;
		}	
		else
		{
			if(a[i]>b[j])
			{
				sum+=200;
				w++;
				i++;
				j++;
			}	
			else 
			{
				if(a[k]<b[j])
				{
					sum-=200;
					lose++;
				}
				k--;
				j++;
			}
				
		}
	}
	return sum;
}
int main()
{	
	int a[1001],b[1001];
	while(cin>>n&&n!=0)
	{
		memset(a,0,sizeof a);
		memset(b,0,sizeof b);
		int i;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
		}
		for(i=0;i<n;i++)
		{
			cin>>b[i];
		}
		qsort(a,n,sizeof a[0],cmp);
		qsort(b,n,sizeof b[0],cmp);
		cout<<pk(a,b)<<endl;
	}
	return 0;
}
int main()
{
	int n,a[1000],b[1000],i,j,t,m;
	for(;;)
	{
		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]);
		
		t=0;
		for(i=0;i<n-1;i++)
		for(j=0;j<n-1-i;j++)if(a[j]<a[j+1]){t=a[j];a[j]=a[j+1];a[j+1]=t;}
		t=0;
		for(i=0;i<n-1;i++)
		for(j=0;j<n-1-i;j++)if(b[j]<b[j+1]){t=b[j];b[j]=b[j+1];b[j+1]=t;}
		
		m=0;
		for(;n>0;n--)
		{
			//1 
		    if(a[0]>b[0])
		    {
			    m++;
			    for(i=0;i<n-1;i++)
			    {
				    a[i]=a[i+1];
				    b[i]=b[i+1];
			        } 
		        }
		    //2
		    else if(a[0]<b[0])
		    {			
    			m--;
    			for(i=0;i<n-1;i++)b[i]=b[i+1];
        	    }
    		//3
    		else if(a[0]==b[0]&&a[n-1]>b[n-1])
    		{
    			m++;
    		    }
    		//4
    		else if(a[0]==b[0]&&a[n-1]<=b[n-1])
    		{
    			if(a[n-1]<b[0])m--;
    			for(i=0;i<n-1;i++)b[i]=b[i+1];
    			}   
		
			}  			
        printf("%d\n",200*m);
        }

	return 0;	
    }
int paixu(const void*a, const void*b)
{
    return(*(int*)b-*(int*)a);
}
int main()
{ 
    int n,i,j,money=0;  
    int s;
    for  (s=0;s<50;s++)
    {
     scanf ("%d",&n);
     if (n>0)
     {
      int a[n],b[n];
     for (i=0;i<n;i++)
     {
        scanf("%d",&a[i]);
     }
    for (i=0;i<n;i++)
     {
        scanf("%d",&b[i]);
     }
    qsort(a,n, sizeof(a[0]),paixu);
    qsort(b,n, sizeof(b[0]),paixu);
    i=0;
    j=0;
    int x,y,t=0;
    x=n-1;
    y=n-1;
    while (t<n)
    {
     if (a[i]>b[j])
     {
       i++;
       j++;
       money+=200;
       t++;
     } 
   
    else if (a[x]>b[y])
    {
       x--;
       y--;
       money+=200;
       t++;
    }
  
    else if (a[x]==b[j])
    {
         x--;
         j++;
         t++;
    }
    else
    {
        money=money-200;
        x--;
        j++;
        t++;
    }
   }
    
    printf("%d\n",money);
    money=0;
   }
  }

  return 0;
}
int cmp(const void *a, const void *b)
{
	return *(int*)b - *(int*)a;
}
int main()
{
	int n,flag,i,j,bonus,mmax,draw;
	int b[1001],a[1001];


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

		for (i=0;i<n;i++)
			cin>>b[i];
		for(i=0;i<n;i++)
			cin>>a[i];

		mmax=-n;

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

		for (i=0;i<n;i++)
		{
			flag = 0;draw = 0;

			for(j=0;j<=i;j++)
			{
				if (b[j] < a[n-i-1+j]) flag = 1;
				else if (b[j] == a[n-i-1+j]) draw++;
			}
			if (flag==1) continue;

			bonus = i+1-draw - (n-i-1);

			if (bonus>mmax) mmax = bonus;
		}

		cout<<mmax*200<<endl;
	}
	return 0;
}
int n;
int tj[1001],qw[1001];

int main()
{
	void sort(int speed[]);
    int i;
    for(scanf("%d",&n);n>0;scanf("%d",&n))
    {
          for(i=0;i<n;i++)
          {
              scanf("%d",&tj[i]);
          }
           for(i=0;i<n;i++)
          {         
            scanf("%d",&qw[i]);
           }
         sort(tj);
         sort(qw);
         int start_tj=0,end_tj=n-1;
         int start_qw=0,end_qw=n-1;
         int money=0;
        while(start_tj<=end_tj)
        {
            while((tj[start_tj]>qw[start_qw])&&(start_tj<=end_tj))
            {
                      money=money+200;
                      start_tj++;
                      start_qw++;
            }
            while((tj[end_tj]>qw[end_qw])&&(start_tj<=end_tj))
            {
                     money=money+200;
                     end_tj--;
                     end_qw--;     
            }
            if(start_tj<=end_tj)
            {
                   if(tj[start_tj]<qw[end_qw])
                    money=money-200;
                    start_tj++;
                    end_qw--;
            }
         }
    printf("%d\n",money);
  }
	return 0;
}
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;                 
                 }
         }
    }
}
// #define SKIP_HORSERACING


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

int main() {
	int n, yourspeed[1000], myspeed[1000], match[1000];
	while(1) {
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < n; i++) {
			scanf("%d", &myspeed[i]);
		}
		for(int i = 0; i < n; i++) {
			scanf("%d", &yourspeed[i]);
		}

		qsort(myspeed, n, sizeof(int), cmp);
		qsort(yourspeed, n, sizeof(int), cmp);

		int cnt = 0, myfirst = 0, mylast = n-1, yourfirst = 0, yourlast = n-1;
		while(myfirst <= mylast) {
			if(myspeed[myfirst] <= yourspeed[yourfirst] && myspeed[mylast] <= yourspeed[yourlast]) {
				match[mylast--] = yourfirst++;
			}
			else if(myspeed[myfirst] > yourspeed[yourfirst]){
				match[myfirst++] = yourfirst++;
			}
			else {
				match[mylast--] = yourlast--;
			}
		}
		for(int i = 0; i < n; i++) {
			if(myspeed[i] > yourspeed[match[i]]) cnt++;
			else if(myspeed[i] < yourspeed[match[i]]) cnt--;
		}


		int gain = 200 * cnt;
		printf("%d\n", gain);
	}
	return 0;
}
main()
{
  int k;
  for(k=0;;k++)
  {
  int n;
  scanf("%d",&n);
  if(n==0)
  return 0;
  int a[1000];//??????
  int b[1000];//??????
  int i,j;
  int d=0;
  int max=(-n)*200;
  for(i=0;i<n;i++)
  scanf("%d",&a[i]);
  for(i=0;i<n;i++)
  scanf("%d",&b[i]);
  int t;//
  for(i=0;i<n;i++)//????
  {
   for(j=n-1;j>i;j--)
   {
    if (a[j]>a[j-1])
 {
  t=a[j];
  a[j]=a[j-1];
  a[j-1]=t;
 }
    if (b[j]>b[j-1])
 {
  t=b[j];
  b[j]=b[j-1];
  b[j-1]=t;
 }
   }
  }
  for(i=0;i<n;i++)
  {
   for(j=0;j<n;j++)
   {
    if(a[(j+i)%n]>b[j])
    d++;
    if(a[(j+i)%n]<b[j])
    d--;
   }
   if(d>max)
   max=d;
   d=0;
  }
  printf("%d\n",max*200);
  }
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();
  getchar();





}
int qi[1002];
int tian[1002];
int n;
int myCompare(const void*a,const void *b)
{
   int *p,*q;
   p = (int*)a;
   q = (int*)b;
   return *q - *p;
}
int main()
{
    while(1)
    {
      cin >> n;
      if(n==0)
         break;
      for(int i=0;i<n;i++)
         scanf("%d",&tian[i]);
      for(int i=0;i<n;i++)
         scanf("%d",&qi[i]);
      qsort(tian,n,sizeof(int),myCompare);
      qsort(qi,n,sizeof(int),myCompare);      
      int qif=0,qis=n-1;
      int tianf=0,tians=n-1;
      int wins=0,ping=0;
      while(tianf<=tians)
      {
         if(tian[tianf]<qi[qif])
         {
            qif++;
            tians--;
            continue;
         }
         else if(tian[tianf]>qi[qif])
         {
            tianf++;
            qif++;
            wins++;
         }
         else
         {
            if(tian[tians]>qi[qis])
            {
               tians--;
               qis--;
               wins++;
            }
            else
            {
               if(tian[tians]==qi[qif])
                  ping++;
               tians--;
               qif++;
            }
         }
      }
      cout << 200*wins - (n-wins-ping)*200 << endl;
    }
    return 0;
}
int win,loose;
main()
{
	void input(int * p1,int x);
	void f(int*p1,int*p2,int x);
	int n,t[num],w[num];
	scanf("%d",&n);
	while(n!=0)
	{
		input(t,n);
		input(w,n);
		win=loose=0;
		f(t,w,n);
		printf("%d\n",win*reward-loose*reward);
		scanf("%d",&n);
	}
}
void f(int*p1,int*p2,int x)
{
	int a1,a2,b1,b2;
	a1=*p1;b1=*p2;
	if (x==1) 
	{
		if (a1>b1)
			win++;
		else
		{
			if (a1<b1)
				loose++;
		}
	}
	else
	{
		a2=*(p1+x-1);b2=*(p2+x-1);
		if (a2<b2)
		{
			loose++;
			f(p1,p2+1,x-1);
		}
		else
		{
			if (a2>b2)
			{
				win++;
				f(p1,p2,x-1);
			}
			else
			{
				if (a1>b1)
				{
					win++;
					f(p1+1,p2+1,x-1);
				}
				else
				{
					if (a1<b1)
					{
						loose++;
						f(p1,p2+1,x-1);
					}
					else
					{
						if (b1>a2)
							loose++;
						f(p1,p2+1,x-1);
					}
				}
			}
		}
	}

}

void input(int * p1,int x)
{
	int i,j,c;
	for (i=0;i<x;i++)
	{
		scanf("%d",p1+i);
	}
	for (i=0;i<x-1;i++)
	{
		for (j=i;j<x;j++)
		{
			if (*(p1+i)<*(p1+j))
			{c=*(p1+i);*(p1+i)=*(p1+j);*(p1+j)=c;
			}
		}
	}
}
void main()
{
	void paixu(int *a,int *b,int c);
	void max(int *a,int *b,int n);
    int a[1001][1001],b[1001][1001],c[1001];
    int i=0,e;
    int *j;
    int *s;
    s=c;
    leap:scanf("%d",s);
    if(*s!=0)
    {	
    	for(j=*(a+i);j<*(a+i)+*s;j++)
    	scanf("%d",j);
    	for(j=*(b+i);j<*(b+i)+*s;j++)
    	scanf("%d",j);
    	i++;
    	s++;
    	goto leap;
    }
    for(e=0;e<i;e++)
    paixu(*(a+e),*(b+e),*(c+e));
    for(e=0;e<i;e++)
    max(*(a+e),*(b+e),*(c+e));
}
void max(int *a,int *b,int n)
{
	int i,j,m;
	int *r;
	int d[1001]={0};
	r=d;
	for(i=0;i<n;i++)
	{
		int s=0,t=0;
		for(j=0;j<n-i;j++)
		{
			if(*(a+j)>*(b+j+i))
			s++;
			else
			{
				if(*(a+j)==*(b+j+i))
				t++;
			}
		}
		for(j=0;j<i;j++)
		{
			if(*(a+n-i+j)>*(b+j))
			s++;
			else
			{
				if(*(a+n-i+j)==*(b+j))
				t++;
			}
		}
		*(r+i)=200*s-200*(n-t-s);
	}
	r=d;
	m=*r;
	for(r=d+1;r<n+d;r++)
	{
		if(*r>m)
		m=*r;
	}
	printf("%d",m);
	printf("\n");
}
void paixu(int *a,int *b,int c)
{
	int g;
	int *d,*f;
	for(d=a;d<a+c-1;d++)
	{
		for(f=d+1;f<a+c;f++)
		{
			if(*f>*d)
			{
				g=*d;
				*d=*f;
				*f=g;
			}
		}
	}
	for(d=b;d<b+c-1;d++)
	{
		for(f=d+1;f<b+c;f++)
		{
			if(*f>*d)
			{
				g=*d;
				*d=*f;
				*f=g;
			}
		}
	}
}
const int MAXN=1010;
int n,ans,sum;
int a[MAXN],b[MAXN];

int battle(int x,int y)
{
    if (x==y)   return 0;
    else
    if (x>y)   return 1;
    else   return -1;
}

int main()
{
    while (1)
      {
        cin>>n;
        if (n==0)   break;
        for (int i=0;i<n;++i)  cin>>a[i];
        for (int i=0;i<n;++i)  cin>>b[i];
        sort(a,a+n);
        sort(b,b+n);
        for (int i=0;i<n/2;++i)   
          {
            swap(a[i],a[n-i-1]);
            swap(b[i],b[n-i-1]);
          }
        ans=-2147483647;
        for (int i=0;i<=n;++i)
          {
            sum=0;
            for (int j=0;j<i;++j)
              sum+=battle(a[j],b[n-i+j]);
            for (int j=0;j<n-i;++j)
              sum+=battle(a[n-j-1],b[j]);
            if (sum>ans)   ans=sum;
          }
        cout<<ans*200<<endl;
      }            
}