semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
	int ma(int n);
	int n;
	for(;1;){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		ma(n);
	}
	return 0;
}
int ma(int n){
	int sum=0,i,j,a=1,b;
	int wang[1001],tian[1001];
	int endw,endt,staw=0,stat=0;
	endw=n-1;
	endt=n-1;
	for(i=0;i<n;i++){
		scanf("%d",&tian[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&wang[i]);
	}
	for(i=0;i<n;i++){
		for(j=n-1;j>i;j--){
			if(tian[j]>tian[j-1]){
				b=tian[j];
				tian[j]=tian[j-1];
				tian[j-1]=b;
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=n-1;j>i;j--){
			if(wang[j]>wang[j-1]){
				b=wang[j];
				wang[j]=wang[j-1];
				wang[j-1]=b;
			}
		}
	}
	for(;stat<=endt;){
		if(tian[stat]>wang[staw]){
			sum+=200;
			staw++;
			stat++;
		}
		else if(tian[stat]<wang[staw]){
			sum-=200;
			endt--;
			staw++;
		}
		else if(tian[stat]==wang[staw]){
			for(;(a==1);){
				if(tian[endt]>wang[endw]){
					sum+=200;
					endt--;
					endw--;
				}
				else if(tian[endt]<=wang[endw]){
					if(tian[endt]<wang[staw]){
						sum-=200;
					}
					staw++;
					endt--;
					a=0;
				}
			}
			a=1;
		}
	}
	printf("%d\n",sum);
	return 0;
}
int cmp(const void* elem1,const void * elem2){
	int * p1,*p2;
	p1 = (int *) elem1;
	p2 = (int *) elem2;
	if(*p1 < *p2) return 1;
	if(*p1 == *p2 ) return 0;
	if(*p1 > *p2) return -1;
}


int main(){
	int n , i ,j ;
	int a[1005],b[1005];
	int p1,p2,end1,end2;
	int win;
	while(1){
		cin>>n;
		if(n == 0) break;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		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);
	
		win = 0;
	

		for(p1 = 0, p2 = 0, end1 = n-1,end2 = n-1 ; p1<=end1 && p2<=end2 ;){
			if(a[p1] > b[p2]){
				win ++;
				p1++;
				p2++;
			}
			if(a[p1] < b[p2]){
				win --;
				end1--;
				p2++;
			}
			if(a[p1] == b[p2]){
				if(a[end1] > b[end2]){
					win ++;
					end1 --;
					end2 --;
				}
				else if(a[end1] == b[end2]){
					if(a[end1] == b[p2]){
						end1 --;
						p2++;
					}
					else{
						win--;
						end1--;
						p2++;
					}
				}
				else {
					win--;
					end1--;
					p2++;
				}
			}
		}				
		cout<<win * 200 <<endl;
		
	}
	return 0;
}
int cmp(const void *a, const void *b)
{
	return *(int*)b - *(int*)a;
}
int main()
{
	int t[1000], w[1000];
	int N;
	int i,k,l,win,re;
	int tfast, tslow, wfast, wslow;
	while (scanf("%d", &N) && N != 0)
	{
		for (l = 0; l < 1000; l++)
		{
			t[l] = 0;
			w[l] = 0;
		}
		for (i = 0; i < N; i++)
		{
			scanf("%d", &t[i]);
		}
		for (i = 0; i < N; i++)
		{
			scanf("%d", &w[i]);
		}
		qsort(t, N, sizeof(int), cmp);
		qsort(w, N, sizeof(int), cmp);
		win = 0;
		tfast = 0;
		wfast = 0;
		tslow = N - 1;
		wslow = N - 1;
		for (i = 0; i<N; i++)         
		{
			if (t[tfast] == w[wfast])    
			{
				if (t[tslow]>w[wslow])
				{ 
					win++; tslow--; wslow--; 
				}
				else if (t[tslow]<w[wslow])
				{
					win--; tslow--; wfast++; 
				}
				else if (t[tslow] == w[wslow])
				{
					if (t[tslow]<w[wfast])
					{
						win--; tslow--; wfast++; 
					}
					else if (t[tslow] == w[wfast])
					{
						break; 
					}
				}
			}
			else if (t[tfast]>w[wfast])     
			{
				win++; tfast++; wfast++;
			}
			else    
			{ 
				win--; tslow--; wfast++; 
			} 
		}
		printf("%d\n", win*200);
		}
		

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

main()
{
      int n;
      int t[1000];
      int q[1000];
      int i,j,k,m;
      int r,tk,tm,qk,qm;
      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]);
                      
      qsort(t,n,sizeof(int),compare);
      qsort(q,n,sizeof(int),compare);
      r=0;
      tk=0;
      tm=n-1;
     qk=0;
     qm=n-1;
     while(tk<=tm)
     {  
                  if(t[tm]>q[qm])
                  {r++;tm--;qm--;}
                  else if(t[tk]>q[qk])
                  {r++;tk++;qk++;}
                    else if(t[tm]<q[qk])
                  {r--;tm--;qk++;}
                  else break;
}

printf("%d\n",r*200);
}

}
void paixu(int *a,int n)
{
     int i,j,maxj,temp;
     for(i=0;i<n-1;i++)
     {maxj=i;
       for(j=i+1;j<n;j++)
          maxj=a[j]>a[maxj]?j:maxj;
       temp=a[i];
       a[i]=a[maxj];
       a[maxj]=temp;
     }
 }
