semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int qi[1000],tian[1000];
int state[1001][1001];

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

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

int main()
{
	int i,j,n,tmp1,tmp2,maxi;
	while(cin>>n){
		if(n==0)
			break;
		


		for(i = 0; i < n; i ++)
			scanf("%d",&tian[i]);
		for(i = 0; i < n; i ++)
			scanf("%d",&qi[i]);
		
		qsort(tian,n,sizeof(int),cmp);
		qsort(qi,n,sizeof(int),cmp);

		for(i = 0; i <=n ; i ++)
			state[0][i]=0;

		for(i = 1; i <= n; i ++)
			for(j = 0; j <= i; j ++){
				if(j == 0)
					state[i][j]=state[i-1][j]+match(qi[i-1],tian[n-i+j]);
				else if(i == j){
					state[i][j]=state[i-1][j-1]+match(qi[i-1],tian[j-1]);
				}
				else
				{	
					tmp1=state[i-1][j-1] + match(qi[i-1],tian[j-1]);
					tmp2=state[i-1][j] + match(qi[i-1],tian[n-i+j]);
					if(tmp1 > tmp2)
						state[i][j]=tmp1;
					else state[i][j]=tmp2;

				}
			}

		maxi=state[n][0];


		for(i = 1; i <= n; i ++){
			if(state[n][i] > maxi)
				maxi=state[n][i];
		}

		printf("%d\n",maxi);

	


	}
	return 0;
}
int n,a[1010],b[1010],l[1010][1010];

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


int main()
{
	int i,j;

	while(1){
		scanf("%d",&n);
		if(n==0){
			return 0;
		}
		for(i=0;i<n;i++)
			scanf("%d",&b[i]);//tianji
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);//qiwang


		qsort(a,n,sizeof(int),cmp);
		qsort(b,n,sizeof(int),cmp);
		for(i=0;i<n;i++)
		{
			if(a[i]<b[0])
				l[i][0]=1;
			else
				if(a[i]==b[0])
					l[i][0]=0;
				else
					l[i][0]=-1;
		}
		for(i=n-2;i>=0;i--) 
		{
			for(j=1;j<n-i;j++)
			{
				if(a[i+j]<b[j])
					l[i][j]=l[i][j-1]+1;
				else 
				{
					if(a[i+j]>b[j])
						l[i][j]=l[i+1][j-1]-1;
					else
					{
						if(l[i+1][j-1]-1>l[i][j-1])
							l[i][j]=l[i+1][j-1]-1;
						else
							l[i][j]=l[i][j-1];
					}
				}
			}
		}
		printf("%d\n",200*l[0][n-1]);
	}
}
int cmp(const void* a,const void* b)
{
	return *(int*)b-*(int*)a;
}
main()
{
	int a[1005],a1,a2;
	int b[1005],b1,b2;
	int i,n,r,BL;
	while (1)
	{
		scanf("%d",&n);
		if (n==0)
			break;
		for (i=0;i<n;i++)
			scanf("%d",&a[i]);
		a1=0;
		a2=n-1;
		for (i=0;i<n;i++)
			scanf("%d",&b[i]);
		BL=0;
		while (BL==0)
		{
			BL=1;
			for (i=0;i<n-1;i++)
				if (a[i]<a[i+1])
				{
					int tmp;
					tmp=a[i];a[i]=a[i+1];a[i+1]=tmp;
					BL=0;
				}
		}
		BL=0;
		while (BL==0)
		{
			BL=1;
			for (i=0;i<n-1;i++)
				if (b[i]<b[i+1])
				{
					int tmp;
					tmp=b[i];b[i]=b[i+1];b[i+1]=tmp;
					BL=0;
				}
		}
		b1=0;
		b2=n-1;
		r=0;
		while (n>0)
		{
			if (a[a1]>b[b1])
			{
				r++;
				a1++;
				b1++;
				n--;
			}
			else
				if (a[a1]<b[b1])
				{
					r--;
					a2--;
					b1++;
					n--;
				}
				else
					if (a[a2]>b[b2])
					{
						r++;
						a2--;
						b2--;
						n--;
					}
					else
						if (a[a2]<b[b2])
						{
							r--;
							a2--;
							b1++;
							n--;
						}
						else
							if (a[a2]==b[b1])
							{
								a2--;
								b1++;
								n--;
							}
							else
							{
								r--;
								a2--;
								b1++;
								n--;
							}
		}
		printf("%d\n",r*200);
	}
}
void list(int x[],int n)
{
    int i,j,temp;
    for(i=0;i<n-1;i++)
    {
          for(j=i+1;j<n;j++)
          {
                   if(x[j]>x[i])
                      {temp=x[i];x[i]=x[j];x[j]=temp;}
          }
    }
} 
int main()
{
    void list(int x[],int n);
    int n,i,tian[1010],qi[1010],win=0,lose=0,*ptianlow,*pqilow,*ptianfast,*pqifast,money;
  for(;;money=win=lose=0)
  {
    scanf("%d",&n);
    if(n==0)
    break;
    else
    {
    
    for(i=0;i<n;i++)
          scanf("%d",&tian[i]);
    for(i=0;i<n;i++)
          scanf("%d",&qi[i]);
    list(tian,n);
    list(qi,n);
    
    ptianlow=&tian[n-1];
    ptianfast=&tian[0];
    pqilow=&qi[n-1];
    pqifast=&qi[0];
    
    for(;ptianfast<ptianlow+1;)
    {
    
    if(*ptianlow<*pqilow)
    {
          lose++;
          ptianlow--;
          pqifast++;
          continue;
    }
          
    else if(*ptianlow>*pqilow)
    {
          win++;
          ptianlow--;
          pqilow--;
          continue;
    }
    
    else
    {
          if(*ptianfast<*pqifast)
          {
                lose++;
                ptianlow--;
                pqifast++;
                continue;
          }
          else if(*ptianfast>*pqifast)
          {
                win++;
                ptianfast++;
                pqifast++;
                continue;
          }
          else
          {
                if(*ptianlow<*pqifast)
                {
                   lose++;
                   ptianlow--;
                   pqifast++;
                }
                else
                {
                    ptianlow--;
                    pqifast++;
                }
          }
        
    }
	}
    
    money=win*200-lose*200;
    printf("%d\n",money);
}}

return 0;
}
int n;
int King[1005];
int Tian[1005];
int Ans[1005];

