semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
void InsertSort(int[],int);
int SaiMa(int[],int[],int);
void main()
{
	int horse_n[100];//??
	int horseTian[100][1000];
	int horseQi[100][1000];
	int horse_i=0;//??(???+1)
	int i;
	scanf("%d",&horse_n[horse_i]);
	do
	{
		for(i=0;i<horse_n[horse_i];i++){
			scanf("%d",&horseTian[horse_i][i]);}
		for(i=0;i<horse_n[horse_i];i++){
			scanf("%d",&horseQi[horse_i][i]);}
		horse_i++;
		scanf("%d",&horse_n[horse_i]);
	}while(horse_n[horse_i]!=0);
	
	for(i=0;i<horse_i;i++){
	InsertSort(horseTian[i],horse_n[i]);
	InsertSort(horseQi[i],horse_n[i]);}
	for(i=0;i<horse_i;i++)
		printf("%d\n",SaiMa(horseTian[i],horseQi[i],horse_n[i]));


}
void InsertSort(int Ptr[],int length)//??????
{
	int i,j,key;
	for(i=1;i<length;i++)
	{ 
		key=Ptr[i];
		j=i-1;
		while(j>=0&&Ptr[j]<key)
		{
			Ptr[j+1]=Ptr[j];
			j=j-1;
		}
		Ptr[j+1]=key;
	}
}
int SaiMa(int Tian[],int Qi[],int length)
{
	int l[1000][1000];
	int i,j;
	for(i=0;i<length;i++)
	{
		if(Qi[i]<Tian[0])
			l[i][0]=1;
		else
		if(Qi[i]==Tian[0])
			l[i][0]=0;
		else
			l[i][0]=-1;
		}
	for(i=length-2;i>=0;i--)
	{
		for(j=1;j<length-i;j++) //???????????????
		{
			if(Qi[i+j]<Tian[j]) //???????
				l[i][j]=l[i][j-1]+1;//????????
			else
			{
				if(Qi[i+j]>Tian[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]; //?????
}
}
}
}
return 200*l[0][length-1];
}
int n;
int q[M];
int p[M];
int map[M][M];
int vis[M][M];


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


void Initial()
{
    memset(map,-1,sizeof(map));
    memset(vis,0,sizeof(vis));
}


int Branch(int cur,int s,int e)
{
    int Cnt = 0;
    if(cur > n) return 0;
    if(p[cur] > q[s]){
       Cnt++; s++;
       if(!vis[s][e]){
          map[s][e] =  Branch(cur+1,s,e);
          vis[s][e] = 1;
       }
       Cnt += map[s][e];
    }
    else if(p[cur] < q[s]){
       Cnt--; e--;
       if(!vis[s][e]){
        map[s][e] = Branch(cur+1,s,e);
        vis[s][e] = 1;
       }
       Cnt += map[s][e];
    }
    else if(p[cur] == q[s]){
        if(!vis[s+1][e]){
          map[s+1][e] = Branch(cur+1,s+1,e);
          vis[s+1][e] = 1;
        }
        if(!vis[s][e-1]){
          map[s][e-1] = Branch(cur+1,s,e-1);
          vis[s][e-1] = 1;
        }
        Cnt += max(map[s+1][e],map[s][e-1]-1); //!!! -1
    }
    return Cnt;
}


int main()
{
    #ifdef LOCA
    freopen("in.in","r",stdin);
    #endif
    int i,j,s,e;
    while(scanf("%d",&n) && n)
    {
        for(i = 1;i <= n;i++)
         scanf("%d",&p[i]);
        for(i = 1;i <= n;i++)
         scanf("%d",&q[i]);
        qsort(&p[1],n,sizeof(int),cmp);
        qsort(&q[1],n,sizeof(int),cmp);
        Initial(); s = 1; e = n;
        printf("%d\n",Branch(1,s,e)*200);
    }


    return 0;
}
int speed[1024], ano[1024];

int fight(int myId, int anoId)
{
	if(speed[myId] < ano[anoId])
		return -1;
	else if(speed[myId] == ano[anoId])
		return 0;
	else
		return 1;
}

