semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int myCompare(const void *int_a, const void *int_b)
{
	return *(int*)int_b - *(int*)int_a;
}

int main()
{
	int n, i;
	int *QiWang;
	int *TianJi;
	int *QFast;
	int *TFast;
	int *QSlow;
	int *TSlow;
	int countWin;

	while(1){

		scanf("%d", &n);
		if(n==0)
			break;
		if(((QiWang=(int*)malloc(n*sizeof(int)))==NULL)
			||((TianJi=(int*)malloc(n*sizeof(int)))==NULL)){
			printf("Error: memory out! (1)/n");
			exit(-1);
		}
		for(i=0; i<n; i++){
			scanf("%d", &TianJi[i]);
		}
		for(i=0; i<n; i++){
			scanf("%d", &QiWang[i]);
		}
		qsort(TianJi, n, sizeof(int), myCompare);
		qsort(QiWang, n, sizeof(int), myCompare);

		TFast = TianJi;
		QFast = QiWang;
		TSlow = TianJi + n - 1;
		QSlow = QiWang + n - 1;

		countWin = 0;
		while(1){
			if(*TSlow<*QSlow){
				countWin --;
				TSlow --;
				QFast ++;
			}else if(*TSlow>*QSlow){
				countWin ++;
				TSlow --;
				QSlow --;
			}else{
				if(TFast!=TSlow){
					if(*TFast<*QFast){
						countWin --;
						QFast ++;
						TSlow --;
					}else if(*TFast==*QFast){
						if(*QFast>*TSlow)
							countWin --;
						QFast ++;
						TSlow --;
					}else{
						countWin ++;
						QFast ++;
						TFast ++;
					}
				}else{
					break;
				}
			}
			if(TFast>TSlow)
				break;
		}
		printf("%d\n", 200*countWin);
		free(TianJi);
		free(QiWang);
	}

	return 0;
}
int a[1005], b[1005], w[1005][1005];

int main()
{
	int i, j, n;
	//freopen("input.txt", "r", stdin);
	while(scanf("%d", &n)==1)
	{ 
		if(n<=0)
			return 0;
		for( i=1 ; i<=n ; i++ )
			scanf("%d", &b[i]);
		for( i=1 ; i<=n ; i++ )
			scanf("%d", &a[i]);
		sort(a+1, a+n+1);
		sort(b+1, b+n+1);
		memset(w, -100, sizeof(w));
		for( i=0 ; i<=n+1 ; i++ )
			w[n+1][i]=0;
		for( i=n; i>=1 ; i-- )
		{
			w[i][n+1]=w[i+1][n+1]-1;
			for( j=n ; j>=i ; j-- )
			{
				if(a[i]<b[j])
				{
					w[i][j]=w[i+1][j+1]+1;
				}
				else if(a[i]==b[j])
					w[i][j]=max(w[i+1][j+1], w[i+1][j]-1);
				else
					w[i][j]=w[i+1][j]-1;
				w[i][j]=max(w[i][j], w[i][j+1]);
			}
		}

		//for( i=1 ; i<=n+1 ; i++ )
		//{
		//	for( j=1 ; j<=n+1 ;j ++ )
		//		printf("%3d ", w[i][j]);
		//	puts("");
		//}
	/*	for( i=0, result=-20060311 ; i<=n ; i++ )
			result=max(result, w[1][i]);*/
		printf("%d\n", w[1][1]*200);
	}
}
main()