int mCmp(const void *v1, const void *v2)
{
	int *i1=(int *)v1;
	int *i2=(int *)v2;
	return *i1-*i2;
}

int main()
{
	int i,j,k;
	int max;
	while(1)
	{
		cin>>n;
		if (n==0) return 0;
		memset(King,0,sizeof(King));
		memset(Tian,0,sizeof(Tian));
		memset(Ans,0,sizeof(Ans));
		max=-1000000;
		for(i=0;i<n;i++)
			cin>>Tian[i];
		for(i=0;i<n;i++)
			cin>>King[i];
		qsort(Tian,n,sizeof(int),mCmp);
		qsort(King,n,sizeof(int),mCmp);
		for(i=0;i<=n;i++)
		{
			Ans[i]=0;
			for(j=0;j<i;j++)
			{
				if(King[n-1-j]>Tian[j])
					Ans[i]-=200;
				else if (King[n-1-j]<Tian[j])
					Ans[i]+=200;
			}
			for(j=i;j<n;j++)
			{
				if(King[j-i]>Tian[j])
					Ans[i]-=200;
				else if (King[j-i]<Tian[j])
					Ans[i]+=200;
			}
			if(Ans[i]>=max) max=Ans[i];
		}
		cout<<max<<endl;
	}
}
int Tj[1001]={0};
int Qw[1001]={0};
int cmp( const void *a, const void *b )
{
	return (*( int *)a - *( int *)b );
}
int main()
{
	int N,i,j;
	int temp=200,count=0;
	while( cin>> N && N!=0 )
	{
			count=N;
			int start1=0,start2=0,end1=N-1,end2=N-1;
			int win=0,lose=0;
		for( i=0; i< N; i++ )
		{
			cin>> Tj[i];
		}
		qsort(Tj,N,sizeof( int ),cmp );
	
		for( i=0; i< N; i++ )
			cin>> Qw[i];
		qsort(Qw,N,sizeof( int ),cmp );
		while( count--)
		{
			if( Tj[start1] > Qw[start2] )
			{
				start1++;
				start2++;
				win++;
			}
			else if( Tj[end1] > Qw[end2] )
			{
				end1--;
				end2--;
				win++;
			}
			else if( Tj[start1] < Qw[start2] )
			{
				start1++;
				end2--;
				lose++;
			}
			else if( Tj[end1] < Qw[end2] )
			{
				start1++;
				end2--;
				lose++;
			}
			else if( Tj[end1] == Qw[end2] )
			{
				if( Tj[start1] < Qw[end2] )
				{
					start1++;
					end2--;
					lose++;
				}
			}
		}

	
      int sum= temp* ( win-lose );
	  cout<<sum<<endl;
	}
	return 0;
}
void sort(int a[],int n)                                         //???????? 
{
	int i,j,k,t;
	for (i=0;i<n;i++)
	{	k=i;
		for (j=i;j<n;j++)
			if (a[j]>a[k])
				k=j;
		if (i!=k)
			{t=a[i];	
			a[i]=a[k];
			a[k]=t;}
	}
}