int max(int x,int y)
{
    return x>y?x:y;
}
main()
{
      int k,n,i,j,t[1000],q[1000],f[1005][1005];
      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]);
             paixu(t,n);
             paixu(q,n);
             memset(f,-5,sizeof(f));
             f[0][0]=0;
             for(i=0;i<n;i++)
               for(j=0;j<=i;j++)
            { if(t[j]>q[i])  f[i+1][j+1]=max(f[i+1][j+1],f[i][j]+200);
             else if(t[j]==q[i])  { f[i+1][j+1]=max(f[i+1][j+1],f[i][j]); f[i+1][j]=max(f[i+1][j],f[i][j]-200);}
             else f[i+1][j]=max(f[i+1][j],f[i][j]-200);
             }
             k=f[n][0];
             for(j=1;j<=n;j++)
               k=f[n][j]>k?f[n][j]:k;
             printf("%d\n",k);
      }
    
      return 0;
}
int n;
int q[1001],t[1001];
int qshang,tshang,qxia,txia;

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

int main()
{
	while(cin>>n)
	{
		if(n==0) break;
		int i;
		for(i=1;i<=n;i++)
			cin>>t[i];
		for(i=1;i<=n;i++)
			cin>>q[i];
		qsort(q+1,n,sizeof(q[1]),cmp);
		qsort(t+1,n,sizeof(t[1]),cmp);
	
		int res=0;
		qxia=txia=n;
		qshang=tshang=1;
		while(qshang<=qxia && tshang<=txia)
		{
			if(t[txia]>q[qxia])
			{
				res++;
				qxia--;
				txia--;
			}
			else if(t[txia]<q[qxia])
			{
				txia--;
				qshang++;
				res--;
			}
			else
			{
				if(q[qshang]>t[tshang])
				{
					qshang++;
					txia--;
					res--;
				}
				else if(q[qshang]<t[tshang])
				{
					tshang++;
					qshang++;
					res++;
				}
				else
				{
					if(t[txia]<q[qshang])
					{
						txia--;
						qshang++;
						res--;
					}
					else
					{
						txia--;
						qshang++;
					}
				}
			}
		}
		cout<<res*200<<endl;
	}
	return 0;
}
int tian[1000], qiw[1000];
int n;
int main()
{
	while(cin>>n && n)
	{
		for(int i = 0;i < n;i ++)
			cin>>tian[i];
		for(int i = 0;i < n;i ++)
			cin>>qiw[i];
		sort(tian,tian + n);
		sort(qiw, qiw + n);
		int ti, tj, qi, qj;
		ti = qi = 0;
		tj = qj = n - 1;
		int sum = 0;
		for(int i = 0;i < n;i ++)
		{
			if(tian[ti] < qiw[qi])
			{
				sum -= 200;
				ti ++;
				qj --;
			}
			else if(tian[ti] > qiw[qi])
			{
				sum += 200;
				ti ++;
				qi ++;
			}
			else if(tian[tj] < qiw[qj])
			{
				sum -= 200;
				ti ++;
				qj --;
			}
			else if(tian[tj] > qiw[qj])
			{
				sum += 200;
				tj --;
				qj --;
			}
			else
			{
				if(tian[ti] > qiw[qj])
					sum += 200;
				else if(tian[ti] < qiw[qj])
					sum -= 200;
				ti ++;
				qj --;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}
int main()
{
    int n,s,tmp; 
    for(s=0;s<100;s++)
    {
           scanf("%d",&n);
           if(n==0)  break;
           int a[1000],b[1000];
           int i,j,k,r;
           for(i=0;i<n;i++)
           scanf("%d",&a[i]);
           for(i=0;i<n;i++)
           scanf("%d",&b[i]);
           for(j=n-1;j>0;j--)
           {
                      for(r=0;r<j;r++)
                      {
                                      if(a[r]>a[r+1])
                                      {
                                                     tmp=a[r+1];
                                                     a[r+1]=a[r];
                                                     a[r]=tmp;
                                      }
                                      if(b[r]>b[r+1])
                                      {
                                                     tmp=b[r+1];
                                                     b[r+1]=b[r];
                                                     b[r]=tmp;
                                      }
                      }
           }
           int m=0;
           for(i=0;i<n;i++)
           {
                           if(a[i]>b[i]) m++;
                           if(a[i]<b[i]) 
                           {
                                         m--;
                                         for(j=n-1;j>i;j--)
                                         b[j]=b[j-1];
                                         continue;
                           }
                           if(a[i]==b[i])
                           {
                                         for(k=n-1;k>i;k--)
                                         {
                                                           if(a[k]>b[k])
                                                           {m++;n--;continue;}
                                                           else
                                                           {
                                                                        if(a[i]==a[k]) continue;
                                                                        m--;
                                                                        for(r=k;r>i;r--)
                                                                        b[r]=b[r-1];
                                                                        n=k+1;
                                                                        break;
                                                           }
                                         }
                           }
           }
      
           printf("%d\n",200*m);
    }
    getchar();
    getchar();
}
int main()
{
	int n,i,tj[1005],qw[1005];
	int win;
	int tl,tr,ql,qr;
	while(cin>>n&&n!=0)
	{
		for(i=0;i<n;i++) cin>>tj[i];
		for(i=0;i<n;i++) cin>>qw[i];
		sort(tj,tj+n);
		sort(qw,qw+n);
		win=0;
		tl=ql=0;
		tr=qr=n-1;
		for(i=0;i<n;i++)
		{
			if(qw[ql]<tj[tl])
			{
				win++;
				ql++;
				tl++;
			}
			else if(qw[ql]>tj[tl])
			{
				win--;
				qr--;
				tl++;
			}
			else
			{
				if(qw[qr]<tj[tr])
				{
					win++;
					qr--;
					tr--;
				}
				else if(qw[qr]>tj[tr])
				{
					win--;
					qr--;
					tl++;
				}
				else
				{
					if(qw[qr]>tj[tl]) {win--;}
					qr--;
					tl++;
					
				}
			}
		}
		cout<<200*win<<endl;
	}
	return 0;
}
int cmp(const void *elem1,const void *elem2)
{
	int *p1,*p2;
	p1=(int *)elem1;
	p2=(int *)elem2;
	return *p2 - *p1;
}
int main()
{
	int mon=0;
	int a[1001];
	int b[1001];
	int n;
	while(cin>>n)
	{
		if(n==0)
		{
			break;
		}
		mon=0;
		int i;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
		}
		for(i=0;i<n;i++)
		{
			cin>>b[i];
		}
		int k,l,j;
		qsort(a,n,sizeof(int),cmp);
		qsort(b,n,sizeof(int),cmp);
		k=0;
		l=n-1;
		j=n-1;
		for(i=0;i<=j;i++)
		{
			if(a[k]>b[i])
			{
				mon+=200;
				k++;
				continue;
			}
			else if(a[k]<b[i])
			{
				mon-=200;
				l--;
				continue;
			}
			else
			{	
				if(a[l]>b[j])
				{
					l--;
					j--;
					i--;
					mon+=200;
					continue;
				}
				else if(a[l]<b[j])
				{
					l--;
					mon-=200;
					continue;
				}
				else
				{
					if(a[l]==b[i])
					{
						l--;
						continue;
					}
					else
					{
						mon-=200;
						l--;
						continue;
					}
				}
			}

		}
		cout<<mon<<endl;
	}
	return 0;
}
int cmp(const void *a,const void *b)
{
return *(int *)b-*(int *)a;//???????????
}
int main()
{
int n,tian[1005],king[1005],tmax,tmin,kmax,kmin,i,j,s;
while(scanf("%d",&n),n>0)
{
   s=0;
   for(i=1;i<=n;i++)
   scanf("%d",&tian[i]);
   qsort(tian+1,n,sizeof(int),cmp);
   for(j=1;j<=n;j++)
   scanf("%d",&king[j]);
   qsort(king+1,n,sizeof(int),cmp);
   tmax=1;tmin=n;kmax=1;kmin=n;
   for(i=1;i<=n;i++)
   {
   if(tian[tmax]>king[kmax])
   {
           s++;
           tmax++;
           kmax++;
    }
    else
    if(tian[tmax]<king[kmax])
    {
    s--;
    tmin--;
    kmax++;
    }
    else
    if(tian[tmin]>king[kmin])
    {
    s++;
    tmin--;
    kmin--;
    }
    else
    if(tian[tmin]<king[kmin])
    {
    s--;
    tmin--;
      kmax++;
    }
    else
    if(tian[tmin]<king[kmax])
    {
    s--;
    tmin--;
    kmax++;
    }
   }
   printf("%d\n",s*200);
}
return 0;
}
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(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[n-1])
					*(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 modify 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 if(*(pwin[i+1]+j-1)-1>*(pwin[i]+j-1)) 
					*(pwin[i]+j)=*(pwin[i+1]+j-1)-1; 
				else 
					*(pwin[i]+j)=*(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;
}
void main()
{
	int n,a[1001],b[1001],i,j,win,draw,lose,t,k,p,max;
	scanf("%d",&n);
	while(n!=0)
	{
		win=0;draw=0;lose=0;
		max=-9999;
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		for(i=1;i<=n;i++)
			scanf("%d",&b[i]);
		for(i=1;i<=n-1;i++) 
			for(j=1;j<=n-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-1;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(j+i>n) k=j+i-n;else k=j+i;
			if (a[k]>b[j]) win=win+1;
			else if(a[k]==b[j]) draw=draw+1;
			else lose=lose+1;
		}
		p=200*(win-lose);
		if(p>max) max=p;
		win=0;draw=0;lose=0;
	}
        printf("%d\n",max);
		scanf("%d",&n);
	}
}
int n;
int t[1000];
int q[1000];

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

int main()
{
	int i;
	int st, sq, et, eq;
	int count;
	while (cin >> n)
	{
		if (n == 0)
			break;
		for (i = 0; i < n; i ++)
			cin >> t[i];
		for (i = 0; i < n; i ++)
			cin >> q[i];

		qsort(t, n, sizeof(int), cmp);
		qsort(q, n, sizeof(int), cmp);

		st = sq = 0;
		et = eq = n - 1;
		count = 0;
		while (st <= et)
		{
			if (t[et] > q[eq])
			{
				count ++;
				et --;
				eq --;
			}
			else if (t[et] < q[eq])
			{
				count --;
				et --;
				sq ++;
			}
			else
			{
				if (t[st] > q[sq])
				{
					count ++;
					st ++;
					sq ++;
				}
				else 
				{
					if (t[et] < q[sq])
						count --;
					et --;
					sq ++;
				}
			}
		}
		cout << 200 * count << endl;
	}
	return 0;
}
int quicksort(int *a,int initial,int end)
{
    int m,i,tmp;
    if (initial>=end) return;
    m=initial;
    for (i=initial+1;i<=end;i++)
      if (a[i]<a[initial])
      {
         tmp=a[i];
         a[i]=a[++m];
         a[m]=tmp;
      }
    tmp=a[m];
    a[m]=a[initial];
    a[initial]=tmp;
    if (initial<m-1) quicksort(a,initial,m-1);
    if (m+1<end) quicksort(a,m+1,end);
}
int run(int a[],int b[],int n)
{
    int *tag1;
    int *tag2;
    int i,time=0,posa1=0,posb1=0,posa2=n-1,posb2=n-1,nul=0;
    tag1=(int *)malloc(sizeof(int)*n);
    tag2=(int *)malloc(sizeof(int)*n);
    quicksort(a,0,n-1);
    quicksort(b,0,n-1);
    while (posa1<=posa2)
    {
        if (a[posa1]>b[posb1])
        {
            time++;
            posa1++;
            posb1++;
        }
        else
          if (a[posa2]>b[posb2])
          {
              time++;
              posa2--;
              posb2--;
          }
          else
            if (a[posa1]<b[posb2])
            {
                time--;
                posa1++;
                posb2--;
            }
            else
              if (a[posa1]==b[posb2])
              {
                  nul++;
                  posa1++;
                  posb2--;
              }
    }
     //printf("win%d nul%d loss%d",time,nul,n-time-nul);
    return (time)*200;//-(n-time-nul)*200;
}

int main()
{
   int n=1,i;
   int *t;
   int *q;
   //scanf("%d",&n);
   while(n!=0)
   {
      scanf("%d",&n);
      t=(int *)malloc(sizeof(int)*n);
      q=(int *)malloc(sizeof(int)*n);
      for (i=0;i<n;i++)
        scanf("%d",t+i);
      for (i=0;i<n;i++)
        scanf("%d",q+i);
      if (n!=0)
      printf("%d\n",run(t,q,n));
   }
}
void main()
{
	int n,i,a[1001],b[1001],temp,t,min,x,y=0,sum=0,j,tt,af,as,bf,bs;
	scanf("%d",&n);
	while(n)
	{
		y=0;
		sum=0;
		for(i=0;i<1000;i++){a[i]=0;b[i]=0;}
		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])
				{
					temp=a[j];
					a[j]=a[j+1];
					a[j+1]=temp;
				}
		for(i=0;i<n-1;i++)
			for(j=0;j<n-1-i;j++)
				if(b[j]<b[j+1])
				{
					temp=b[j];
					b[j]=b[j+1];
					b[j+1]=temp;
				}
		as=n-1;bs=n-1;af=0;bf=0;
		for(i=n-1;i>=af;i--)
		{
			if(a[i]>b[bs])
			{
				as--;bs--;sum+=200;
			}
			else if(a[i]<b[bs])
			{
				as--;bf++;sum-=200;
			}
			else
			{
				while(a[af]>b[bf])
				{
					af++;bf++;sum+=200;
				}
				if(a[af]<b[bf])
				{
					as--;bf++;sum-=200;
				}
				else if (i>af)
				{
					if(a[i]<b[bf])
						sum-=200;
					as--;bf++;
				}
			}
		}
		printf("%d\n",sum);scanf("%d",&n);
	}	
}
int n;
int TianJi[M], King[M];
int dp[M][M];          //dp[i][j]????????????????????i?????,
                       //?"?"??j?????,?"?"??i-j?????,??????????.