{    
     int m=1;
     while(m!=0) 
      {
      scanf("%d",&m);
      if(m==0)
      break;
      int a[1000],b[1000];
      int i;
      for(i=0;i<=m-1;i++)
      scanf("%d",&a[i]);
      for(i=0;i<=m-1;i++)
      scanf("%d",&b[i]);
      int j;
      int k;
      int num1=0,num2=0;
      for(i=0;i<=m-1;i++)
         {for(j=i;j<=m-1;j++)
           {if(a[i]<a[j])
              { k=a[i];
                a[i]=a[j];
                a[j]=k; 
              }          
           } 
         }
      for(i=0;i<=m-1;i++)
         {for(j=i;j<=m-1;j++)
           {if(b[i]<b[j])
              { k=b[i];
                b[i]=b[j];
                b[j]=k; 
              }          
           } 
         }
      int x,y,z,w; 
      x=a[0];
      y=b[0];
      z=a[m-1];
      w=b[m-1];
      if (x>y)
      y=x;
      if (z>w)
      z=w;
      
      
      for(i=0;i<m;i++)
      {for (j=0;j<m;j++)
           {if (a[m-1-i]>b[j])
             {num1++;
              a[m-1-i]=z-1;
              b[j]=y+1;
              break;} 
           
           }
              
      }
      for (i=0;i<m;i++)
      {for(j=0;j<m;j++)
          {if (a[i]==b[j])
             {num2++;
             a[i]=z-1;
             b[j]=y+1;}
          }
      }
      
            
      printf("%d\n",num1*200-(m-num1-num2)*200);
     }
        
     
      
      
}
void insertsort(int* array,int left,int right){
     int i,j,temp;
     for(i = left + 1; i <= right; i++){
           temp = array[i];
           for(j = i - 1; j >= left; j--){
                 if(array[j] > temp){
                             array[j + 1] = array[j];
                 }
                 else{
                      break;
                 }
           }
           array[j + 1] = temp;
     }
} 
void merge(int* array,int* temp,int left,int right,int middle){
     int i,j,k,index1,index2;
     for(i = left; i <= middle; i++){
           temp[i] = array[i];
     }
     for(j = 1; j <= right - middle; j++){
           temp[right - j + 1] = array[j + middle];
     }
     for(index1 = left,index2 = right, k = left; k <= right; k++){
                if(temp[index1] <= temp[index2]){
                     array[k] = temp[index1++];
                }
                else{
                     array[k] = temp[index2--];
                }
     }
}
void mergesort(int* array,int* temp,int left,int right){
     if(right - left > 16){
             int middle = (left + right) / 2;
             mergesort(array,temp,left,middle);
             mergesort(array,temp,middle + 1,right);
             merge(array,temp,left,right,middle);
     }
     else{
          insertsort(array,left,right);
     }
}
int main(){
    int n;
    scanf("%d",&n);
    if(n == 0){return 0;}
    int horse_q[1005];      //???? 
    int horse_t[1005];     //????
    int i;
    for(i = 0; i < n; i++){
            scanf("%d",&horse_t[i]);
    }
    for(i = 0; i < n; i++){
            scanf("%d",&horse_q[i]);
    }
    int temp[1005];
    mergesort(horse_t,temp,0,n - 1);
    mergesort(horse_q,temp,0,n - 1);
    int t_head = n - 1;        //?????????? 
    int t_last = 0;            //?????????? 
    int q_head = n - 1;           //??????????
    int q_last = 0;       //?????????? 
    int ans = 0;              //?? 
    while(q_head >= q_last){     //??????????
         if(horse_t[t_head] > horse_q[q_head]){
                       ans += 200;
                       t_head--;
                       q_head--;
         }
         else if(horse_t[t_head] < horse_q[q_head]){
              ans -= 200;
              t_last++;
              q_head--;
         }
         else{
              if(horse_t[t_last] > horse_q[q_last]){
                        ans += 200;
                        t_last++;
                        q_last++;
              }
              else{
                   if(horse_t[t_last] < horse_q[q_head]){
                                      ans -= 200;
                   }
                   t_last++;
                   q_head--;
              }
         }
    }
    printf("%d\n",ans);
    main();
}
int min(int a[],int n)
{
	int min=a[1],i;
	for(i=0;i<n;i++)
	{
		if(min>a[i])
		{
			min=a[i];
		}
	}
	return min;
}
void main()
{
	int T[1100],Q[1100],n=1,i,k,e,s,money=0,first,endT,endQ;
	while(n!=0)
	{
		scanf("%d",&n);
		first=0,endT=n-1,endQ=n-1;
		if(n==0)
			break;
		for(i=0;i<n;i++)
			scanf("%d",&T[i]);
		for(i=0;i<n;i++)
			scanf("%d",&Q[i]);
		for(k=1;k<n;k++)
		{
			for(i=0;i<n-k;i++)
			{
				if(T[i]<T[i+1])
				{
					e=T[i];
					T[i]=T[i+1];
					T[i+1]=e;
				}
				if(	Q[i]<Q[i+1])
				{
					e=Q[i];
					Q[i]=Q[i+1];
					Q[i+1]=e;
				}
			}
		}
		for(i=0;i<n;i++)
		{
			if(T[first]>Q[i])
			{
				first++;
				money+=200;
			}
			else if(T[first]<Q[i])
			{
				endT--;
				money-=200;
			}
			else if(T[first]==Q[i])
			{
				for(k=endT,s=endQ;k>=first;k--,s--)
				{
					if(T[k]>Q[s])
					{
						money+=200;
						endT--;
						endQ--;
					}
					else
					{
						if(T[k]<Q[i]) 
						money-=200;
						endT=k-1;
						endQ=s;
						break;               
					}
				}
			}
			if(first>endT)
				break;
		}
		printf("%d\n",money);
		money=0;
	}
}
void exchange(int *a,int *b)
{
	if(*a>*b)
	{
		*a=*a+*b;
		*b=*a-*b;
		*a=*a-*b;
	}
}
void sort(int*p,int n)
{
	int i,j;
	for(i=0;i<n-1;i++)
	for(j=0;j<n-1-i;j++)
	exchange(p+j,p+j+1);
}
int race(int*t,int*q,int n)
{
	int tj=0,qw=0,count=0;
	for(;;)
	{
		if(n==0)	break;
		if(*(t+tj)>*(q+qw))
		{	tj++;qw++;count++;n--;	}
		else if(*(t+tj+n-1)>*(q+qw+n-1))
		{	count++;n--;	}
		else 
		{	
			if(*(t+tj)<*(q+qw+n-1))count--;
			tj++;n--;	
		}
	}	
	return count;
}
int main()
{
	int n,t[1000],q[1000],i;
	for(;;)
	{
	scanf("%d",&n);
	if(n==0)break;
	for(i=0;i<n;i++)scanf("%d",&t[i]);
	for(i=0;i<n;i++)scanf("%d",&q[i]);
	sort(t,n);
	sort(q,n);
	printf("%d\n",200*race(t,q,n));
	}
	return 0;
}
int compare(const void*a,const void*b)
{
	return (*(int*)b)-(*(int*)a);
}
int main()
{
	int n=0,i=0,tianji[1000]={0},qiwang[1000]={0};
	while(cin>>n)
	{
		if(n==0)
			break;
		for(i=0;i<n;i++)
			cin>>tianji[i];
		for(i=0;i<n;i++)
			cin>>qiwang[i];
		qsort(tianji,n,sizeof(int),compare);
		qsort(qiwang,n,sizeof(int),compare);
		int head1=0,tail1=n-1,head2=0,tail2=n-1,money=0;
		while(head1<=tail1)
		{
			if(tianji[tail1]>qiwang[tail2])
			{
				money+=200;
				tail1--;
				tail2--;
			}
			else if(tianji[tail1]<qiwang[tail2])
			{
				money-=200;
				tail1--;
				head2++;
			}
			else
			{
				if(tianji[head1]>qiwang[head2])
				{
					money+=200;
					head1++;
					head2++;
				}
				else if(tianji[head1]<qiwang[head2])
				{
					money-=200;
					tail1--;
					head2++;
				}
				else
				{
					if(tianji[tail1]<qiwang[head2])
						money-=200;
					tail1--;
					head2++;
				}
			}
		}
		cout<<money<<endl;
	}
	return 0;
}
void main()
{
	int num[100],speed_tian[100][1000],speed_qi[100][1000],money[100],win,lose,i,j,k,l,end_qi,x,start_qi,start_tian,mid;
	for(i=0;;i++)
	{
		scanf("%d",&num[i]);
		if (num[i]==0) break;
		else 
		{
			for(j=0;j<=num[i]-1;j++)	scanf("%d",&speed_tian[i][j]);
			for(j=0;j<=num[i]-1;j++)	scanf("%d",&speed_qi[i][j]);
		}
	}//??????
	for(j=0;j<=i-1;j++)
	{
		for (k=0;k<=num[j]-1;k++)
			for (l=0;l<num[j]-1-k;l++)
				if(speed_tian[j][l]<speed_tian[j][l+1])
				{
					mid=speed_tian[j][l];
					speed_tian[j][l]=speed_tian[j][l+1];
					speed_tian[j][l+1]=mid;
				}
	}//????????
	for(j=0;j<=i-1;j++)
	{
		for (k=0;k<=num[j]-1;k++)
			for (l=0;l<num[j]-1-k;l++)
				if(speed_qi[j][l]<speed_qi[j][l+1])
				{
					mid=speed_qi[j][l];
					speed_qi[j][l]=speed_qi[j][l+1];
					speed_qi[j][l+1]=mid;
				}
	}//????????
	for(j=0;j<=i-1;j++)//??????
	{
		start_qi=0;
		start_tian=0;
		end_qi=num[j]-1;
		win=0;
		lose=0;
		x=num[j]-1;
		while(x>=start_tian)
		{
			if (speed_tian[j][x]>speed_qi[j][end_qi])
			{
				win++;
				end_qi--;
			}
			else if(speed_tian[j][x]<speed_qi[j][end_qi])
			{
				lose++;
				start_qi++;
			}
			else 
			{
				while(speed_tian[j][start_tian]>speed_qi[j][start_qi])
				{
					win++;
					start_tian++;
					start_qi++;
				}
				if(speed_tian[j][x]<speed_qi[j][start_qi]) lose++;
				start_qi++;
			}
			x--;
		}

		money[j]=win*200-lose*200;
	}
	for(j=0;j<=i-1;j++) printf("%d\n",money[j]);
}
int n;
int tian[1001] = { 0 };
int qi[1001] = { 0 };
int cal(int n)
{
	int result = -200 * n;
	int money =0 ;
	for(int i=0;i<n;i++)
	{
		int k=0;
		while(i+k<n)
		{
			if(tian[k] > qi[i+k])
			{
				k++;
				money += 200;
			}
			else if(tian[k] == qi[i+k])
			{
				k++;
			}
			else
			{
				k = 0;
				money = 0;
				break;
			}
		}
		if(i+k==n)
		{
			if(money - i * 200 > result)
			{
				result = money  - i * 200;
			}
			money = 0;
		}
	}
	return result;
}
int cmp(const void * af, const void *bf)
{
	int *elem1 = (int*)af;
	int *elem2 = (int*)bf;
	return (*elem2 - *elem1);
}
int main()
{
	int n;
	while(cin >> n && n!=0)
	{
		for(int i=0;i<n;i++)
		{
			cin >> tian[i];
		}
		for(int i=0;i<n;i++)
		{
			cin >> qi[i];
		}
		qsort(tian,n,sizeof(int),cmp);
		qsort(qi,n,sizeof(int),cmp);
		int pos = 0;
		cout << cal(n) << endl;

	}
	return 0;
}
void main()
{
	int l1,l2,t1,t2,temp,i,j,n;
         long sum;
	int a[2000],b[2000];
	scanf("%d",&n);
	while (n>0)
	{
		sum=0;
		l1=1;l2=n;t1=1;t2=n;
		for (i=1;i<=n;i++)
			scanf("%d",&a[i]);
		for (i=1;i<n;i++)
			for (j=i+1;j<=n;j++)
				if (a[i]<a[j])
				{temp=a[i];a[i]=a[j];a[j]=temp;}
		for (i=1;i<=n;i++)
			scanf("%d",&b[i]);
		for (i=1;i<n;i++)
			for (j=i+1;j<=n;j++)
				if (b[i]<b[j])
				{temp=b[i];b[i]=b[j];b[j]=temp;}
		while (l1<=l2)
		{
			if (a[l1]>b[t1])
			{ 
			    sum=sum+200;
			    l1++;t1++;
			}
			else
			{
			    if (a[l2]>b[t2])
				{
					sum=sum+200;
					l2--;t2--;
				}
				else
				{
					if (a[l2]>b[t1]) sum=sum+200;
					if (a[l2]<b[t1]) sum=sum-200;
					l2--;t1++;
				}
					
			}
		}
		printf("%d\n",sum);
		scanf("%d",&n);
	}
}
int cmp(const void* e1,const void* e2)
{
	return *(int*)e2-*(int*)e1;
}