main()
{	int n,i,j,k,l,s;
	int t[MAX],q[MAX];
	while (1)
		{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);
		s=0;	 
		for (k=0,i=0,j=0,l=n-1;k<n;k++)
			{	if (t[i]>q[j])
					{i++;
					j++;
					s++;}
				else if (t[l-j+i]>q[l])
					{l--;
					s++;}
				else if (t[l-j+i]<q[l])
					{j++;
					s--;}
					else if (t[l-j+i]<q[j])
						{j++;
						s--;}
						else
						j++;
												
			}
		printf("%d\n",s*200);			
					
					
					
				
				
			}		
		}
const int MAX = 1005;
int tian[MAX],qi[MAX];
int n;

int func(int t0,int q0,int t1,int q1){
	if(t0>t1 || q0>q1) return 0;

	while(tian[t1]>qi[q1]){
		t1--;q1--;
		return 1+func(t0,q0,t1,q1);
	}
	while(tian[t0]>qi[q0]){
		t0++;q0++;
		return 1+func(t0,q0,t1,q1);
	}

	if(tian[t0]<qi[q1])
		return func(t0+1,q0,t1,q1-1)-1;
	else if(tian[t0] == qi[q1])
		return func(t0+1,q0,t1,q1-1);
}

int main(){
	while(cin>>n){
		if(n==0) break;
		for(int i=0;i<n;i++)
			cin>>tian[i];
		for(int i=0;i<n;i++)
			cin>>qi[i];
		
		sort(tian,tian + n);
		sort(qi,qi+n);

		cout<<200*func(0,0,n-1,n-1)<<endl;
	}

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

void main()
{
	int n,i,win=0,lose=0,btj,bqw,etj,eqw;
	int *tj,*qw;
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
			break;
		else
		{
			tj=(int*)malloc(n*sizeof(int));
			qw=(int*)malloc(n*sizeof(int));
			for(i=0;i<n;i++)
				scanf("%d",tj+i);
			for(i=0;i<n;i++)
				scanf("%d",qw+i);
			sort(tj,n);
			sort(qw,n);
			btj=bqw=0;
			etj=eqw=n-1;
			while(btj<=etj)
			{
				if(*(tj+btj)>*(qw+bqw))
				{
					win=win+1;
					btj++;
					bqw++;
					continue;
				}
				if(*(tj+etj)>*(qw+eqw))
				{
					win=win+1;
					etj--;
					eqw--;
					continue;
				}
				if(*(tj+btj)<=*(qw+bqw))
				{
					if(*(tj+etj)<*(qw+bqw))
						lose=lose+1;
					bqw++;
					etj--;
					continue;
				}
			}
			printf("%d\n",win*200-lose*200);
			win=lose=0;
		}
	}
}
int compare(const void * elem1, const void * elem2)
{
	return (*(int *)elem1 - *(int *)elem2);
}

