semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
void h(int x[],int y)
{   int i,j,t;
  for(i=1;i<y;i++)
     for(j=y;j>i;j--)
     if(x[j]>x[j-1])
   {     t=x[j-1];
         x[j-1]=x[j];
         x[j]=t;     }
}
   
int c(int a[],int b[],int m)  
{     int i; int j;
      if(a[m]>b[m])
       return (1);
       if(a[m]<b[m])
       {   for(i=1;i<=m-1;i++)
           b[i]=b[i+1];
           return (-1);   
        }   
       if(a[m]==b[m]&&a[1]>b[1])
       {      for(i=1;i<=m-1;i++)
              { b[i]=b[i+1];
                a[i]=a[i+1]; }
            return (1);            }
       if(a[m]==b[m]&&a[1]<b[1])
        {  for(i=1;i<=m-1;i++)
               b[i]=b[i+1];
               return (-1);        }
       if(a[m]==b[m]&&a[1]==b[1])
     {        
           if(a[m]==b[1])    
             j=0;
             if(a[m]<b[1])   
             j=-1;
              for(i=1;i<=m-1;i++)
              b[i]=b[i+1]; 
             return (j);
             }        
    }         
main()
{ int n,l,i,j,t;
  int a[10000];
  int b[10000];
for(;;)
{  scanf("%d",&n);
   if(n==0) break;
  
  for(i=1;i<=n;i++)
  scanf("%d",&a[i]);
  for(i=1;i<=n;i++)
  scanf("%d",&b[i]);
  l=n;t=0;
  h(a,l);h(b,l);
 
  for(i=1;i<=n;i++)
{
     t=t+c(a,b,l);            
       l--;
                   }  
    t=t*200;
    printf("%d\n",t);
}


      }
int cmp(const void *a,const void *b)
{
 return *(int *)a < *(int *)b ? 1 : -1; 
}
int main()
{
 int n,m;
 int i,j,tian[1005],king[1005];
 int tmax,kmax,tmin,kmin;
 while(cin>>n,n)
 {
  for(i=1;i<=n;i++)
   cin>>tian[i];
  qsort(tian+1,n,sizeof(tian[0]),cmp);
  for(j=1;j<=n;j++)
   cin>>king[j];
  qsort(king+1,n,sizeof(king[0]),cmp);
  int cnt = 0;
  tmax = 1;
  tmin = n;
  kmax = 1;
  kmin = n;
  for (i = 1; i <= n; i++)
  {
   if(tian[tmax] > king[kmax])
   {
    cnt++;
    tmax++;
    kmax++;
   }
   else if(tian[tmax] < king[kmax])
   {
    cnt--;
    tmin--;
    kmax++;
   }
   else
   {
                if(tian[tmin] > king[kmin])
    {
     cnt++;
     tmin--;
     kmin--;
    }
    else if(tian[tmin] <king[kmin])
    {
     cnt--;
     tmin--;
     kmax++;
    }
    else
    {
     if(tian[tmin] < king[kmax])
     {
      cnt--;
      tmin--;
      kmax++;
     }
     
    }
   }
   
  }
    cout<<cnt*200<<endl;
 }
 return 0;
}
int mycomp(const void *e1,const void *e2)
{
	int *p1=(int*)e1,*p2=(int*)e2;
	return p1[0]-p2[0];
}

int x[1001],y[1001];