int main()
{
	int n;
	int King[1000];
	int Tian[1000];

	//??????
	int Win;
	//????
	int Lose;
	
	int begin;
	int end;

	int i,j;
	while(1)
	{
		Win=0;
		Lose=0;
		cin>>n;
		if(n==0)
			break;
		
		for(i=0;i<n;i++)
			cin>>Tian[i];
		for(i=0;i<n;i++)
			cin>>King[i];
		

		qsort(King,n,sizeof(int),cmp);
		qsort(Tian,n,sizeof(int),cmp);
		//??
		begin=0;
		end=n-1;
		//??
		i=0;j=n-1;
		while(i<=j)
		{
			//win
			if(King[i]<Tian[begin])
			{
				Win++;
				begin++;
				i++;
			}
			
			//lose
			else if(King[i]>Tian[begin])
			{
				Lose++;
				i++;
				end--;
			}

			//tie
			else if(King[i]==Tian[begin])
			{
				while(King[j]<Tian[end] && j>i && end>begin )
				{
					Win++;
					end--;
					j--;
				}
				if(King[j]>Tian[end])
				{
					Lose++;
					i++;
					end--;
				}
				else if(King[j]==Tian[end])
				{
					if(King[i]>Tian[end])
					{
						Lose++;
						end--;
						i++;
					}
					else if(King[i]==Tian[end])
					{
						end--;
						i++;
					}
				}
			}
		}
		
		cout<<(Win-Lose)*200<<endl;
	}

	return 0;
}
long n;
long tian[1010],king[1010];
void sort(long a[])
{
    long i,j,temp;
    for(i=1;i<n;i++)
    {
         for(j=i+1;j<=n;j++)
         {
                if(a[j]<a[i])
                {
                      temp=a[j];
                      a[j]=a[i];
                      a[i]=temp;                 
                 }
         }
    }
}