int main()
{
	int n;
	int TJ[2001];
	int QW[2001];
	
	while(cin >> n && n != 0)
	{
		for (int i = 0; i < n; i ++)
			cin >> TJ[i];
		for (int i = 0; i < n; i ++)
			cin >> QW[i];
		
		qsort(TJ, n, sizeof(int), compare);
		qsort(QW, n, sizeof(int), compare);

		int Tslow, Tfast, Qslow, Qfast;
		Tslow = Qslow = 0;
		Tfast = Qfast = n - 1;

		int bonus = 0;

		while(Tslow <= Tfast && Qslow <= Qfast)
		{
			if (TJ[Tfast] > QW[Qfast])
			{
				Tfast --;
				Qfast --;
				bonus ++;
			}
			else if (TJ[Tfast] < QW[Qfast])
			{
				Tslow ++;
				Qfast --;
				if (TJ[Tslow - 1] < QW[Qfast + 1])
					bonus --;
			}
			else
			{
				while(Tslow <= Tfast && Qslow <= Qfast)
				{
					if (TJ[Tslow] > QW[Qslow])
					{
						Tslow ++;
						Qslow ++;
						bonus ++;
					}
					else
					{
						Tslow ++;
						Qfast --;
						if (TJ[Tslow - 1] < QW[Qfast + 1])
							bonus --;
						break;
					}
				}
			}
		}
		cout << bonus * 200 << endl;
	}
	return 0;
}
void readdata(); 
void init();
void sort(int a[], int n);
int n,a[1000],b[1000],l[1000][1000]; 
int main() 
{ 
	int i,j;
	while(1)
	{
		readdata(); 
		init(); 
		for(i=n-2;i>=0;i--)
		{ 
			for(j=1;j<n-i;j++)
			{ 
				if(a[i+j]<b[j]) 
					l[i][j]=l[i][j-1]+1; 
				else if(a[i+j]>b[j]) 
					l[i][j]=l[i+1][j-1]-1; 
				else if(l[i+1][j-1]-1>l[i][j-1]) 
					l[i][j]=l[i+1][j-1]-1; 
				else 
					l[i][j]=l[i][j-1];
			}
		} 
		printf("%d\n",l[0][n-1]*200); 
	}
} 

void readdata() 
{ 
	int i; 
	scanf("%d",&n);
	if(n==0)
		exit(0);
	for(i=0;i<n;i++) 
		scanf("%d",&b[i]); 
	for(i=0;i<n;i++) 
		scanf("%d",&a[i]); 
} 

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



void init() 
{ 
	int i;
	sort(a, n);
	sort(b, n);
	for(i=0;i<n;i++) 
	{ 
		if(a[i]<b[0]) 
			l[i][0]=1; 
		else if(a[i]==b[0]) 
			l[i][0]=0; 
		else 
			l[i][0]=-1; 
	} 
}
//??????
void f(int p[],int n)
{
 int i,j,t;
 for(i=0;i<n;i++)
  {
        for(j=(i+1);j<n;j++)
         {
             if(p[j]<p[i])
             {t=p[i];p[i]=p[j];p[j]=t;}
         }
  }
}