int main()
{
	int n;
	while (scanf("%d",&n),n)
	{
		for (int i=0;i<n;i++)
			scanf("%d",x+i);
		qsort(x,n,sizeof(int),mycomp);
		for (int i=0;i<n;i++)
			scanf("%d",y+i);
		qsort(y,n,sizeof(int),mycomp);
		int ans=0;
		int hx,hy,tx,ty;
		hx=hy=0;
		tx=ty=n-1;
		while (hx<=tx)
		{
			if (x[hx]>y[hy])
			{
				++ans;
				++hx;
				++hy;
				continue;
			}
			if (x[tx]>y[ty])
			{
				++ans;
				--tx;
				--ty;
				continue;
			}
			if (x[hx]<y[ty])
				--ans;
			else
				if (x[hx]>y[ty]) ++ans;
			++hx;
			--ty;
		}
		printf("%d\n",ans*200);
	}
	return 0;
}
int cmp(const void *a,const void *b)
{
  if(*((int*)a)>*((int*)b))return -1;
  else if(*((int*)a)<*((int*)b))return 1;
  else return 0;
}
int main()
{
  int n,a[1000],b[1000],i,j,k,sum,s1,s2,i1,i2;
  scanf("%d",&n);
  while(n)
  {
    sum=0;
    for(i=0;i<n;i++)scanf("%d",&a[i]);
    for(i=0;i<n;i++)scanf("%d",&b[i]);
    qsort(a,n,sizeof(a[0]),cmp);
    qsort(b,n,sizeof(b[0]),cmp);
    i1=i2=n-1;
    s1=s2=0;
    while(s1<=i1)
    {
      while(a[i1]!=b[i2]&&s1<=i1)
      {
        if(a[i1]>b[i2])
        {
          sum++;
          i1--;
          i2--;
        }
        else
        {
          sum--;
          i1--;
          s2++;
        }
      }
      if(s1>i1)break;
      while(a[s1]!=b[s2]&&s1<=i1)
      {
        if(a[s1]>b[s2])
        {
          sum++;
          s1++;
          s2++;
        }
        else
        {
          sum--;
          i1--;
          s2++;
        }
      }
      if(s1>i1)break;
      if(a[s1]==b[s2]&&a[i1]==b[i2])
      {
        if(a[i1]>b[s2])sum++;
        else if(a[i1]<b[s2])sum--;
        i1--;
        s2++;
      }
      if(s1>i1)break;
    }
    printf("%d\n",sum*200);
    scanf("%d",&n);
 }
 return 0;
}
int win(int x,int w[],int p[])
 {    
      int i,topw=0,topp=0,downw=x-1,downp=x-1;
      int j,convert,converts;
      int win=0,same=0,fail=0;
        for (i=0;i<x;i++)
           for (j=0;j<x-i-1;j++)
      {
                if (w[j]<w[j+1])
              {
                   convert=w[j];
                   w[j]=w[j+1];
                   w[j+1]=convert;      
               }
      
               if (p[j]<p[j+1])
                 {
                   converts=p[j];
                   p[j]=p[j+1];
                   p[j+1]=converts;      
                  }
      } 
     /* for (i=0;i<x;i++)
      printf ("%d %d\n",w[i],p[i]);*/
          for (i=0;i<x;i++)
           {
              if (w[downw]>p[downp])
               {
                  win++;
                  downw--;
                  downp--;
               }
              else 
                 if (w[downw]<p[downp])
                   {
                       fail++;
                       downw--;
                       topp++;
                       } 
                  else 
                    if (w[topw]>p[topp])
                     {
                        win++;
                        topw++;
                        topp++;
                        }
                    else
                    if(w[downw]==p[topp])
                    break;
                    else
                   {  
                     fail++;
                     topp++;
                     downw--;
                   }    
           }
          /* printf ("%d %d\n",win,fail);*/
           return (200*(win-fail));
      }            