int main()
{
	int n;
	while(scanf("%d", &n) == 1 && n != 0)
	{
		int sum = 0;
		for(int i = 0; i < n; ++i)
			scanf("%d", speed + i);
		for(int i = 0; i < n; ++i)
			scanf("%d", ano + i);
		sort(speed, speed + n);
		sort(ano, ano + n);
		int myLow = 0, myHigh = n - 1, anoLow = 0, anoHigh = n - 1;
		while(myLow <= myHigh)
		{
			if(speed[myLow] > ano[anoLow])
			{
				sum += fight(myLow, anoLow);
				++myLow, ++anoLow;
			}
			else if(speed[myLow] < ano[anoLow])
			{
				sum += fight(myLow, anoHigh);
				++myLow, --anoHigh;
			}
			else if(speed[myHigh] > ano[anoHigh])
			{
				sum += fight(myHigh, anoHigh);
				--myHigh, --anoHigh;
			}
			else if(speed[myHigh] <= ano[anoHigh])
			{
				sum += fight(myLow, anoHigh);
				++myLow, --anoHigh;
			}
		}
		printf("%d\n", sum * 200);
	}
}
int main(){
    int n,i;
    int tianji[10100],king[10100];
    while(cin>>n){
        if(!n)break;
        i=0;
        while(i<n){
            cin>>tianji[i++];
        }
        i=0;
        while(i<n){
            cin>>king[i++];
        }
        sort(tianji,tianji+n);
        sort(king,king+n);
        int b1,e1,b2,e2,score=0;
       // cout<<"%"<<score<<endl;
        b1=0;e1=n-1;b2=0;e2=n-1;
        while(b1<=e1){
            if(tianji[e1]>king[e2]){
                score+=200;e1--;e2--;
            }
            else if(tianji[e1]<king[e2]){
                score-=200;e2--;b1++;
            }
            else{
                if(tianji[b1]!=king[b2]&&b1<=e1)
                                while(tianji[b1]!=king[b2]&&b1<=e1){
                    if(tianji[b1]>king[b2]){
                        b1++;b2++;score+=200;
                    }
                    else{
                        b1++;e2--;score-=200;
                    }
                }
                else if(b1<e1&&tianji[b1]==king[b2]){
                    if(tianji[b1]<king[e2])score-=200;
                    b1++;e2--;
                }
                else if(b1==e1)break;
            }
        }
        cout<<score<<endl;
    }
    return 0;
}
void bubble_sort(int a[],int n)
    {
    int i,j,t;
    for(j=0;j<n;j++)
        { 
                 for(i=0;i<n-j-1;i++)
                {
                        if(a[i]<a[i+1])
                         {t=a[i];
                        a[i]=a[i+1];
                        a[i+1]=t;} 
                        else;          
                 }
        }    
   }

  
int main()
{
   int a[1000]={0},b[1000]={0};  
   int i,n;
   int  sum,amax,bmax,amin,bmin; 
   
   while((scanf("%d",&n))&&(n!=0))
   { 
     
          for(i=0;i<n;i++)  
          scanf("%d",&b[i]); //???      
          for(i=0;i<n;i++)
          scanf("%d",&a[i]);//??? 
        
          bubble_sort(a,n);
          bubble_sort(b,n);

           sum=0;amax=0;bmax=0;amin=n-1;bmin=n-1;
           for(i=0;i<n;i++) //??????? n? ???????? 
           { 
              if(a[amax]<b[bmax])
              {sum+=200;amax++;bmax++;}  
              else if(a[amax]>b[bmax])
              {sum-=200;amax++;bmin--;}     
              else 
                { 
                     if(a[amin]<b[bmin])
                     {sum+=200;amin--;bmin--;}
                      else if(a[amin]>b[bmin])
                       {sum-=200;bmin--;amax++;}
                      else   //?????? ????????????????? ????? ????????????????? 
                        { 
                            if(a[amax]>b[bmin])
                            {sum-=200;amax++;bmin--;}  //????? ????? ?? ??????? ?????????????? ?? ????????? ?????  ???????  ????????? 
                            else
                            break;
                        } 
          
                 }
          }          
 //??s??????  
   
      
    printf("%d\n",sum);     
    }

return 0; 
}
void paixu(int*p,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;
      }
      getchar();getchar();
}
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 compare(const void* p1,const void*p2)
{
    return (*((int*)p2)-*((int *)p1));
}