main()
{
      
       for(;;)
      {   
        
        int n,i,j,m,win,pmax,qmax;
        scanf("%d",&n);
        if(n==0) break;
     
        int* q=(int*)malloc(n*sizeof(int));
        int* p=(int*)malloc(n*sizeof(int));
        for(i=0;i<n;i++)
        {scanf("%d",&q[i]);}
        for(i=0;i<n;i++)
        {scanf("%d",&p[i]);}
        f(p,n);
        f(q,n);
        
        i=0;j=0;
        win=0;
        pmax=n-1;
        qmax=n-1;
        m=n;
         for(;m>=1;m--)
        {
              if(q[i]>p[j])
              {
                   win++;
                   i++;
                   j++;
              }
              else if(q[i]==p[j])
              {
                   if(q[qmax]>p[pmax])
                   {
                       win++;
                       qmax--;
                       pmax--;
                   }
                  else
                   {
                       if(q[i]<p[pmax]) win--;
                       pmax--;
                       i++;
                   }
                  
                   
              }
              else if(q[i]<p[j])
              {
                  win--;
                  i++;
                  pmax--;
              }
        } 
      printf("%d\n",win*200);
      free(p);free(q); 
      }
}
int cmp(const void*p1,const void*p2)
{
	int *e1,*e2;
	e1=(int*)p1;
	e2=(int*)p2;
	return *e1 > *e2?1:-1;
}
int main()
{
	int n;
	int T[1001],E[1001];
	while(1)
	{
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		cin >> T[i];
		for(int i=0;i<n;i++)
		cin >> E[i];
		qsort(T,n,sizeof(int),cmp);
		qsort(E,n,sizeof(int),cmp);
		int ans=0;
		int lT=0,lE=0,rT=n-1,rE=n-1;
		while(lT<=rT)
		{
			if(T[lT]>E[lE]){ans+=200;lT++;lE++;}
			else if(T[lT]<E[lE])
			{
				ans-=200;
				lT++;rE--;
			}
			else
			{
				if(T[rT]<E[rE]){ans-=200;lT++;rE--;}
				else if(T[rT]>E[rE]){ans+=200;rE--;rT--;}
				else
				{
					if(T[lT]<E[rE]){ans-=200;lT++;rE--;}
					else {lT++;rE--;}
				}
			}
		}
		cout <<ans<<endl;
	}

	return 0;
}
void main()
{
	

	while(1)
	{
		int a[1024]={0},b[1024]={0},choose[1024]={0},bchoose[1024]={0};
		int n;
		scanf("%d",&n);
		if(n==0)
			break;


		int i,j;

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

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


		int win=0,deuce=0,lose=0;
		
		int heada=0,headb=0,taila=n-1,tailb=n-1;
		while(heada<=taila&&headb<=tailb)
		{
			if(choose[heada]!=n)
			{
				heada++;
				continue;
			}
			else if(choose[taila]!=n)
			{
				taila--;
				continue;
			}
			else if(bchoose[headb]==1)
			{
				headb++;
				continue;
			}
			else if(bchoose[tailb]==1)
			{
				tailb--;
				continue;
			}
			else
			{
				if(a[heada]>b[headb])
				{
					choose[heada]=headb;
					bchoose[headb]=1;
					win++;
					heada++;
					headb++;
				}
				else if(a[taila]>b[tailb])
				{
					choose[taila]=tailb;
					bchoose[tailb]=1;
					win++;
					taila--;
					tailb--;
				}
				else
				{
					choose[taila]=headb;
					bchoose[headb]=1;
					if(a[taila]<b[headb])
						lose++;
					else 
						deuce++;
					headb++;
					taila--;
				}
			}
		}

		int money=200*win-(lose)*200;
		printf("%d\n",money);

		
	}
}
int mycmp(const void *e1, const void *e2) {
	return *((int*)e1) - *((int*)e2);
}