main ()
{
  int n,i,j,k,get;
  scanf ("%d",&n);
  while (1)
  {    
       if (n==0)
       break;
       else
       {    
            int a[n];
            int b[n];
            for (i=0;i<n;i++) 
            scanf ("%d",&a[i]);
            for (i=0;i<n;i++)
            scanf ("%d",&b[i]); 
        get=win(n,a,b);
        printf("%d\n",get);
        }
        scanf ("%d",&n);
     }
     getchar ();
     getchar ();
}
void p(int masu[],int n)
{
     int i,j,t;
     for(i=1;i<=n;i++)
     {
         for(j=n-1;j>=i;j--)
         {
             if(masu[j-1]>masu[j])
             {
                t=masu[j-1];
                masu[j-1]=masu[j];
                masu[j]=t;                     
             }                  
         }                
     }
}
main()
{
      for(;;)
      {
          int n,a[1100],b[1100],i,j,sub=0,x,y,k;
          scanf("%d",&n);
          if(n==0) {break;}
          else
          { 
               for(i=0;i<n;i++)
                   scanf("%d",&a[i]);
               for(i=0;i<n;i++)
                   scanf("%d",&b[i]);
               p(a,n),p(b,n);
               x=n-1,y=n-1,i=0,j=0;
               for(;;)
               {
                   
                      if(a[i]>b[j]) {sub=sub+1;i=i+1;j=j+1;}
                      else if(a[i]==b[j])
                      {
                           if(a[x]<=b[y])
                           {
                           if (a[i]<b[y]){sub=sub-1;}
                           i++;y--;
                           }
                           else {sub=sub+1,x=x-1,y=y-1;}             
                      }
                      else if(a[i]<b[j])
                      {
                          i=i+1;
                          y=y-1;
                          sub=sub-1;            
                      }
                      if (i>x)break;
               }
               printf("%d\n",200*sub);
          } 
      }

}
int max(int a,int b)
{
	return (a>b?a:b);
}
int cmp(const void *a,const void *b)
{
	return (*(int *)b - *(int *)a);
}
int g(int i,int j,int general[],int king[])
{
	if(general[i-1] > king[j-1])	
		return 200;
	else if(general[i-1] < king[j-1])
		return -200;		
	else				
		return 0;
}

int f[2000][2000];
int main()
{
	int n;
	while(cin >> n)
	{
		if(n == 0)
			break;
		int i,j;
		int king[1002];//??
		int general[1002];//??
		for(i = 0;i < n;i++)
			cin >> general[i];
		for(i = 0;i < n;i++)
			cin >> king[i];
		
		qsort(general,n,sizeof(general[0]),cmp);
		qsort(king,n,sizeof(king[0]),cmp);
		
/*??????*/
		for(i = 0;i <= n;i++)
			f[0][i] = 0;
		for(i = 1;i <= n;i++)
			f[i][0] = f[i-1][0] + g(n+1-i,i,general,king);
//DP
		for(i = 1;i <= n;i++)
			for(j = 1;j <= i;j++)
			{
				if(i == j)
					f[i][j] = f[i-1][j-1] + g(j,i,general,king);
				else
					f[i][j] = max(f[i-1][j]+g(n-(i-j)+1,i,general,king),f[i-1][j-1]+g(j,i,general,king));
			} 
		int temp = -200000000;
		for(i = 0;i <= n;i++)
			temp = max(temp,f[n][i]);

		cout << temp << endl;
	}
	return 0;
}
int main(int argc, char* argv[])
{
	int n;
	while(1)
	{
		scanf("%d",&n);
		if(n==0){
			break;
		}else{
			int qiwang[1000];
			int tianji[1000];
			int win[1000];
			int i,k;
			for(i=0;i<n;i++){
				scanf("%d",&tianji[i]);
			}
			for(i=0;i<n;i++){
				scanf("%d",&qiwang[i]);
			}
			int e;
			for(k=1;k<n;k++){
				for(i=0;i<n-k;i++){
					if(qiwang[i]<qiwang[i+1]){
						e=qiwang[i];
						qiwang[i]=qiwang[i+1];
						qiwang[i+1]=e;
					}
				}
			}
			for(k=1;k<n;k++){
				for(i=0;i<n-k;i++){
					if(tianji[i]<tianji[i+1]){
						e=tianji[i];
						tianji[i]=tianji[i+1];
						tianji[i+1]=e;
					}
				}
			}
			int get=0,j;
			int tianji1[1000];
			for(k=0;k<n;k++){
				for(i=0;i<n;i++){
					j=(i+k)%n;
					tianji1[i]=tianji[j];
				}
				for(i=0;i<n;i++){
					if(tianji1[i]>qiwang[i]){
						get=get+200;
					}else if(tianji1[i]<qiwang[i]){
						get=get-200;
					}
				}
				win[k]=get;
				get=0;
			}
			int max=win[0];
			for(i=0;i<n;i++){
				if(win[i]>max){
					max=win[i];
				}
			}
			printf("%d\n",max);
		}
	}
	return 0;
}
int compare(const void * p1, const void * p2) // ?????????
{
	return *((int *)p2) - * ((int *)p1);
};
int main()
{
	int n;
	int hq[10002]; // ??????
	int ht[10002]; // ??????
	int i, j, head, ans, m;
	int tailt, tailq;
	while (1)
	{
		cin >> n;
		if (n == 0)
			break;
		for (i = 0; i < n; i++)
		{
			cin >> ht[i];
		}
		qsort(ht, n, sizeof(int), compare);
		for (i = 0; i < n; i++)
		{
			cin >> hq[i];
		}
		qsort(hq, n, sizeof(int), compare);
		head = 0;
		tailt = tailq = n - 1;
		ans = 0;
		for(i=0;i<n;i++)
        {
            if(ht[head]>hq[i])
            {
                head++;
                ans+=200;
            }
            else if(ht[head]<hq[i])
            {
                tailt--;
                ans-=200;
            }
            else if(ht[head]==hq[i])
            {
                for(j=tailt,m=tailq;j>=head;j--,m--)
                {
                    if(ht[j]>hq[m])
                    {
                        ans+=200;
                        tailt--;
                        tailq--;
                    }
                    else
					{
						if(ht[j]<hq[i]) ans-=200;
						tailt=--j;
						tailq=m;
						break;               
					}
                }
            }
			
            if(head>tailt) break;
        }
		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(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);

		
	}
}
/*
 * PG-HorseRace.cpp
 *
 *  Created on: 2011-3-31
 *      Author: lyh
 */