void main()
{
    long i,j,money;
    for(scanf("%ld",&n);n>0;scanf("%ld",&n))
    {
          for(i=1;i<=n;i++)
          {
              scanf("%ld",tian+i);
          }
           for(i=1;i<=n;i++)
          {         
            scanf("%ld",king+i);
           }
         sort(tian);sort(king);
         long begin_tian=1,end_tian=n;
          long begin_king=1,end_king=n;
         money=0;
        while(begin_tian<=end_tian)
        {
            while((tian[begin_tian]>king[begin_king])&&(begin_tian<=end_tian))
            {
                      money+=200;
                      begin_tian++;begin_king++;
            }
            while((tian[end_tian]>king[end_king])&&(begin_tian<=end_tian))
            {
                     money+=200;
                     end_tian--;end_king--;     
            }
            if(begin_tian<=end_tian)
            {
                   if(tian[begin_tian]<king[end_king])
                    money-=200;
                    begin_tian++;end_king--;
            }
         }
    printf("%ld\n",money);
  }
}
int Mycompare(const void *p1, const void *p2)
{
	return *((int *)p2) - *((int *)p1);
}
int main()
{
	int horseNum, Thorse[1000], Qhorse[1000], i;
	int Th, Tt, Qh, Qt, sum;
	while(cin>>horseNum)
	{
		if(horseNum == 0)
			break;
		for(i=0; i<horseNum; i++)
			cin>>Thorse[i];
		for(i=0; i<horseNum; i++)
			cin>>Qhorse[i];
		qsort(Thorse, horseNum, sizeof(int), Mycompare);
		qsort(Qhorse, horseNum, sizeof(int), Mycompare);
		Th = Qh = 0;
		Tt = Qt = horseNum - 1;
		sum = 0;
		while(Th <= Tt)
		{
			if(Thorse[Th] > Qhorse[Qh])
			{
				sum = sum + 200;
				Th = Th + 1;
				Qh = Qh + 1;
			}
			else if(Thorse[Th] < Qhorse[Qh])
			{
				sum = sum - 200;
				Qh = Qh + 1;
				Tt = Tt - 1;
			}
			else
			{
				if(Thorse[Tt] > Qhorse[Qt])
				{
					sum = sum + 200;
					Tt = Tt - 1;
					Qt = Qt - 1;
				}
				else
				{
					if(Thorse[Tt] < Qhorse[Qh])
					{
						sum = sum - 200;
						Tt = Tt - 1;
						Qh = Qh + 1;
					}
					else
					{
						Tt = Tt - 1;
						Qh = Qh + 1;
					}
				}
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}
main()
{
    
    for(;;)
    {
    int n=1,a[1005],b[1005],i,j,h,m,mt,yin=0,shu=0,pin=0;       
    scanf("%d",&n);
    if(n==0) break;
    else
    {
    for(i=1;i<=n;i++)
       scanf("%d",&a[i]);
    for(j=1;j<=n;j++)
       scanf("%d",&b[j]);
    for(h=n-1;h>=1;h--)
    {
        for(i=1;i<=h;i++)
        {
             if(a[i]<a[i+1]) 
             {m=a[i]; a[i]=a[i+1]; a[i+1]=m;}    
        }
    }     
    //for(i=1;i<=n;i++)printf("%d ",a[i]);printf("\n");
    for(h=n-1;h>=1;h--)
    {
        for(i=1;i<=h;i++)
        {
             if(b[i]<b[i+1]) 
             {m=b[i]; b[i]=b[i+1]; b[i+1]=m;}    
        }
    }    
    //for(i=1;i<=n;i++)printf("%d ",b[i]); printf("\n");
    
    m=1;mt=1;
    for(i=n,j=n;j>=m;)
    {
        if(a[i]>b[j]) 
                {i--;j--;yin++;continue;}  
        if(a[i]==b[j])
                {
                 if(a[mt]>b[m])
                     {mt++;m++;yin++;continue;}
                 if( a[mt]<b[m] )
                     {i--;m++;shu++;continue;}
                 if(( a[mt]==b[m])&&(b[m]!=b[j]) )    
                     {i--;m++;shu++;continue;}
                 if( (a[mt]==b[m])&&(b[m]==b[j]) )    
                     {i--;j--;pin++;continue;}    
                }
        if(a[i]<b[j])
                {i--;m++;shu++;continue;}
    }
    
    //printf("%d\n",yin);
    //printf("%d\n",shu);
    //printf("%d\n",pin);
    printf("%d\n",200*(yin-shu));
    }
    }
}
int main()
{
	int money;
	int smart[1000];
	int stupid[1000];
	int *p;
	int	*q;
	int n,i,j,e;
	int profit;
	p=smart;
	q=stupid;
	for(;;){
		profit=-100000;
		
		scanf("%d",&n);
		if(n==0){
			break;
		}
		else{
			for(i=0;i<n;i++){
				scanf("%d",p+i);
			}
			for(i=0;i<n;i++){
				scanf("%d",q+i);
			}
			for(i=n-1;i>=0;i--){
				for(j=0;j<i;j++){
					if(*(p+j)<*(p+j+1)){
						e=*(p+j);
						*(p+j)=*(p+j+1);
						*(p+j+1)=e;
					}
				}
			}
			for(i=n-1;i>=0;i--){
				for(j=0;j<i;j++){
					if(*(q+j)<*(q+j+1)){
						e=*(q+j);
						*(q+j)=*(q+j+1);
						*(q+j+1)=e;
					}
				}
			}
			for(i=0;i<n;i++){
				for(j=i;j<n;j++){
					if(*(p+j-i)>*(q+j))
						money=money+200;
					else if(*(p+j-i)<*(q+j))
						money=money-200;
				}
				for(j=i-1;j>=0;j--){
					if(*(p+n-1-j)>*(q+j))
						money=money+200;
					else if(*(p+n-1-j)<*(q+j))
						money=money-200;
				}
				if(money>profit){
					profit=money;
				}
				money=0;
			}
			printf("%d\n",profit);
		}
		
	}
	return 0;
}
int compare(const void *a,const void *b)
{

    int x,y;
    x=*(int *)a;
    y=*(int *)b;
    if (x<y)
          return 1;
    else if (x>y)
          return -1;
        else 
        	return 0;
}
int main()
{
    int i,j,k,s,x,n,t[1000],q[1000];
    cin>>n;
    while (n!=0)
    {
          for (i=0;i<n;i++)
                cin>>t[i];
          for (i=0;i<n;i++)
                cin>>q[i];
          qsort(t,n,sizeof(t[0]),compare);
          qsort(q,n,sizeof(q[0]),compare);
          for (i=0;t[0]<q[i] && i<n;i++);
          for (s=-200*n;i<n;i++)
          {
                x=-i*200;
                for (j=i,k=0;j<n;j++,k++)
                {
                      if (t[k]>q[j])
                            x+=200;
                      else if (t[k]<q[j])
                            x-=200;
                }
                if (x>s)
                      s=x;
          }
          cout<<s<<endl;
          scanf("%d",&n);
    }
    return 0;
}
void main()
{
	
	int a[1000],b[1000],n,i,j,max,c[1000],num,t,s,k;
	for(k=0;k<1000;k++)
	{
		num=0;max=0;
	scanf("%d",&n);
	if(n==0)break;
	for(i=0;i<n;i++)
		scanf("%d",&b[i]);
    for(i=0;i<n;i++)
		scanf("%d",&a[i]);

        for(j=0;j<n-1;j++)
		for(i=0;i<n-1-j;i++)
		{
			if(a[i]<a[i+1])
			{
				t=a[i];
	            a[i]=a[i+1];
				a[i+1]=t;
			}
			if(b[i]<b[i+1])
			{
				s=b[i];
				b[i]=b[i+1];
				b[i+1]=s;
			}
		}

	for(i=0;i<n;i++)
			{
			if(b[i]>a[i])
				num=num+200;
			if(b[i]<a[i])
				num=num-200;
			}
			c[n-1]=num;
			
        for(j=0;j<n-1;j++)
		{
			num=0;
t=b[n-1];
            for(i=0;i<n-1;i++)
			{
				
				b[n-1-i]=b[n-2-i];
				
			}
b[0]=t;
			for(i=0;i<n;i++)
			{
			if(b[i]>a[i])
				num=num+200;
			if(b[i]<a[i])
				num=num-200;
			}
			c[j]=num;
		}
		max=c[0];
for(j=0;j<n;j++)
			if(c[j]>max)
				max=c[j];
	
		
		printf("%d\n",max);
	}
	

    

}
static int cmp(const void *a, const void *b)
{
	return *(int *)b - *(int *)a;
}
int main()
{
	int n;
	int i,j,k;
	int temp;
	int win=0;
	int tie=0;
	int lose=0;
	int tianji[1000];
	int qiwang[1000];
	while(1)
	{
		win=0;
		tie=0;
		lose=0;
		scanf("%d",&n);
		if(n==0)
		{
			break;
		}
		for(i=0;i<n;i++)
		{
			scanf("%d",tianji+i);
		}
		for(i=0;i<n;i++)
		{
			scanf("%d",qiwang+i);
		}
		qsort(tianji,n,sizeof(int),cmp);
		qsort(qiwang,n,sizeof(int),cmp);
		for(j=0;j<n;j++)
		{
			if(qiwang[j]==-1)
			{
				continue;
			}		
			for(i=n-1;i>=0;i--)
			{
				if(tianji[i]==-1)
				{
					continue;
				}
				if(tianji[i]>qiwang[j])
				{
					tianji[i]=-1;
					qiwang[j]=-1;
					win++;
					break;				
				}
			}
		}
		for(i=0;i<n;i++)
		{
			if(tianji[i]==-1)
			{
				continue;
			}
			for(j=0;j<n;j++)
			{
				if(qiwang[j]==-1)
				{
					continue;
				}
				if(tianji[i]==qiwang[j])
				{
					tianji[i]==-1;
					qiwang[j]==-1;
					tie++;
					break;
				}
			}
		}
		lose=n-win-tie;
		printf("%d\n",(win-lose)*200);	
	}
	return 0;
}
int a[1010],b[1010];  
int main()  
{  
    int n;  
	int i;
    while(scanf("%d",&n),n)  
    {  
        for(i=1; i<=n; i++)  scanf("%d",&a[i]);  
        for(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;  
}
void paixu(int*p,int k);
int saima(int*p,int*q,int k);
main()
{
      int tian[2020],qi[1010];
      int n,i,j,k,m,max;
      for(;;)
      {
             scanf("%d",&n);
             if(n!=0)
             {
                     for(i=0;i<n;i++)
                     scanf("%d",&tian[i]);
                     for(j=0;j<n;j++)
                     scanf("%d",&qi[j]);
                     paixu(tian,n);
                     paixu(qi,n);
                     max=-n;
                     for(k=0;k<n;k++)
                     tian[n+k]=tian[k];
                     for(i=0;i<n;i++)
                     {
                          m=0;
                          for(j=0;j<n;j++)
                          {
                                if(tian[j+i]>qi[j])
                                m=m+1;
                                if(tian[j+i]<qi[j])
                                m=m-1;
                          }
                          if(m>max)
                          max=m;
                     }
                     printf("%d\n",200*max);
             }
             else
             break;
      }

}
void paixu(int*p,int k)
{
     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 kh[1000], th[1000];

int cmp(const void *a, const void *b)
{
    return (*(int *)b-*(int *)a);
}
int main(void)
{
    int N, i, j, k, mxt, mxk, w;
    while(scanf("%d", &N),N)
    {
        for(i = 0; i < N; ++i)
            scanf("%d", &th[i]);
        qsort(th, i, sizeof(th[0]), cmp);
        for(i = 0; i < N; ++i)
            scanf("%d", &kh[i]);
        qsort(kh, i, sizeof(kh[0]), cmp);
       
        w = k = j = 0;
        mxk = mxt = N-1;
        for(i = 0; i < N; ++i)
        {
            if(th[j] > kh[k])
                ++w, ++j, ++k;
            else if(th[mxt] > kh[mxk])
                ++w, --mxt, --mxk;
            else if(th[mxt] < kh[k])
                --w, --mxt, ++k;
            else;
        }
        printf("%d\n", 200*w);
    }
    return 0;
}