int main() {
	int tj[1002], qw[2002], *q, n, ans;
	while(cin >> n) {
		if (n == 0)
			break;
		ans = -99999;
		for (int i = 0; i < n; i++)
			cin >> tj[i];
		for (int i = 0; i < n; i++)
			cin >> qw[i];
		qsort(tj, n, sizeof(int), mycmp);
		qsort(qw, n, sizeof(int), mycmp);
		for (int i = 0; i < n; i++)
			qw[i + n] = qw[i];
		for (q = qw; q < qw + n; q++) {
			int tmp = 0;
			for (int i = 0; i < n; i++) {
				if(tj[i] > q[i])
					tmp ++;
				else if (tj[i] < q[i])
					tmp --;
			}
//			cout << qw[0] << "|" << qw[1] << endl;
//			cout << tmp << endl;
			if (tmp > ans) ans = tmp;
		}
		cout << 200 * ans << endl;
	}
	return 0;
}
main()
{
  int n,i,j,k,a,b,t1,t2,q1,q2,w=0,l=0;
  static int t[1005],q[1005];
  do{
     scanf("%d",&n);
     if(n==0)
       break;
     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++)
        for(j=i+1;j<=n;j++)
             if(t[i]<t[j])
                {
                 a=t[i];
                 t[i]=t[j];
                 t[j]=a;
                }
      for(i=1;i<n;i++)
        for(j=i+1;j<=n;j++)
             if(q[i]<q[j])
                {
                 a=q[i];
                 q[i]=q[j];
                 q[j]=a;
                }
      t1=1;
      t2=n;
      q1=1;
      q2=n;
      while(t1!=t2&&q2!=q1)
           {
             if(t[t1]>q[q1])
               {
                w++;
                t1++;
                q1++;
                continue;
               }
             else if (t[t2]>q[q2])
               {
                 w++;
                 t2--;
                 q2--;
                 continue;
               }
             else if(t[t2]==q[q1])
               {
                t2--;
                q1++;
               }
             else if(t[t2]<q[q1])
               {
                 l++;
                 t2--;
                 q1++;
               }
           }
      if(t[t1]>q[q1])
        w++;
      if(t[t1]<q[q1])
        l++;
      printf("%d\n",(w-l)*200);
      for(i=1;i<=n;i++)
         {
           t[i]=0;
           q[i]=0;
         }
     w=0;
     l=0;
    }while(1);
}
int main()
{
	int array_1[1005],array_2[1005];
	int num;
	int count;
	int first;
	int last;
	while(cin>>num)
	{
		if(num==0)
			break;
		count=0;
		first=0;
		last=num;
		for(int i=0;i<num;i++)
		{
			cin>>array_1[i];
		}
		for(int i=0;i<num;i++)
		{
			cin>>array_2[i];
		}
		sort(array_1,array_1+num);
		sort(array_2,array_2+num);
		for(int i=0;i<num;i++)
		{
			if(array_1[i]>array_2[first])
			{
				count=count+200;
				first++;
			}
			else 
			{
				while(array_1[num-1]>array_2[last-1]&&num-1>i)
				{
					count=count+200;
					num--;
					last--;
				}
				if(array_1[i]<array_2[last-1])
				{
					count=count-200;
					last--;
				}
				else
				last--;
			}

		}
		cout<<count<<endl;
	}
	return 0;
}
int main()
{
	int king_horse[1010], tian_horse[1010], king_head, tian_head, king_tail, tian_tail, n = 0, i = 0, sum = 0, flag = 0;
	while (cin >> n && n != 0)
	{
		sum = 0;
		flag = 0;
		for (i = 0; i < n; i ++)
			cin >> tian_horse[i];
		for (i = 0; i < n; i ++)
			cin >> king_horse[i];
		sort(tian_horse, tian_horse + n);
		sort(king_horse, king_horse + n);
		king_head = tian_head = 0;
		king_tail = tian_tail = n - 1;
		while (king_head <= king_tail && tian_head <= tian_tail)
		{
			if (tian_horse[tian_tail] > king_horse[king_tail])
			{
				sum = sum + 200;
				tian_tail --;
				king_tail --;
			}
			else
			{
				while (king_head <= king_tail && tian_head <= tian_tail)
				{
					if (tian_horse[tian_head] > king_horse[king_head])
					{
						sum = sum + 200;
						tian_head ++;
						king_head ++;
					}
					else
					{
						if (tian_horse[tian_head] < king_horse[king_tail])
							sum = sum - 200;
						tian_head ++;
						king_tail --;
						break;
					}
				}
			}
			if (tian_horse[tian_head] > king_horse[king_tail])
			{
				flag = 1;
				break;
			}
		}
		if (flag == 1)
			sum = sum + (tian_tail - tian_head + 1) * 200;
		cout << sum << endl;
	}
	return 0;
}
int tj[1000],qw[1000];

int main(){
	//freopen("data.txt","r",stdin);
	int n,i,j,w,win,c,m;
	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);
		m=-n;
		for(i=0;i<n;i++)
		{
			c=-i;
			for(j=i,w=0;j<n&&tj[j]>=qw[w];j++,w++)
				if(tj[j]>qw[w])
					c++;
			if(j==n&&c>m)
				m=c;
		}
		printf("%d\n",m*200);
	}
	return 0;
}
void array(int *a,int n)          //array larger-less
{
     
     int i,j,t;
     int *p=a;
     for(i=1;i<=n-1;i++)
     {
                        for(j=1;j<=n-i;j++)
                        {
                                          if(*(p+j)<*(p+j+1))
                                          {
                                                             t=*(p+j);
                                                             *(p+j)=*(p+j+1);
                                                             *(p+j+1)=t;
                                          }
                        }
     }
}
int result(int *a,int *b,int n)
{
    int i,j,t,item[5000]={0},sum=-500;
    for(i=1;i<=n;i++)
    {
                     for(j=1;j<=n;j++)
                     {
                                      t=i+j-1;
                                      if(t>n){t=t-n;}
                                      if(a[t]>b[j]){item[i]++;}
                                      if(a[t]<b[j]){item[i]--;}
                     }
                     if(item[i]>sum)
                     {sum=item[i];}
    }
    return(sum); 
}
int main()
{
for(;;){
      int n,i,j,money;
      int a[5000],b[5000];
      memset(a,0,sizeof(a));
      memset(b,0,sizeof(b));
      scanf("%d",&n);
      if(0==n){break;}
      for(i=1;i<=n;i++)
      {scanf("%d",&a[i]);}
      for(i=1;i<=n;i++)
      {scanf("%d",&b[i]);}
      
      array(a,n);
      array(b,n);
      
      /*for(i=1;i<=n;i++)
      {printf("%d ",a[i]);}*/
      
      money=result(a,b,n)*200;
      printf("%d\n",money);
}
}
int qi[1001];
int tian[1001];