int g(int a,int b)
{
    if(a>b)
    return 200;
    else if(a==b)
    return 0;
    else
      return -200;
}

int main()
{
    int n,i,j,tian[1000],qi[1000],re[1001][1001];
    cin>>n;
    while(n!=0)
    {
        if(n==1)
        {
            cin>>tian[0]>>qi[0];
            cout<<g(tian[0],qi[0])<<endl;
        }
        else
        {
        //int *tian=new int[n];
        //int *qi=new int[n];
        for(i=0;i<n;i++)
           cin>>tian[i];
        for(i=0;i<n;i++)
           cin>>qi[i];
        qsort(tian,n,sizeof(int),compare);
        qsort(qi,n,sizeof(int),compare);

       // for(i=0;i<n;i++)
         // cout<<tian[i]<<" "<<qi[i]<<endl;

       // int** re=new int*[n+1];
       // for(i=0;i<n+1;i++)
         //   re[i]=new int[n+1];

        re[1][0]=g(tian[n-1],qi[0]);
        re[1][1]=g(tian[0],qi[0]);
        for(i=2;i<n+1;i++)
        {
            re[i][0]=re[i-1][0]+g(tian[n-i],qi[i-1]);
            for(j=1;j<i;j++)
            {
                if(re[i-1][j-1]+g(tian[j-1],qi[i-1])>re[i-1][j]+g(tian[n-i+j],qi[i-1]))
                    re[i][j]=re[i-1][j-1]+g(tian[j-1],qi[i-1]);
                else
                    re[i][j]=re[i-1][j]+g(tian[n-i+j],qi[i-1]);
            }
            re[i][i]=re[i-1][j-1]+g(tian[i-1],qi[i-1]);
        }

       /* for(i=1;i<n+1;i++)
         for(j=0;j<i+1;j++)
           cout<<re[i][j]<<" ";
           cout<<endl;*/

        for(i=1;i<n+1;i++)
        {
            if(re[n][i]>re[n][0])
              re[n][0]=re[n][i];
        }
        cout<<re[n][0]<<endl;
        //delete []tian;
        //delete []qi;
        //for(i=0;i<n+1;i++)
        //delete []re[i];
        //delete []re;
        }
        cin>>n;
    }
    return 0;
}
int main()
{
    int n,y,z,i,s,t,u,j,k,l,m,win,lose,money;
    int a[1001],b[1001];
//    scanf("%d",&k);
//  for(j=1;j<=k;j++)
  for(;;)
  {
    scanf("%d",&n);
if(n==0) break;
    for(l=0;l<=n-1;l++)
    {
         scanf("%d",&a[l]);
    }
    for(l=0;l<=n-1;l++)
    {
         scanf("%d",&b[l]);
    } 
//??????
    if(n>=2)
    {
         for(y=0;y<=n-2;y++)
         {
              for(z=y+1;z<=n-1;z++)
              {
                   if(a[z]>a[y])
                   {
                        m=a[y];
                        a[y]=a[z];
                        a[z]=m;
                   }
                   if(b[z]>b[y])
                   {
                        m=b[y];
                        b[y]=b[z];
                        b[z]=m;
                   }
              }
         }
    }
//??????
    win=0;
    lose=0;
    if(n>=2)
    {
    for(i=1;i<=n-1;i++)
    {
         if(a[0]>b[0])
         {
              win++;
              for(s=0;s<=n-i-1;s++)
              {
                   a[s]=a[s+1];
                   b[s]=b[s+1];
              }
         }
         else
         {
              for(t=n-i;t>=0;t--)
              {
                   if(a[t]>b[t])
                   {
                        win++;
                        i++;
                        if(n==i)
                        break;
                   }
                   else
                   {
                        if(a[n-i]<b[0])
                        {
                             lose++;
                        }
                        for(u=0;u<=n-i-1;u++)
                        {
                             b[u]=b[u+1];
                        }
                        break;
                   }
              }
         }
    }
    }
    if(a[0]>b[0])
    win++;
    if(a[0]<b[0])
    lose++;
   money=200*(win-lose);
    printf("%d\n",money);
  }
return 0;
}
void paixu(int a[],int n)
{
     int i,j,t;
     for(i=0;i<n-1;i++)
     {
      for(j=i+1;j<n;j++)
      {
       if(a[i]<a[j])
       {
                    t=a[i];
                    a[i]=a[j];
                    a[j]=t;

               }
               }
               }//for(i=0;i<n;i++)printf("%d ",a[i]);printf("\n");
               
 }