int cmp(const void *a, const void *b)
{
       return *(int *)b - *(int *)a;
}
int profit(int x, int y)
{
       if (TianJi[x] > King[y])
       {
              return 200;
       }
       else if (TianJi[x] < King[y])
       {
              return -200;
       }
       else
       {
              return 0;
       }
}
int main()
{
       int i, j;
       while (scanf("%d", &n) && n != 0)
       {
              memset(dp, 0, sizeof(dp));
              for (i = 1; i <= n; i++)
              {
                     scanf("%d", &TianJi[i]);
              }
              for (i = 1; i <= n; i++)
              {
                     scanf("%d", &King[i]);
              }
              //?????????????????
              qsort(TianJi + 1, n, sizeof(TianJi[0]), cmp);
              qsort(King + 1, n, sizeof(King[0]), cmp);
              //??dp
              for (i = 1; i <= n; i++)
              {
                     //????????????????????????,????????????????????
                     dp[i][0] = dp[i - 1][0] + profit(n - i + 1, i);  
                     //????????????????????????,????????????????
                     dp[i][i] = dp[i - 1][i - 1] + profit(i, i);
                     //?????????????????????????,?????????????????,????i?????????
                     for (j = 1; j < i; j++)
                     {
                            dp[i][j] = max( ( dp[i - 1][j] + profit(n - (i - j) + 1, i) ), ( dp[i - 1][j - 1] + profit(j, i) ) );
                     }
              }
              //????????
              int ans = -99999999;
              for (i = 0; i <= n; i++)
              {
                     if (ans < dp[n][i])
                     {
                            ans = dp[n][i];
                     }
              }
              printf("%d\n", ans);
       }
       return 0;
}
int compare(const void *x,const void *y)
{
    int *p1,*p2;
    p1=(int *)x;
    p2=(int *)y;
    return (*p2)-(*p1);
}
main()
{
   while(1)
   {
   int x=0,i,j,k,n,a[1000],b[1000];
   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]);
   qsort(a,n,sizeof(int),compare);
   qsort(b,n,sizeof(int),compare);
   for(i=0;i<n;i++)
   {
      if(a[i]>b[i])
         x++;    
      if(a[i]<b[i] || a[i]==b[i])
      {
         for(j=(n-1);j>=0;j--)
         {
              if(a[j]>b[j])
                 x++;
              if(a[j]<b[j] || a[j]==b[j])
              {
                 n=j;
                 if(i==j && a[i]==b[i])
                    break;
                 for(k=i;k<n;k++)
                    b[k]=b[k+1];
                 if(a[j]<b[i]) x--;
                 break;              
              }                   
         }   
         i--;      
      }                 
   }    
   printf("%d\n",x*200);
}
}
int mycompare(const void *a, const void *b)
{
	return (*(int *)a)-(*(int *)b);
}
int main()
{
	int t[2000];
	int q[2000];
	int ncase;
	int i;
	int h;
	int pbegin;
	int tmax;
	int count;
	while(cin >> ncase)
	{
		if(ncase == 0)
			break;
		for(i = 0; i < ncase; i ++)
		{
			cin >> t[i];
		}
		qsort(t, ncase, sizeof(int), mycompare);
		for(i = 0; i < ncase; i ++)
		{
			cin >> q[i];
		}
		qsort(q, ncase, sizeof(int), mycompare);
		tmax = -99999999;
		pbegin = 0;
		count = 0;
		for(pbegin = 0; pbegin < ncase; pbegin ++)
		{
			count = 0;
			for(i = 0; i < ncase; i ++)
			{
				if(t[(pbegin+i)%ncase] > q[i])
					count += 200;
				if(t[(pbegin+i)%ncase] < q[i])
					count -= 200;
			}
			if(tmax < count)
				tmax = count;
		
		}
		cout << tmax << endl;
	}

	return 0;
}
main()
{
 int n,i,j,k,end1,end2,sum,m;
    int a[1000];
    int b[1000];
    scanf("%d",&n);
    while(n!=0)
    {
        sum=0;
        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;i++)
        {
            for(j=0;j<n-i-1;j++)
            {
                if(a[j]>a[j+1])
                {
                    m=a[j+1];
                    a[j+1]=a[j];
                    a[j]=m;
                }
                
            }
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<n-i-1;j++)
            {
                if(b[j]>b[j+1])
                {
                    m=b[j+1];
                    b[j+1]=b[j];
                    b[j]=m;
                }
                else
                ;
            }
        }
     for(i=j=n-1,end1=end2=0;j>=end2&&i>=end1;j--)
     {
         if(a[i]>b[j])
         {
             sum++;
             i--;
         }
         else if(a[i]<b[j])
         {
             sum--;
             end1++;
         }
         else
         {
             if(a[end1]>b[end2])
             {
                 sum++;
                 end1++;
                 end2++;
                 j++;
             }
             else if(a[end1]<b[end2])
             {
                 sum--;
                 end1++;
             }
             else
             {
                 if(a[end1]==b[j])
                 {
                     end1++;
                 }
                  else
                 {
                     sum--;
                     end1++;
                 }
             }
         }
     }
     printf("%d\n",200*sum);
     scanf("%d",&n);
    }

 
}