int cmp(const void *e1,const void *e2)
{
	return *(int*)e2-*(int*)e1;
}

int main()
{
	int n;
	int count;
	while(cin>>n)
	{
		if(n==0) break;
		count=0;
		int i,j;
		for(i=0;i<n;i++)
			cin>>tian[i];
		for(i=0;i<n;i++)
			cin>>qi[i];

		qsort(tian,n,sizeof(int),cmp);
		qsort(qi,n,sizeof(int),cmp);

		int l=0,m=0;
		for(i=n-1,j=n-1;i>=l&&j>=m;)
		{
			if(tian[i]<qi[j])
			{
				count--;
				i--;
				m++;
			}
			else if(tian[i]>qi[j])
			{
				count++;
				i--;
				j--;
			}
			else
			{
				if(tian[l]>qi[m])
				{
					count++;
					l++;
					m++;
				}
				else
				{
					if(qi[m]!=tian[i])count--;
					m++;
					i--;
				}
			}
		}
		cout<<count*200<<endl;
	}
	return 0;
}
static int cmp(const void *a, const void *b)
{
	return *(int *)b - *(int *)a;
}
int main()
{
	int n,a[1000]={0},b[1000]={0},t,s,j,p,t1,p1,c,tk,tm,qk,qm;
	for(;;)
	{
		scanf("%d",&n);
		if (n==0) break;
		t1=0;
		p1=0;
		t=0;
		p=0;
		j=0;
		s=0;
		for(int i=0;i<n;i++) scanf("%d",&a[i]);
		for(int i=0;i<n;i++) scanf("%d",&b[i]);
		qsort(a,n,sizeof(int),cmp);
		qsort(b,n,sizeof(int),cmp);
		tk=0;
		tm=n-1;
		qk=0;
		qm=n-1;
		for (;tk<=tm;)
		{
			if (a[tm]>b[qm])
			{
				t++;
				tm--;
				qm--;
			}
			else if(a[tm]<b[qm])
			{
				s++;
				tm--;
				qk++;
			}
			else if(a[tk]>b[qk])
			{
				t++;
				tk++;
				qk++;
			}
			else if (a[tk]<b[qk])
			{
				s++;
				tm--;
				qk++;
			}
			else if(a[tm]<b[qk])
			{
				s++;
				tm--;
				qk++;
			}
			else if(a[tm]>b[qk])
			{
				t++;
				tm--;
				qk++;
			}
			else
			{
				tm--;
				qk++;
			}
		}
		printf("%d\n",t*200-s*200);
	}
	return 0;
}
void saima(int a,int b[1500],int d[1500]);
void paixu(int e[1500],int c);
int main(){
	int tianji[1500],kingma[1500];
	int n,i,num=0;	
	do{
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&tianji[i]);
		}	
		for(i=0;i<n;i++){
			scanf("%d",&kingma[i]);
		}
		if(n==0){
			break;
		}
		paixu(tianji,n);
		paixu(kingma,n);	
		saima(n,tianji,kingma);
	}while(n!=0);	
	return 0;

}
void paixu(int e[1500],int c){
	int temp,k,l;
	for(k=0;k<c-1;k++){
		for(l=0;l<c-1;l++){
			if(e[l]<e[l+1]){
				temp=e[l];
				e[l]=e[l+1];
				e[l+1]=temp;
			}
		}
	}
}
void saima(int a,int b[1500],int d[1500]){
	int qian=0,head=0,twei=a-1,kwei=a-1;
	int j,x,y;
	for(j=0;j<a;j++){
		if(b[head]>d[j]){
			head++;
			qian+=200;
		}else{
			for(x=twei,y=kwei;x>=head;x--,y--){
				if(b[x]>d[y]){
					qian+=200;
					twei--;
					kwei--;
				}
				else{
					if(b[x]<d[j]){
					qian-=200;					
					}
					twei--;
					break;
				}
				
			}
			
		}
		if(twei<head){break;}
	}
	printf("%d\n",qian);
}