long int most(int a[],int b[],int n)
{
    int i,j,v=0,m=0,k,f,p,l=n-1;
    for(i=0;i<n;i++)
     {
       if(b[i]>a[i]) v++;
       else if(b[i]<=a[i])
       {
            for(j=l;j>=i;j--)
            {
              if(b[j]<=a[j]) 
              {
                 l=j;
                 break;
                 }
                 }
            p=b[l];
            for(k=l;k>=i+1;k--)
            {
               b[k]=b[k-1];
               }
            b[i]=p;   
            if(b[i]==a[i]) m++;
            }
            }
            f=n-v-m;
    return(200*(v-f));
}
main()
{
      int n=1,a[1000],b[1000],j,i;
      long int k;
      for(;n!=0;)
      {
           scanf("%d",&n); 
           for(j=0;j<n;j++)
            scanf("%d",&b[j]);
           for(j=0;j<n;j++)
            scanf("%d",&a[j]);
           paixu(a,n);
           paixu(b,n);
           k=most(a,b,n);
           if(n)
           printf("%ld\n",k);
           }
      
      }
main()
{
      int n,i,j,t,c;
      int a[1010],b[1010];
      scanf("%d",&n);
      while (n!=0)
      {     int win=0;
            int lose=0;
            int equal=0;
            for (i=0;i<=n-1;i++)
            {
                scanf("%d",&a[i]);
            }
            for (i=0;i<=n-1;i++)
            {
                scanf("%d",&b[i]);
            }
            for (i=n-2;i>=0;i--)
            {
                for (j=0;j<=i;j++)
                {
                    if (a[j]>a[j+1])
                    {
                                    t=a[j+1];
                                    a[j+1]=a[j];
                                    a[j]=t;
                    }
                }
            }
            for (i=n-2;i>=0;i--)
            {
                for (j=0;j<=i;j++)
                {
                    if (b[j]>b[j+1])
                    {
                                    t=b[j+1];
                                    b[j+1]=b[j];
                                    b[j]=t;
                    }
                }
            }
            
           for (i=0;i<=n-1;i++)
           {
               t=0;
               for (j=0;j<=n-1;j++)
               {   
                   if (b[j]==100000)
                   {
                                continue;
                   }
                   else
                   {
                       if (a[i]-b[j]>0)
                       {
                               t=j;
                       }
                   }
               }
               if (a[i]-b[t]>0)
               {
                       win++;
                       b[t]=100000;
                       a[i]=-2;
               }
           }
           for (i=0;i<=n-1;i++)
           {
             if(a[i]==-2)
             {
                continue;
             }
             else
             {
                 c=0;
                 t=0;
                 for (j=0;j<=n-1;j++)
                 {
                     if (b[j]==100000)
                     {
                                 continue;
                     }
                     else
                     {
                         if(a[i]==b[j])
                         {
                                       a[i]=-2;
                                       b[j]=100000;
                                       equal=equal+1;
                                       break;
                         }               
                     }  
                 }
             }
           } 
              lose=n-win-equal;
              int money;
              money=(win-lose)*200;
              printf("%d\n",money);                
              scanf("%d",&n);
   }
   getchar();getchar();getchar();getchar();getchar();
}
/*
	program: ????
	Author : ??
	ID     : 00948159
	Date   : 2011.3.29
*/


const int MAXN = 1000;
const int PRICE = 200;

int h[2][MAXN];