int Cmp(const void * p1, const void * p2)
{
	int * C1 = (int *)p1;
	int * C2 = (int *)p2;
	return *C2 - *C1;
}
int main()
{
	int TianJi[1005];
	int QiKing[1005];
	int nHorses;
	int silver;
	while(cin >> nHorses && nHorses)
	{
		silver = 0;
		for(int i = 0; i < nHorses; i ++)
			cin >> TianJi[i];
		qsort(TianJi, nHorses, sizeof(TianJi[0]), Cmp);
		for(int i = 0; i < nHorses; i ++)
			cin >> QiKing[i];
		qsort(QiKing, nHorses, sizeof(QiKing[0]), Cmp);
		int Head = 0;
		int Tail = nHorses - 1;
		for(int i = 0; i < nHorses; i ++)
		{
			if(TianJi[Head] > QiKing[i])
			{
				Head ++;
				silver += 200;
				continue;
			}
			if(TianJi[Head] < QiKing[i])
			{
				Tail --;
				silver -= 200;
				continue;
			}
			if(i == nHorses - 1) break;
			int sum1 = 0;
			int sum2 = -200;
			for(int j = i + 1; j < nHorses; j ++)
			{
				if(TianJi[Head + j - i] > QiKing[j])sum1 += 200;
				else
				if(TianJi[Head + j - i] < QiKing[j])sum1 -= 200;

				if(TianJi[Head + j - i - 1] > QiKing[j]) sum2 += 200;
				else
				if(TianJi[Head + j - i - 1] < QiKing[j]) sum2 -= 200;
			}
			if(sum1 > sum2)
			{
				Head ++;
				continue;
			}
			else
			{
				Tail --;
				silver -= 200;
			}
		}
		cout << silver << endl;
	}
}
int t[1000],q[1000];
int MyCompare(const void *e1,const void *e2)
{
	return *(int *)e2 - *(int *)e1;
}
int main()
{
	int n,i,tFirst,tLast,qFirst,qLast,ans;
	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),MyCompare);
		qsort(q,n,sizeof(int),MyCompare);
		tFirst = qFirst = 0;
		tLast = qLast = n - 1;
		ans = 0;
		while(tFirst <= tLast)
		{
			if(t[tLast] > q[qLast])
			{
				tLast --;
				qLast --;
				ans += 200;
			}
			else if(t[tLast] < q[qLast])
			{
				tLast --;
				qFirst ++;
				ans -= 200;
			}
			else
			{
				if(t[tFirst] > q[qFirst])
				{
					tFirst ++;
					qFirst ++;
					ans += 200;
				}
				else if(t[tFirst] < q[qFirst])
				{
					tLast --;
					qFirst ++;
					ans -= 200;
				}
				else
				{
					if(t[tLast] > q[qFirst])
					{
						tLast --;
						qFirst ++;
						ans += 200;
					}
					else if(t[tLast] < q[qFirst])
					{
						tLast --;
						qFirst ++;
						ans -= 200;
					}
					else
					{
						tLast --;
						qFirst ++;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}
int T[1005]={0};
	int Q[1005]={0};
	int Save[1005][1005]={0};
int main()
{

	int Num=0;
	int i=0;
	int Temp1=0;
	int Temp2=0;
	
	int j=0;
	int Ans=-1000000;

	while(cin>>Num && Num!=0)
	{
		Ans=-2000000;
		memset(Save,0,sizeof(Save));
		memset(T,0,sizeof(T));
		memset(Q,0,sizeof(Q));

	for (i=1;i<=Num;i++)
	{
		cin>>T[i];
	}
	for (i=1;i<=Num;i++)
	{
		cin>>Q[i];
	}

	sort(T+1,T+Num+1);
	sort(Q+1,Q+Num+1);

	reverse(T+1,T+Num+1);
	reverse(Q+1,Q+Num+1);
	

	for (i=1;i<=Num;i++)
	{
		j=0;
		Temp1=Save[i-1][j];

		if ( T[Num-(i-1-j)] - Q[i] <0)
		{
			Temp1-=200;
		}
		if ( T[Num-(i-1-j)] - Q[i] >0)
		{
			Temp1+=200;
		}

			Save[i][j]=Temp1;


	//	cout<<"("<<i<<","<<j<<")-"<<Save[i][j]<<endl;
		for (j=1;j<=i;j++)
		{
			Temp1=Save[i-1][j];
			Temp2=Save[i-1][j-1];
			if ( T[Num-(i-1-j)] - Q[i] <0)
			{
				Temp1-=200;
			}
			if ( T[Num-(i-1-j)] - Q[i] >0)
			{
				Temp1+=200;
			}
			if ( T[j] - Q[i] < 0)
			{
				Temp2-=200;
			}
			if ( T[j] - Q[i] > 0)
			{
				Temp2+=200;
			}

			if (i<=j)
			{
				Temp1=-2000000;
			}
			if (Temp1> Temp2)
			{
				Save[i][j]=Temp1;
			}
			else
			{
				Save[i][j]=Temp2;
			}
		//			cout<<"("<<i<<","<<j<<")-"<<Save[i][j]<<endl;
		}
	}

	for (i=1;i<=Num;i++)
	{
		if ( Save[Num][i]> Ans)
		{
			Ans=Save[Num][i];
		}
	}
		
	cout<<Ans<<endl;
	}
	return 0;
}
int pfCompare(void const *elem1, void const *elem2)
{
    return *(int*)elem2 -*(int*)elem1;
}
int main()
{
	while(1)
	{
		int n;
		scanf("%d",&n);
		if(0 == n)
			break;
		else
		{
			int m = 0,p = 0,q = 0;
			int *a = (int *)malloc(n* sizeof(int));
			int *b = (int *)malloc(n* sizeof(int));
			int i = 0;
			while(i<n)
			{
				scanf("%d",&a[i]);
				i++;
			}
			i = 0;
			while(i<n)
			{
				scanf("%d",&b[i]);
				i++;
			}
			qsort(a,n,sizeof(int),pfCompare);
			qsort(b,n,sizeof(int),pfCompare);
			i = 0;
			while(i<n)
			{
				if(a[i]>b[i])
				{
					m++;
				}
				else if(a[i]<b[i])
				{
					while(a[n-1]>b[n-1])
					{
						m++;
						n--;
					}
					
						p++;
					q = n-1;
					while(q>i)
					{
						a[q] = a[q-1];
						q--;
					}
				}
				else
				{
						while(a[n-1]>b[n-1])
					{
						m++;
						n--;
					}
						if(a[i]!=a[n-1])
			         {
				    q = n-1;
					while(q>i)
					{
						a[q] = a[q-1];
						q--;
					}
					p++;
						}
						else 
						break;
				}
			i++;
			}
			int l = 200 * m - 200 * p;
			printf("%d\n",l);
		}

	}
	return 0;
}
int f(int n,int t[2000],int q[2000])
{
    int m=0,i=0; 
    for(i=n;i!=1;i--) 
    {
           if(t[0]>q[0])               
           {
               m=m+200;
               for(int k=0;k<i-1;k++) 
               {
                       t[k]=t[k+1];
                       q[k]=q[k+1];
               }
           }
           else
           { 
              if (t[0]<q[0])              
              {
                     m=m-200;
                 for(int k=0;k<i-1;k++) 
                 {
                       q[k]=q[k+1];
                 } 
              } 
              else
              {
                  if(t[i-1]>q[i-1])           
                  {
                         m=m+200;
                  }
                  else                                              
                 {

                   if(t[i-1]<q[0])
                         m=m-200;
					  else
						  m=m;
                         for(int k=0;k<i-1;k++)     
                         {
                              q[k]=q[k+1];
                         }

                  } 
               }
              } 
          
    }
    if (t[0]<q[0])                 
    {
        m=m-200; 
    }
    else 
    {
         if (t[0]>q[0])
         {
               m=m+200; 
         }
         else
         m=m; 
    }
    return m;
}
int main()
{
    int n=2,t[2000],q[2000];
    for(int k=0;n!=0;k++) 
    {
        scanf("%d",&n);
        if(n!=0)
		{
                for(int i=0;i<n;i++)
				{
                        scanf("%d",&t[i]);
                }
                for(int i=0;i<n;i++) 
				{
                        scanf("%d",&q[i]);
                }

                for(int i=0;i<n;i++)                       
                {
                         for(int j=0;j<n-i-1;j++)
                         {
                             if(t[j]<t[j+1])
                             {
                                     int s;
                                         s=t[j];
                                      t[j]=t[j+1];
                                     t[j+1]=s;
                             }
                         }
                 }
                for(int i=0;i<n;i++)                         
                {
                         for(int j=0;j<n-i-1;j++)
                         {
                             if(q[j]<q[j+1])
                             {
                                     int s;
                                         s=q[j];
                                      q[j]=q[j+1];
                                     q[j+1]=s;
                             }
                         }
                 }
				if(k==0)
                printf("%d",f(n,t,q));
				else
                printf("\n%d",f(n,t,q));
        } 
    }
    getchar();
    getchar();
}
int s(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}
main ()
{
	int n;
	do
	{
	 int a[1000],b[1000];
	 scanf ("%d",&n);
	 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),s);
	 qsort(b,n,sizeof(int),s);
	 int t1=n-1,t2=0,k1=n-1,k2=0,sum=0,sum1=0;
	 if (n!=0)
	 {do {
	     if (a[t1]==b[k1]&&a[t2]==b[k2])
	     	{if (a[t2]<b[k1])
		  	sum--;
		  	else if(a[t2]>b[t1])
		  	sum++;
		  	t2++;k1--;sum1++;}
	     else if (a[t2]!=b[k2])
	      {if (a[t2]>b[k2])
		  {sum++;t2++;k2++;sum1++;}
		  else 
		  {if (a[t2]>b[k1])
		   sum++;
		   else if(a[t2]<b[k1])
		   sum--;
		   t2++;k1--;sum1++;}
		 }
	     else
	     	    {
				 if (a[t1]>b[k1])
		  		  {sum++;t1--;k1--;}
		  	     else 
		  		  {if (a[t2]<b[k1])
				  sum--;
				  else if(a[t2]>b[k1])
				  sum++;
				 t2++;
				 k1--;}
		         sum1++;}
		}while(sum1!=n);
	 printf ("%d\n",200*sum);}
	 }while(n!=0);
}
int h1[1000]; //horses belongs to tianji
int h2[1000]; //horses belongs to qiwang

void Sort(int h[],int n)  //sort the horse 
{
   //QuickSort(h,0,n-1);
   InsertSort(h,n);
}


void InsertSort(int A[],int n)
{
    int i,j,key;
    for(j=1;j<n;j++)
    {
       key=A[j];
       //A[ j ] is added in the sorted sequence A[1, .. j-1]
       i = j - 1;
       while( i >= 0 && A [i] > key )
       {
         A[i+1]=A[i];
         i=i-1;
       }
       A[i+1]=key;
    }
}


void QuickSort(int array[],int left,int right)
{
   int pivot,leftIdx=left,rightIdx=right,temp;
   if( right - left > 0 ) 
      pivot = (left + right) / 2;
   while(leftIdx <= pivot && rightIdx >= pivot)
   {
             while( array[leftIdx] < array[pivot] && leftIdx <= pivot )
                 leftIdx = leftIdx + 1;
             while( array[rightIdx] > array[pivot] && rightIdx >= pivot )
                 rightIdx = rightIdx - 1;
             temp = array[leftIdx];
             array[leftIdx] = array[rightIdx];
             array[rightIdx] = temp;
             leftIdx = leftIdx + 1;
             rightIdx = rightIdx - 1;
             if(leftIdx - 1 == pivot)
             {
                 pivot =  rightIdx + 1;
                 rightIdx = rightIdx + 1;
             }
             else if (rightIdx + 1 == pivot)
             {
                 pivot = leftIdx - 1;
                 leftIdx = leftIdx - 1;
             } 
    }
         QuickSort(array, left, pivot - 1);
         QuickSort(array, pivot + 1, right); 
}

// return the money tianji can win
int Race(int n)
{
	int i,Nwin=0;
	int begin1,end1; //identify the horse
	int begin2,end2;
        begin1=n-1; begin2=n-1;
	end1=0; end2=0;
        Sort(h1,n);
        Sort(h2,n);  
	for(i=0;i<n;i++) //n times
	{
           if ( h1[begin1]>h2[begin2] ) //tianji's horse better than qiwang's 
	   {
		   //tianji win 1 race
	           Nwin++;
		   begin2--;
                   begin1--;		   
	   }
	   else if( h1[end1]>h2[end2] ) //tianji's horse better than qiwang's 
	   {
                   Nwin++;
                   end1++;
		   end2++;
	   }
           else
           {
              if( h1[end1]<h2[begin2] ) //tianji lose 1 race
                Nwin--;
              begin2--;
              end1++;   
           }
	}
	return Nwin*200;
}

void ParseHorse(int n)
{
	int i;
	for(i=n-1;i>=0;i--)
	{
		scanf("%d",&(h1[i]));
	}
    for(i=n-1;i>=0;i--)
	{
		scanf("%d",&(h2[i]));
	}
}
int main()
{
	int i,n=0;
	int result[50000];
	scanf("%d",&i);
    while(i)
	{
		ParseHorse(i);
		result[n]=Race(i);
		n++;
		scanf("%d",&i);
	}
    for(i=0;i<n;i++)
	{ 
		printf("%d",result[i]);
		if(i!=n-1)
		  printf("\n");
	}

	return 0;
}