int main()
{
	int n, i, j, ans, s0, t0, s1, t1;

	while (scanf("%d", &n), n > 0)
	{
		for (i = 0; i < 2; ++i)
		{
			for (j = 0; j < n; ++j)
				scanf("%d", &h[i][j]);
			sort(h[i], h[i] + n);
		}

		ans = 0;
		s0 = 0;
		s1 = 0;
		t0 = n - 1;
		t1 = n - 1;
		while (s0 <= t0)
		{
			while (s0 <= t0 && h[0][s0] > h[1][s1])
			{
				ans += PRICE;
				++s0;
				++s1;
			}
			while (s0 <= t0 && h[0][t0] > h[1][t1])
			{
				ans += PRICE;
				--t0;
				--t1;
			}
			if (s0 <= t0)
			{
				if (h[0][s0] == h[1][t1])
					break;
				ans -= PRICE;
				++s0;
				--t1;
			}
		}

		printf("%d\n", ans);
	}

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

void Input(int house[],int n)
{
	int i;
	for(i=0;i<n;i++)
		{
			scanf("%d",&house[i]);
		}
}

main()
{
	int n,i,j,tianji[1000],qiwang[1000],money=0,fast=0,slowt,slowq,st,sq;
	for(i=0;1;i++)
	{
		scanf("%d",&n);
		if(n==0)
		{
			return 0;
		}else{
			Input(tianji,n);
			Order(tianji,n);
			Input(qiwang,n);
			Order(qiwang,n);
			money=0;
			fast=0;
			slowt=n-1;
			slowq=n-1;
			for(j=0;j<n;j++)
			{
				if(tianji[fast]>qiwang[j])
				{
					money++;
					fast++;
				}else if(tianji[fast]<qiwang[j]){
					money--;
					slowt--;
				}else if(tianji[fast]==qiwang[j]){
					for(st=slowt,sq=slowq;st>fast;st--,sq--)
					{
						if(tianji[st]>qiwang[sq])
						{
							money++;
							slowt--;
							slowq--;
							n--;
						}else if(tianji[st]<=qiwang[sq]){
							if(tianji[st]<qiwang[j])
							{
								money--;
								slowt=st-1;
								slowq=sq;
								break;
							}else{
								slowt=st-1;
								slowq=sq;
							}
						}
					}
				}
				if(fast>slowt)
				{
					break;
				}
			}
			printf("%d\n",money*200);
		}
	}
	return 0;
}
int cmp(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];
    scanf("%d",&n);
    while (n!=0)
    {
          for (i=0;i<n;i++)
                scanf("%d",&t[i]);
          for (i=0;i<n;i++)
                scanf("%d",&q[i]);
          qsort(t,n,sizeof(t[0]),cmp);
          qsort(q,n,sizeof(q[0]),cmp);
          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;
          }
          printf("%d\n",s);
          scanf("%d",&n);
    }
    return 0;
}
void swap(int* x, int* y)
{
	int z;
	z = *x;
	*x = *y;
	*y = z;
}

int main(void)
{
	int n, ts, qs, te, qe, i, j, ans;
	int t[1005], q[1005];

	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]);
		for (i = 1; i < n; i++)
			for (j = 0; j < i; j++) {
				if (t[i] > t[j]) swap(&t[i], &t[j]);
				if (q[i] > q[j]) swap(&q[i], &q[j]);
			}
		ts = qs = 0;
		te = qe = n-1;
		ans = 0;
		for (i = 0; i < n; i++) {
			if (t[te] > q[qe]) {
				ans++;
				te--;
				qe--;
			}
			else if(t[te] < q[qe]) {
				ans--;
				te--;
				qs++;
			}
			else {
				if (t[ts] > q[qs]) {
					ans++;
					ts++;
					qs++;
				}
				else if (t[ts] < q[qs]) {
					ans--;
					te--;
					qs++;
				}
				else {
					if (q[qs] > t[te]) ans--;
					qs++;
					te--;
				}
			}
		}
		printf("%d\n", ans*200);
	}
		return 0;	
}
int ans = 0;
int n;
int horses1[1001], horses2[1001];
void cal ()
{
	int pos;
	if (horses1[n -1] == -1) return;
	for (int i = 0 ; i < n ; i ++)
	{
		if (horses1[i] != -1)
		{
			pos = i;
			break;
		}
	}
	if (horses1[pos] > horses2[pos])
	{
		ans += 200;
		horses1[pos] = -1;
		horses2[pos] = -1;
		cal ();
		return;
	}
	if (horses1[pos] < horses2[pos])
	{
		ans -= 200;
		horses1[pos] = -1;
		for (int i = n - 1 ; i >= 1 ; i --)
			horses2[i] = horses2[i - 1];
		horses2[0] = -1;
		cal ();
		return;
	}
	if (horses1[n - 1] > horses2[n - 1])
	{
		ans += 200;
		for (int i = n - 1 ; i >= 1 ; i --)
			horses1[i] = horses1[i - 1];
		horses1[0] = -1;
		for (int i = n - 1 ; i >= 1 ; i --)
			horses2[i] = horses2[i - 1];
		horses2[0] = -1;
		cal ();
		return;
	}
	if (horses1[n - 1] < horses2[n - 1])
	{
		ans -= 200;
		horses1[pos] = -1;
		for (int i = n - 1 ; i >= 1 ; i --)
			horses2[i] = horses2[i - 1];
		horses2[0] = -1;
		cal ();
		return;
	}
	if (horses1[n - 1] == horses2[n - 1])
	{
		if (horses1[pos] < horses2[n - 1])
			ans -= 200;
		horses1[pos] = -1;
		for (int i = n - 1 ; i >= 1 ; i --)
			horses2[i] = horses2[i - 1];
		horses2[0] = -1;
		cal ();
		return;
	}
}
int main ()
{
	while (1)
	{
		cin >> n;
		if (n == 0) break;
		for (int i = 0 ; i < n ; i ++)
			cin >> horses1[i];
		for (int i = 0 ; i < n ; i ++)
			cin >> horses2[i];
		sort (horses1, horses1 + n);
		sort (horses2, horses2 + n);
		cal ();
		cout << ans << endl;
		ans = 0;
		/*
		for (int i = 0 ; i < n ; i ++)
			cout << horses1[i] << ' ';
		cout << endl;
		for (int i = 0 ; i < n ; i ++)
			cout << horses2[i] << ' ';
		cout << endl;
		*/
	}
	return 0;
}
int cmp(const void *a,const void *b)
{
    int x,y;
    x=*(int *)a;
    y=*(int *)b;
   return y-x;
}
int main()
{
    int i,j,k,s,x,n,t[1000],q[1000];
    scanf("%d",&n);
    while (n!=0)
    {
          for (i=0;i<n;i++)
                scanf("%d",&t[i]);
          for (i=0;i<n;i++)
                scanf("%d",&q[i]);
          qsort(t,n,sizeof(t[0]),cmp);
          qsort(q,n,sizeof(q[0]),cmp);

          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;
			  }
          printf("%d\n",s);
          scanf("%d",&n);
    }
    return 0;
}
main()
{
    int n;
    for(;;)
    {
        scanf("%d",&n);
        if(n==0)
            break;
        else
        {
            int i,j,k,lose=0,win=0,a1,a2,b1,b2,a[2000]={0},b[2000]={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=i+1;j<n;j++)
                {
                    if(a[i]>a[j])
                        k=a[i],a[i]=a[j],a[j]=k;
                    if(b[i]>b[j])
                        k=b[i],b[i]=b[j],b[j]=k;
                }
            }
            for(a1=0,a2=n-1,b1=0,b2=n-1;a1<=a2;)
            {
                if(a[a1]>b[b1])
                    a1++,b1++,win++;
                else
                {
                    if(a[a1]<b[b1])
                        a1++,b2--,lose++;
                    else
                    {
                        if(a[a2]>b[b2])
                            a2--,b2--,win++;
                        else
                        {
                            if(a[a2]<b[b2])
                                a1++,b2--,lose++;
                            else
                            {
                                if(a[a1]==a[a2])
                                    a1++,b1++;
                                else
                                    a1++,b2--,lose++;
                            }
                        }
                    }
                }
            }
            k=200*win-200*lose;
            printf("%d\n",k);
        }
    }
   
}