int compare (const void *a,const void *b)
{   return *(int*)b-*(int*)a;;
    }
int main ()
{   int n,k1,k2,m1,m2,win,i,w;
     int c[10000];
    for (;;)
    {   scanf ("%d",&n);
        if (n==0)
        break;
        int *a;
        a=(int *)malloc (sizeof(int*)*n);
        for (i=0;i<n;i++)
        scanf ("%d",&a[i]);
        int *b;
        b=(int *)malloc (sizeof(int*)*n);
        for (i=0;i<n;i++)
        scanf ("%d",&b[i]);
        qsort(a,n,sizeof(int),compare);
        qsort(b,n,sizeof(int),compare);
        win=0;
        k1=0;
        k2=0;
        m1=n-1;
        m2=n-1;
        while (k1<=m1)
        {if (a[m1]>b[m2])
          {win++;
           m1--;
           m2--;}
         else if (a[k1]>b[k2])
         {win++;
          k1++;
          k2++;}
         else if (a[m1]<b[k2])
                {win--;
           m1--;
           k2++;}
         else
                 break;
                    }
         printf ("%d\n",200*win);
         }

        }


int comp(const void * elem1, const void * elem2)
{
	if(*(int*)elem1<*(int*)elem2)
		return 1;
	if(*(int*)elem1>*(int*)elem2)
		return -1;
	if(*(int*)elem1==*(int*)elem2)
		return 0;
}
main()
{
      int i,j,n;
      for(i=0;;i++)
      {
        scanf("%d",&n);
        if(n==0)
        break;
        int *tj = (int *)malloc(n*sizeof(int));
        int *qww= (int *)malloc(n*sizeof(int));
        for(j=0;j<n;j++)
        scanf("%d",&tj[j]);
       	qsort(tj,n,sizeof(int),comp);
        for(j=0;j<n;j++)
        scanf("%d",&qww[j]);
       	qsort(qww,n,sizeof(int),comp);
       j = 0;
        int s = 0;
       int  k = n-1;
        for(i = 0; i < n && j <= k;){
            if(tj[j] < qww[i]){
                s--;
                k--;
                i++;
            }
            else if(tj[j] == qww[i] ){
                if(tj[k] < qww[n-1]){
                    s--;
                    i++;
                    k--;
                }
                else if(tj[k] > qww[n-1]){
                    s++;
                    n--;
                    k--;
                }
                else if(tj[k] == qww[n-1]){
                    if(tj[k] != qww[i]){
                        s--;
                        i++;
                        k--;
                    }
                    else break;
                }
            }
            else{
                s++;
                i++;
                j++;
            }
        }
        printf("%d\n", s*200);
        free(tj);
        free(qww);
      }
}


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

int main()
{
	int a[1001];
	int b[1001];
	int n, i, total;
	while(cin >> n)
	{
		total = 0;
		if(n == 0) break;
		for(i = 0; i < n; i ++) scanf("%d", &b[i]);
		for(i = 0; i < n; i ++) scanf("%d", &a[i]);
		qsort(a, n, sizeof(int), mycompare);
		qsort(b, n, sizeof(int), mycompare);
		int p1 = 0, p2 = n - 1, p3 = 0, p4 = n - 1;
		while(p1 <= p2)
		{
			if(a[p1] < b[p3])
			{
				p1 ++;
				p3 ++;
				total += 200;
			}
			else if(a[p2] < b[p4])
			{
				p2 --;
				p4 --;
				total += 200;
			}
			else
			{
				if(a[p1] > b[p4]) total -= 200;
				p1 ++;
				p4 --;
			}
		}
		cout << total << endl;
	}
	return 0;
}


void bubble(int a[],int n)
{
     int pass,hold,j;
     for(pass=1;pass<=n-1;pass++)
     for(j=0;j<=n-2;j++)
     if(a[j]<a[j+1])
     {
              hold=a[j];
              a[j]=a[j+1];
              a[j+1]=hold;
     }
}
int compare(const void*a1,const void*a2)
{
    int i;
    return (*(int*)a2-*(int*)a1);
}
main()
{
      int I;
      for(I=1;;I++)
      {
          int *a,*b,i,n,as,ae,bs,be,money1=0,money2=0;

          scanf("%d",&n);
          if(n==0)
          break;
          else
          {
              a=(int*)malloc(n*sizeof(int));
              b=(int*)malloc(n*sizeof(int));
              for(i=0;i<=n-1;i++)
              scanf("%d",&a[i]);
              for(i=0;i<=n-1;i++)
              scanf("%d",&b[i]);
              bubble(a,n);
              qsort(b,n,sizeof(b[0]),compare);
              as=bs=0;
              ae=be=n-1;
              for(;as<=ae;)
              {
                           if(a[ae]>b[be])
                           {
                                 money1++;
                                 ae--;
                                 be--;
                           }
                           else if(a[ae]<b[be])
                           {
                                 money2++;
                                 ae--;
                                 bs++;
                           }
                           else if(a[as]>b[bs])
                           {
                                money1++;
                                as++;
                                bs++;
                           }
                           else if(a[as]<b[bs])
                           {
                                money2++;
                                ae--;
                                bs++;
                           }
                           else if(a[ae]<b[bs])
                           {
                                money2++;
                                ae--;
                                bs++;
                           }
                           else if(a[ae]>b[bs])
                           {
                                money1++;
                                ae--;
                                bs++;
                           }
                           else
                           {
                                ae--;
                                as++;
                           }
              }
              printf("%d\n",200*(money1-money2));
          }
      }
}


int main()

{
    int n[10000],sudu[10000][2];
    int i,j,l,x;
    i=0;
    int m,z,zhongjian[2];
    int yinzi[1000];
    int wei,weik,tou,touk;

    do
    {

       scanf("%d",&n[i]);
       if(n[i]==0)
       break;

       else
      {
         for(j=0;j<n[i];j++)
         {
           scanf("%d",&sudu[j][0]);
         }
         for(j=0;j<n[i];j++)
         {
           scanf("%d",&sudu[j][1]);
         }
      }

          for(l=0;l<n[i];l++)
          {
              for(j=0;j<n[i]-1;j++)
              {
                    if(sudu[j][0]>sudu[j+1][0])
                      {
                          zhongjian[0]=sudu[j+1][0];
                          sudu[j+1][0]=sudu[j][0];
                          sudu[j][0]=zhongjian[0];

                       }
                    else;
              }
         }

         for(l=0;l<n[i];l++)
         {
             for(j=0;j<n[i]-1;j++)
             {
                   if(sudu[j][1]>sudu[j+1][1])
                     {
                         zhongjian[0]=sudu[j+1][1];
                         sudu[j+1][1]=sudu[j][1];
                         sudu[j][1]=zhongjian[0];

                      }
                   else;
             }
         }

         yinzi[i]=0;
         m=n[i]-1;
         wei=0;
         weik=0;
         tou=m;
         touk=m;
         x=0;

        do{
             if(sudu[tou][0]>sudu[touk][1])
             {
                yinzi[i]=yinzi[i]+200;
                x++;
                tou--;
                touk--;
             }
             else if(sudu[tou][0]<sudu[touk][1])
             {
                yinzi[i]=yinzi[i]-200;
                x++;
                wei++;
                touk--;
             }
             else
              {

                    while(sudu[wei][0]>sudu[weik][1])
                     {
                          wei++;
                          weik++;
                          yinzi[i]=yinzi[i]+200;
                          x++;
                     }

                 if(sudu[wei][0]==sudu[touk][1])
                 {
                     wei++;
                     touk--;
                     x++;
                 }
                 else
                 {
                     wei++;
                     touk--;
                     yinzi[i]=yinzi[i]-200;
                     x++;
                 }
                 }

        }
        while(x<n[i]);

    i++;
    }
    while(n[i-1]!=0);

    z=i;
       for(i=0;i<z;i++)
    {
    printf("%d\n",yinzi[i]);
    }

    getchar();
    getchar();
}


int cmp(const void *x , const void *y)
{
	return (*(int *)y) - (*(int *)x) ;
}
int main()
{
	int n ;
	int a[1010] , b[1010] ;
	while ( cin >> n ){
		if ( n == 0 ) break ;
		for ( int i = 0 ; i < n ; i ++ )
			cin >> a[i] ;
		for ( int i = 0 ; i < n ; i ++ )
			cin >> b[i] ;
		qsort( a , n , sizeof (a[0]) , cmp ) ;
		qsort( b , n , sizeof (b[0]) , cmp ) ;

		int aStart = 0 , aEnd = n - 1 , bStart = 0 , bEnd = n - 1 ;
		int count = 0 ;
		while ( aStart <= aEnd ){
			if ( a[aStart] > b[bStart] ){
				count ++ ;
				aStart ++ ;
				bStart ++ ;
			}
			else if ( a[aEnd] > b[bEnd] ){
				count ++ ;
				aEnd -- ;
				bEnd -- ;
			}
			else {
				if ( a[aEnd] < b[bStart] )
					count -- ;
				aEnd -- ;
				bStart ++ ;
			}
		}
		cout << count * 200 << endl ;
	}
	return 0 ;
}


int tj[1001],qw[1001];
void main()
{
	int game(int n,int money);
	int n,i,j,k,temp;
	scanf("%d",&n);
	while(n!=0)
	{for(i=1;i<=n;i++)
     scanf("%d",&tj[i]);
	for(i=1;i<=n;i++)
     scanf("%d",&qw[i]);
	for(i=1;i<=n;i++)
	for(j=i+1;j<=n;j++)
	{
		if(tj[i]<tj[j]) {temp=tj[i];tj[i]=tj[j];tj[j]=temp;}
		if(qw[i]<qw[j]) {temp=qw[i];qw[i]=qw[j];qw[j]=temp;}
	}
	k=game(n,0);
	printf("%d\n",k);
	scanf("%d",&n);}
}
int game(int n, int money)
{
	int i;
    if(n==0) return money;
	else{
		if(tj[n]>qw[n]) money=money+200;
		else if(tj[n]<qw[n])
		{money=money-200;
		for(i=1;i<n;i++) qw[i]=qw[i+1];
		}
		else
		{
			if(n!=1)	{
			if(tj[1]<qw[1]) {money=money-200; for(i=1;i<n;i++) qw[i]=qw[i+1];}
           else if(tj[1]==qw[1]&&tj[1]>tj[n]) {money=money-200; for(i=1;i<n;i++) qw[i]=qw[i+1];}
		   else if(tj[1]>qw[1]) {money=money+200;for(i=1;i<n;i++) {tj[i]=tj[i+1];qw[i]=qw[i+1];}}
			}
		}
		n--;
return	game(n,money);
	}
}


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

main()
{
      int n,i,r;
      int tk,tm,qk,qm;
      int t[1000],q[1000];
      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),cmp);
          qsort(q,n,sizeof(int),cmp);
          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 {tm--;qk++;}
          }
          printf("%d\n",200*r);

      }
}


int compare(const void *x,const void *y)
{
	return *((int*)x)-*((int*)y);
}
main()
{
	while(1)
	{
	int n,i,k=0,sum=0,tou,wei;
	int tian[1000],qiwa[1000];
	scanf("%d",&n);
	if(n==0)
	break;
	for(i=0;i<n;i++)
	{
		scanf("%d",&tian[i]);
	}
	for(i=0;i<n;i++)
	{
		scanf("%d",&qiwa[i]);
	}
	tou=n-1;
	wei=n-1;
	qsort(tian,n,sizeof(int),compare);
	qsort(qiwa,n,sizeof(int),compare);
	for(i=0;i<=wei;)
	{
		if(tian[i]>qiwa[k])
		{
			sum=sum+200;
			k++;
			i++;
			continue;
		}
		if(tian[i]<qiwa[k])
		{
			sum=sum-200;
			tou--;
			i++;
			continue;
		}
		if(tian[i]==qiwa[k])
		{
			if(tian[wei]>qiwa[tou])
			{
				sum=sum+200;
				wei--;
				tou--;
				continue;
			}
			else
			{

			if(tian[i]==qiwa[tou])
			{
				tou--;
				i++;
				continue;
			}
			else
			{
				sum=sum-200;
				tou--;
				i++;
				continue;
			}
			}
		}
	}
	printf("%d\n",sum);

} }


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

   }

}

void main()
{
  int n,i,j,head,ans,tailt,tailk;
  int m;
  int t[1005],k[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",&k[i]);
  sort(t,n);sort(k,n);
  head=0;ans=0;tailt=n-1;tailk=n-1;
  for(i=0;i<n;i++)
        {
            if(t[head]>k[i])
            {
                head++;
                ans+=200;
            }
            else if(t[head]<k[i])
            {
                tailt--;
                ans-=200;
            }
            else if(t[head]==k[i])
            {
                for(j=tailt,m=tailk;j>=head;j--,m--)
                {
                    if(t[j]>k[m])
                    {
                        ans+=200;
                        tailt--;
                        tailk--;
                    }
                    else
                     {
                           if(t[j]<k[i]) ans-=200;
                          tailt=--j;
                          tailk=m;
                          break;
                     }
                }
            }

            if(head>tailt) break;
        }

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

  }
}


int T[1001],K[1001];

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

int main()
{
    int n,i,sum;
    int flag;
    int t_tail,t_head,k_tail,k_head;
    while (scanf("%d",&n)!=EOF && n)
    {
        for(i=0;i<n;i++)
            scanf("%d",&T[i]);
        for(i=0;i<n;i++)
            scanf("%d",&K[i]);

        qsort(T,n,sizeof(T[0]),cmp);
        qsort(K,n,sizeof(K[0]),cmp);
        sum=0;
        flag=1;
        k_head=t_head=0;
        k_tail=t_tail=n-1;

        while(t_head<=t_tail && k_head<=k_tail)
        {
            if(T[t_head]>K[k_head])
            {
                sum+=200;
                t_head++;
                k_head++;
            }
//?????else?
            else if(T[t_head]<K[k_head])
            {
                sum-=200;
                t_tail--;
                k_head++;
            }
            else
            {
                while(t_head<=t_tail && k_head<=k_tail)
                {
                    if(T[t_tail]>K[k_tail])
                    {
                        sum+=200;
                        t_tail--;
                        k_tail--;
                    }
                    else
                    {
                        if(T[t_tail] <K[k_head])
                            sum-=200;
                        t_tail--;
                        k_head++;
                        break;
                    }
                }
            }
            if(T[t_tail]>K[k_head])
            {
                flag=1;
                break;
            }
        }
        if(flag==1)
            sum+=(t_tail-t_head+1)*200;
        printf("%d\n",sum);
    }
    return 0;
}


// ???????
int n;
int self[1000], enemy[1000];

// ??
int result;

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

// ????????
void play(int s, int e)
{
	if (s > e)
		result += 200;
	else if (s < e)
		result -= 200;
}

// ??????
int calcMax(void)
{
	int i, smax, smin, emax, emin;
	result = 0;
	smax = emax = 0;
	smin = emin = n - 1;
	for (i = 0; i < n; i++)
	{
		if (self[smin] > enemy[emin])
		{
			play(self[smin], enemy[emin]);
			smin--;
			emin--;
		}
		else if (self[smin] < enemy[emin])
		{
			play(self[smin], enemy[emax]);
			smin--;
			emax++;
		}
		else if (self[smax] > enemy[emax])
		{
			play(self[smax], enemy[emax]);
			smax++;
			emax++;
		}
		else
		{
			play(self[smin], enemy[emax]);
			smin--;
			emax++;
		}
	}
	return result;
}

int main(void)
{
	int i;
	while (scanf("%d", &n) != -1 && n != 0)
	{
		for (i = 0; i < n; i++)
			scanf("%d", &self[i]);
		qsort(self, n, sizeof(int), compare);
		for (i = 0; i < n; i++)
			scanf("%d", &enemy[i]);
		qsort(enemy, n, sizeof(int), compare);
		printf("%d\n", calcMax());
	}
	return 0;
}


int money(int n){
	int i,j,m,ans=0,mid,head=0,tailt=n-1,tailk=n-1;
	int *k=(int*)malloc(sizeof(int)*n);
	int *t=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
		scanf("%d",&t[i]);
	for(i=0;i<n;i++)
		scanf("%d",&k[i]);
	for(i=0;i<n;i++)
		for(j=0;j<n-1;j++)
			if(k[j]<k[j+1]){
				mid=k[j];
				k[j]=k[j+1];
				k[j+1]=mid;
			}
	for(i=0;i<n;i++)
		for(j=0;j<n-1;j++)
			if(t[j]<t[j+1]){
				mid=t[j];
				t[j]=t[j+1];
				t[j+1]=mid;
			}
    for(i=0;i<n;i++)
        {
            if(t[head]>k[i])
            {
                head++;
                ans+=200;
            }
            else if(t[head]<k[i])
            {
                tailt--;
                ans-=200;
            }
            else if(t[head]==k[i])
            {
                for(j=tailt,m=tailk;j>=head;j--,m--)
                {
                    if(t[j]>k[m])
                    {
                        ans+=200;
                        tailt--;
                        tailk--;
                    }
                    else
                     {
                        if(t[j]<k[i]) ans-=200;
                        tailt=--j;
                        tailk=m;
                        break;
                     }
                }
            }

            if(head>tailt) break;
        }
	free(k);
	free(t);
	return ans;
}
void main(){
	int n;
	while(scanf("%d",&n)==1&&n!=0)
		printf("%d\n",money(n));
}


int n;
int a[1001], b[1001];	//a,b??????????????
int win, lose;		//?????????

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

void cal(int m)
{
	if (m==0)
		return;

	if (a[1]>b[m]){
		win += m;
		return;
	}

	if (b[1]>a[m]){
		lose += m;
	}

	if (a[1]==b[m]){
		for (int i=1; i<m; i++){
			a[i] = a[i+1];
		}
		cal(m-1);
		return;
	}

	if (b[1]==a[m]){
		for (int i=1; i<m; i++){
			b[i] = b[i+1];
		}
		cal(m-1);
		return;
	}

	int i,j;

	for (i=1; i<=m; i++){
		if (a[i]<=b[1])
			continue;
		for (j=1; j<=m; j++){
			if (a[i]>b[j] && j<m)
				continue;
			if (a[i]<=b[j])
				j--;
			for (int t=i; t<m; t++)
				a[t] = a[t+1];
			for (int t=j; t<m; t++)
				b[t] = b[t+1];
			win++;
			cal(m-1);
			return;
		}
	}
}

int main()
{
	while(true){
		cin>>n;
		if (n==0)
			break;
		for (int i=1; i<=n; i++)
			cin>>a[i];
		for (int i=1; i<=n; i++)
			cin>>b[i];
		a[0] = b[0] = 0;
		qsort(a, n+1, sizeof(int), cmp);
		qsort(b, n+1, sizeof(int), cmp);
		win=0;
		lose=0;
		cal(n);
		cout<<200*(win-lose)<<endl;
	}
	return 0;
}


int cmp(const void*e1,const void *e2)
{
	return *((int*)e2)-*((int*)e1);
}
int main()
{
	int n,a[1000],b[1000],i,j,k,s,t,result;
	while(scanf("%d",&n) && n )
	{
		for(i=0;i<n;++i)
			scanf("%d",&b[i]);
		qsort(b,n,sizeof(int),cmp);
		for(i=0;i<n;++i)
			scanf("%d",&a[i]);
		qsort(a,n,sizeof(int),cmp);
		i=k=0;
		j=s=n-1;
		result=0;
		for(t=0;t<n;++t)
		{
			if(b[i]>a[k])
			{
				result+=200;
				++i;
				++k;
			}
			else if(b[j]>a[s])
			{
				result+=200;
				--j;
				--s;
			}
			else
			{
				if(b[j]>a[k])
					result+=200;
				else if(b[j]<a[k])
					result-=200;
				--j;
				++k;
			}
		}
		printf("%d\n",result);
	}
	return 0;
}


int num1[1001];
int num2[1001];
int num;
int compare(const void * p1,const void * p2)
{
	int * q1,* q2;
	q1=(int *) p1;
	q2=(int *) p2;
	return *q1-*q2;
}
int main()
{
	while(true)
	{

		cin>>num;
		if(num==0)
			break;
		for(int i=1;i<=num;i++)
		{
			cin>>num1[i];
		}
		for(int i=1;i<=num;i++)
		{
			cin>>num2[i];
		}
		qsort(&(num1[1]),num,sizeof(int),compare);
		qsort(&(num2[1]),num,sizeof(int),compare);
		int p1,p2,p3,p4;
		p1=1;
		p2=num;
		p3=1;
		p4=num;
		int money=0;
		while(true)
		{
			if(p1==p2)
			{
				if(num1[p1]>num2[p3])
					money++;
				if(num1[p1]<num2[p3])
					money--;
				break;
			}
			else
			{
				if(num1[p1]>num2[p3])
				{
					money++;
					p1++;
					p3++;
					continue;
				}
				if(num1[p2]>num2[p4])
				{
					money++;
					p2--;
					p4--;
					continue;
				}
				if(num1[p1]<num2[p4])
					money--;
				if(num1[p1]>num2[p4])
					money++;
				p1++;
				p4--;
			}
		}
		cout<<money*200<<endl;
	}
	return 0;
}


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

int main()
{
	int n;
	while(cin>>n)
	{
		if(n==0)break;
	int tianji[1001],qiwang[1001];
	int i,j;
	for(i=0;i<n;i++)
		cin>>tianji[i];
	for(i=0;i<n;i++)
		cin>>qiwang[i];
	qsort(tianji,n,sizeof(int),cmp);
	qsort(qiwang,n,sizeof(int),cmp);
	i=0;
	j=i;
	int k=n-1,h=n-1;
	int money=0;

	for(int m=0;m<n;m++)
	{
		if(tianji[i]>qiwang[j])
		{
			i++,j++;
			money+=200;
		}
		else
		{
			if(tianji[k]>qiwang[h])
			{
				k--,h--;
				money+=200;
			}
			else
			{
				if(tianji[k]>qiwang[j])
					money+=200;
				else if(tianji[k]<qiwang[j])
					money-=200;
				k--;
				j++;
			}
		}
	}
	cout<<money<<endl;
	}
}


int main()
{
    int z,totalhorse,tianwins[10000]={0},tianloses[10000]={0},p1,p2,p3,p4,qihorse[10000],tianhorse[10000],y,k1,m1,temp1,k2,m2,temp2,count=0,i,j;
    //p1???????????????p2??????????????p3??????????????p4?????????????
    for(z=0;z<=10000;z++)
    {
        scanf("%d",&totalhorse);
        if(totalhorse==0)
        {
            break;
        }
        else
        {
            count++;
        }
        for(i=0;i<=totalhorse-1;i++)
        {
            scanf("%d",&tianhorse[i]); //??????
        }
        for(j=0;j<=totalhorse-1;j++)
        {
            scanf("%d",&qihorse[j]); //??????
        }
        for(k1=0;k1<=totalhorse-1;k1++)
        {
            for(m1=0;m1<=totalhorse-2-k1;m1++)
            {
                if(tianhorse[m1]<tianhorse[m1+1])    //???????????
                {
                    temp1=tianhorse[m1];
                    tianhorse[m1]=tianhorse[m1+1];
                    tianhorse[m1+1]=temp1;
                }
            }
        }
        for(k2=0;k2<=totalhorse-1;k2++)
        {
            for(m2=0;m2<=totalhorse-2-k2;m2++)
            {
                if(qihorse[m2]<qihorse[m2+1])    //???????????
                {
                    temp2=qihorse[m2];
                    qihorse[m2]=qihorse[m2+1];
                    qihorse[m2+1]=temp2;
                }
            }
        }
        p1=0;
        p2=0;
        p3=totalhorse-1;
        p4=totalhorse-1;
        for(y=1;y<=totalhorse;y++)
        {
                if(tianhorse[p2]>qihorse[p1])
                {
                    tianwins[z]++;
                    p2++;
                    p1++;
                }
                else
                {
                        if(tianhorse[p4]>qihorse[p3])
                        {
                            tianwins[z]++;
                            p4--;
                            p3--;

                        }
                        else if(tianhorse[p4]==qihorse[p3]&&tianhorse[p4]<qihorse[p1])
                        {
                                tianloses[z]++;
                                p4--;
                                p1++;
                        }
                        else if(tianhorse[p4]==qihorse[p3]&&tianhorse[p4]==qihorse[p1])
                        {
                            tianloses[z]++;
                            tianwins[z]++;
                            p4--;
                            p1++;
                        }
                        else if(tianhorse[p4]<qihorse[p3])
                        {
                            tianloses[z]++;
                            p1++;
                            p4--;
                        }
                }
        }
    }
    int x;
    for(x=0;x<=count-1;x++)
    {
        printf("%d\n",(tianwins[x]-tianloses[x])*200);
    }

}


int compare( const void *a, const void *b)
{
      return *((int *)a)-*((int *)b);
}
main()
{
      int i,j,k,n,t,a[1000],b[1000],max,w;
      scanf("%d",&n);
      while(n!=0)
      {
                 for(i=0;i<n;i++)
                     scanf("%d",&a[i]);
                 for(j=0;j<n;j++)
                     scanf("%d",&b[j]);
                 qsort(a,n,sizeof(int),compare);
                 qsort(b,n,sizeof(int),compare);
                 max=-n;
                 for(t=0;t<n;t++)
                 {
                     w=0;
                     for(k=0;k<n;k++)
                     {
                         if(a[(k+t)%n]<b[k])
                           w--;
                         if(a[(k+t)%n]>b[k])
                           w++;
                     }
                     if(w>max) max=w;
                 }
                 printf("%d\n",200*max);
                 scanf("%d",&n);
      }
}


int wis[MAX];
int king[MAX];

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

int main()
{
	int n, count;
	int i, imax, imin, jmax, jmin;

	while (1)
	{
		scanf("%d", &n);
		if (n == 0)
			break;

		for (i=0 ; i<n ; i++)
			scanf("%d", wis+i);
		for (i=0 ; i<n ; i++)
			scanf("%d", king+i);

		qsort(wis, n, sizeof(int), comp);
		qsort(king, n, sizeof(int), comp);

		imin = 0;
		imax = n-1;
		jmin = 0;
		jmax = n-1;
		count = 0;
		while (jmin < jmax)
		{
			if (wis[imin] > king[jmin])
			{
				count++;
				imin++;
				jmin++;
			}
			else if (wis[imin] < king[jmin])
			{
				count--;
				imin++;
				jmax--;
			}
			else	//wis[imin] == king[jmin]
			{
				while (jmin < jmax)
				{
					if (wis[imax] > king[jmax])
					{
						count++;
						imax--;
						jmax--;
					}
					else if (wis[imax] < king[jmax])
					{
						count--;
						imin++;
						jmax--;
					}
					else	//wis[imax] == king[jmax]
					{
						if (wis[imin] < king[jmax])
							count--;
						imin++;
						jmax--;
						break;
					}
				}
			}
		}
		if (wis[imax] > king[jmax])
			count++;
		else if (wis[imax] < king[jmax])
			count--;
		count *= 200;

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

	return 0;
}


void _qsort ( int a[] , int start , int end )
{
   int i , j , temp;
   i = start , j = end;
   temp = a[i];
   while ( i < j )
    {
     for ( ; temp >= a[j] && i < j ; j -- );
     i < j ? a[i++] = a[j] : 0;
     for ( ; a[i] >= temp && i < j ; i ++ );
     i < j ? a[j--] = a[i] : 0;
    }
   a[i] = temp;
   if ( start < i-1 ) _qsort ( a , start , i-1 );
   if ( j + 1 < end ) _qsort ( a , j + 1 , end );
}

int main ()
{
   int n , s , max , q[MAXN] , t[MAXN] , i , j;
   for ( ;; )
    {
     scanf ( "%d" , &n );
     if ( n == 0 ) break;
     max = -1001;
     for ( i = 0 ; i < n ; i ++ )
      scanf ( "%d" , &t[i] );
     _qsort ( t , 0 , n-1 );
     for ( i = 0 ; i < n ; i ++ )
      scanf ( "%d" , &q[i] );
     _qsort ( q , 0 , n-1 );
     for ( i = 0 ; i < n ; i ++ )
      {
       s = 0;
       for ( j = 0 ; j < n ; j ++ )
        if ( q[(i+j)%n] > t[j] )
          s --;
         else if ( q[(i+j)%n] < t[j] )
          s ++;
       if ( s > max ) max = s;
      }
     printf ( "%d\n" , max*200 );
    }
  // getchar (); getchar ();
   return 0;
}


int n,a[1001],b[1001];
void sifta(int i,int num)
{
	int j=i*2,tmp=a[i];
	while(j<=num)
	{
		if(j<num && a[j]<a[j+1])	j++;
		if(tmp<a[j]){a[i]=a[j];i=j;j=j*2;}
		else break;
	}
	a[i]=tmp;
}
void siftb(int i,int num)
{
	int j=i*2,tmp=b[i];
	while(j<=num)
	{
		if(j<num && b[j]<b[j+1])	j++;
		if(tmp<b[j]){b[i]=b[j];i=j;j=j*2;}
		else break;
	}
	b[i]=tmp;
}
void hsa()
{
	int i,tmp;
	for(i=n/2;i>0;i--)sifta(i,n);
	for(i=n;i>0;i--){
		tmp=a[i];a[i]=a[1];a[1]=tmp;
		sifta(1,i-1);
	}
	//for(i=1;i<=n;i++)	printf("%d ",a[i]);
}
void hsb()
{
	int i,tmp;
	for(i=n/2;i>0;i--)siftb(i,n);
	for(i=n;i>0;i--){
		tmp=b[i];b[i]=b[1];b[1]=tmp;
		siftb(1,i-1);
	}
	//for(i=1;i<=n;i++)	printf("%d ",b[i]);
}
int main()
{
	int i;
	while(1)
	{
		scanf("%d",&n);
		if(n==0)break;
		for(i=1;i<=n;i++)scanf("%d",&b[i]);	//tianji
		for(i=1;i<=n;i++)scanf("%d",&a[i]);	//qiwang
		hsa();
		hsb();//find the minest one >= it

		int tot=0,j=0,t=0,visited[1001]={0};

		int ha=1,ta=n,hb=1,tb=n;
		while(ha<=ta)
		{
			if(a[ha]<b[hb]){
				tot+=200;ha++;hb++;
			}
			else if(a[ta]<b[tb]){
				tot+=200;ta--;tb--;
			}
			else{
				if(a[ta]>b[hb])
					tot-=200;	//lose
				//draw
				ta--;hb++;
			}
		}
		/*
		for(i=1;i<=n;i++){
			//j++;if(j>n){t--;break;}
			t=i;
			while(b[j]<a[i] && j<n)j++;
			if(b[j]>a[i])
			{
				tot+=200;visited[j]=1;j++;
				printf("%d wins %d\n",b[j],a[i]);
			}
			else if(b[j]<a[i]) {tot-=200;visited[j]=1;break;}
			else {visited[j]=1;break;}
		}
		j=1;
		for(i=t+1;i<=n;i++){
			while(j<=n && (visited[j] || a[i]>b[j]))j++;
			if(a[i]!=b[j]){tot-=200;break;}
			else {visited[j]=1;j++;t++;if(j>n)break;}
		}
		*/
		printf("%d\n",tot);
	}
	//getchar();getchar();
	return 0;
}


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

    for(;;)
    {
     int n;
    scanf("%d",&n);
    if (n==0) break;
      int *tian=(int *)malloc(n*sizeof(int));
      int *qi=(int *)malloc(n*sizeof(int));
      for(int i=0;i<n;i++)
      {
              scanf("%d",tian+i);
      }
      for(int i=0;i<n;i++)
      {
              scanf("%d",qi+i);
      }
      paixu(tian,n);
      paixu(qi,n);

      int t=0,q=0,qmax=n-1,tmax=n-1,win=0;
      for(;n>=1;n--)
      {
              if(*(tian+t)>*(qi+q))
              {
                   win++;
                   t++;
                   q++;
              }
              else if(*(tian+t)==*(qi+q))
              {
                   if(*(tian+tmax)>*(qi+qmax))
                   {
                       win++;
                       tmax--;
                       qmax--;
                   }
                   else if(*(tian+tmax)<=*(qi+qmax))
                   {
                       if(*(tian+t)<*(qi+qmax)) win--;
                       qmax--;
                       t++;
                   }

              }
              else if(*(tian+t)<*(qi+q))
              {
                  win--;
                  t++;
                  qmax--;
              }
      }
      printf("%d\n",win*200);
    }

}


int Comp(const void *p1, const void *p2)
{
	return *((int *)p1) > *((int *)p2) ? -1:1;
}

int main()
{
	int tian[2000],qi[2000];
	int n;
	int count;
	int a_first,a_end,b_first,b_end;
	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];
		}

		qsort(tian,n,sizeof(int),Comp);
		qsort(qi,n,sizeof(int),Comp);
		count = 0;
		a_first = 0;
		a_end = n - 1;
		b_first = 0;
		b_end = n - 1;
		while(a_first <= a_end)
		{
			//cout<<a_first<<" "<<a_end<<" "<<b_first<<" "<<b_end<<endl;
			//cout<<tian[a_first]<<" "<<qi[b_first]<<endl;
			if(tian[a_first] > qi[b_first])
			{
				count++;
				a_first++;
				b_first++;
			}
			else if(tian[a_end] > qi[b_end])
			{
				count++;
				a_end--;
				b_end--;
			}
			else if(tian[a_first] == qi[b_first])
			{
				if(tian[a_end] > qi[b_first])
				{
					count++;
					a_end--;
					b_first++;
				}
				else if(tian[a_end] == qi[b_first])
				{
					a_end--;
					b_first++;
				}
				else if(tian[a_end] < qi[b_first])
				{
					count--;
					a_end--;
					b_first++;
				}
			}
			else
			{
				if(tian[a_end] > qi[b_first])
				{
					count++;
					a_end--;
					b_first++;
				}
				else if(tian[a_end] == qi[b_first])
				{
					a_end--;
					b_first++;
				}
				else if(tian[a_end] < qi[b_first])
				{
					count--;
					a_end--;
					b_first++;
				}
			}
		}
		cout<<count*200<<endl;
	}
	return 0;
}


// #include <conio.h>
int tian[1004];
int qi[1004];
int cmp(const void *c1,const void *c2)
{
	return *(int *)c2-*(int *)c1;
}
int main()
{
	int n;
	while(true)
	{
		scanf("%d",&n);
		if(n<=0)
			break;
		for(int i = 0;i<n;i++)
			scanf("%d",&tian[i]);
		for(int i = 0;i<n;i++)
			scanf("%d",&qi[i]);
		qsort(tian,n,sizeof(int),cmp);
		qsort(qi,n,sizeof(int),cmp);
		int ts = 0,te = n-1,qs = 0,qe = n-1;
		int nMoney = 0;
		while(ts<=te)
		{
			if(tian[ts]>qi[qs])
			{
				ts++;
				qs++;
				nMoney+=200;
			}
			else if(tian[ts]<qi[qs])
			{
				nMoney-=200;
				qs++;
				te--;
			}
			else
			{
				if(tian[te]>qi[qe])
				{
					nMoney+=200;
					te--;
					qe--;
				}
				else if(tian[te]<qi[qe])
				{
					nMoney-=200;
					te--;
					qs++;
				}
				else
				{
					if(tian[te]>qi[qs])
					{
						nMoney+=200;
						te--;
						qs++;
					}
					else
					{
						if(tian[te]<qi[qs])
							nMoney-=200;
						te--;
						qs++;
					}
				}
			}
		}
		printf("%d\n",nMoney);
	}
// 	getch();
	return 0;
}


void sort(int a[],int n); //sort from quick to slow

int main(){
	int i,j,n;
	int tquick,tslow,qquick,qslow;
	int tj[1000],qw[1000];
	int win,lose;

	while(1){
		scanf("%d",&n);
		if(n==0)
			break;
		for(i=0;i<n;i++)
			scanf("%d",&tj[i]);
		for(i=0;i<n;i++)
			scanf("%d",&qw[i]);
		win=0;
		tquick=qquick=0;
		tslow=qslow=n-1;
		sort(tj,n);
		sort(qw,n);
		while(n--){
			if(tj[tslow]>qw[qslow])
			{
				tslow--;
				qslow--;
				win++;
			}
			else if(tj[tslow]<qw[qslow])
			{
				qquick++;
				tslow--;
				win--;
			}
			else if(tj[tquick]>qw[qquick])
			{
				qquick++;
				tquick++;
				win++;
			}
			else if(tj[tquick]<qw[qquick])
			{
				tslow--;
				qquick++;
				win--;
			}
			else if(tj[tquick]==qw[qquick])
			{
				if(tj[tslow]<qw[qquick])
				{
					win--;
				}
				tslow--;
				qquick++;
			}
		}
		printf("%d\n",200*win);
	}
	return 0;
}

void sort(int a[],int n){
	int i,j;
	int tmp,max;

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


int tj[M], qw[M];
int n;

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

int main()
{
    int i, b,e, bb, ee, sum;
    while (scanf("%d", &n)!=EOF && n!=0) {
	for (i=0; i<n; i++)
	    scanf("%d", &tj[i]);
	for (i=0; i<n; i++)
	    scanf("%d", &qw[i]);
	qsort(tj, n, sizeof(int), cmp);
	qsort(qw, n, sizeof(int), cmp);
	b=bb=0; e=ee=n-1;
	sum = 0;
	while (b <= e) {
	    if (tj[e] > qw[ee])
		++sum, --e, --ee;
	    else if (tj[e] < qw[ee])
		--sum, ++b, --ee;
	    else if (tj[b] > qw[bb])
		++sum, ++b, ++bb;
	    else if (tj[b] < qw[bb])
		--sum, ++b, --ee;
	    else {
		if (tj[b] < qw[ee])
		    --sum, ++b, --ee;
		else ++b, --ee;
	    }
	}
	printf("%d\n", sum*200);
    }
    return 0;
}


int comp(const void *p, const void *q)
{
    return (*(int *)q - *(int *)p);
}
int main()
{
 int n[50],tianji[50][1000],qiwang[50][1000],result[50],i,j,ii,jj,max,max0,nmax,cmax,cnmax;
 int tb,tm,qb,qm;
 i=0;
 while(1)
 {scanf("%d",&n[i]);
 if (n[i]==0) break;
 for (j=0;j<n[i];j++)
    scanf("%d",&tianji[i][j]);

 for (j=0;j<n[i];j++)
    scanf("%d",&qiwang[i][j]);
  qsort(tianji[i], n[i], sizeof(int), comp);
  qsort(qiwang[i], n[i], sizeof(int), comp);
  i++;
 }

 for (ii=0;ii<i;ii++)
{   result[ii]=0;
    tb=0;
    tm=n[ii]-1;
    qm=n[ii]-1;
    qb=0;
    for (j=n[ii]-1;j>=tb;j--)
    {

        if(tianji[ii][j]>qiwang[ii][qm])
          {
          tm--;
          qm--;
          result[ii]=result[ii]+200;

          }
          else if (tianji[ii][j]<qiwang[ii][qm])
             {tm--;
             qb++;
             result[ii]=result[ii]-200;;
             }
             else if (tianji[ii][j]==qiwang[ii][qm])
             {
                while(tianji[ii][tb]>qiwang[ii][qb])
                   {tb++;
                   qb++;
                   result[ii]=result[ii]+200;
                   }
                  if(tianji[ii][tb]<qiwang[ii][qb])
                      {tm--;
                      qb++;
                      result[ii]=result[ii]-200;
                      }
                  else if(tianji[ii][tb]==qiwang[ii][qb]&&j>tb)
                      {
                       if(tianji[ii][j]<qiwang[ii][qb])
                       result[ii]=result[ii]-200;
                        qb++;tm--;
                       }

                      }
        }
      printf("%d\n",result[ii]);
    }
return 0;
}


int comp(const void *a, const void *b)
{
	return *(int *)b - *(int *)a;
}
int main()
{
	int n,i,t[1001],q[1001];
	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), comp);
		qsort(q, n, sizeof(int), comp);
		int tl = 0,ql = 0;
		int tr = n - 1,qr = n - 1;
		int result = 0;
		while(tl <= tr)
		{
			if(t[tl] > q[ql])
			{
				result += 200;
				tl ++;
				ql ++;
			}
			else if(t[tr] > q[qr])
			{
				result += 200;
				tr --;
				qr --;
			}
			else
			{
				if(t[tr] > q[ql])
					result += 200;
				else if(t[tr] < q[ql])
					result -= 200;
				tr --;
				ql ++;
			}
		}
		cout << result << endl;
	}
}


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

int main(){
	int n;
	scanf("%d",&n);
	while(n){
		int tianji[n],qiwang[n];
		for(int i=0;i<n;i++){
			scanf("%d",&tianji[i]);
		}
		for(int i=0;i<n;i++){
			scanf("%d",&qiwang[i]);
		}
		sort(tianji,n);
		sort(qiwang,n);

		int tfirst=0,qfirst=0;
		int tlast=n-1,qlast=n-1;
		int j=0;
		int win=0;
		int lose=0;

		while(j<n){
			if(tianji[tfirst]>qiwang[qfirst]){
				win++;
				tfirst++;
				qfirst++;
			}
			else if(tianji[tfirst]<qiwang[qfirst]){
				lose++;
				tlast--;
				qfirst++;
			}
			else{
				if(tianji[tlast]>qiwang[qlast]){
					win++;
					tlast--;
					qlast--;
				}
				else{
					if(tianji[tlast]<qiwang[qfirst])lose++;
					tlast--;
					qfirst++;
				}
			}
			j++;
		}

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

		scanf("%d",&n);
	}
}


int main()
{
	int n,i,j,s,sub=0,sum[1000]={0};
	int tfast,tslow,wfast,wslow;
	int t[1000],w[1000];
	int k=0;
  while(scanf("%d",&n)&&(n!=0))
  {
	  for(i=0;i<n;i++)
		  scanf("%d",&t[i]);
	  for(i=0;i<n;i++)
		  scanf("%d",&w[i]);
   	for(i=0;i<n-1;i++)
 		for(j=i+1;j<n;j++)
            if(t[i]<t[j])
			{s=t[j];t[j]=t[i];t[i]=s;}
 	for(i=0;i<n-1;i++)
 		for(j=i+1;j<n;j++)
            if(w[i]<w[j])
			{s=w[j];w[j]=w[i];w[i]=s;}
     tfast=0;tslow=n-1;
     wfast=0;wslow=n-1;
    for(i=0;i<n;i++)
	{
	    if(t[tfast]==w[wfast])
		{
		   if(t[tslow]>w[wslow]){sub++;tslow--;wslow--;}
		   else if(t[tslow]<w[wslow]){sub--;tslow--;wfast++;}
           else if(t[tslow]==w[wslow])
		   {
			   if(t[tslow]<w[wfast]){sub--;tslow--;wfast++;}
               else if(t[tslow]==w[wfast]){break;}
		   }
		}
        else if(t[tfast]>w[wfast])
        		{sub++;tfast++;wfast++;}
		else {sub--;tslow--;wfast++;}
	}
   sum[k++]=sub*200;
   sub=0;
  }
  for (i=0;i<k;i++) printf("%d\n",sum[i]);

}


int main() {
	int n, a[1000], b[1000];
	int i, j, al, ar, bl, br;
	while (cin >> n) {
		if (n == 0)
			break;
		for (i = 0; i < n; i++)
			cin >> a[i];
		for (i = 0; i < n; i++)
			cin >> b[i];
		sort(a, &a[n]);
		sort(b, &b[n]);

		int total = 0;
		al = bl = 0;
		ar = br = n - 1;
		while (al <= ar) {
			if (a[al] > b[bl]) {
				total += 200;
				al++;
				bl++;
			} else if (a[ar] > b[br]) {
				total += 200;
				ar--;
				br--;
			} else {
				if (a[al] < b[br]) {
					total -= 200;
					al++;
					br--;
				} else {
					al++;
					br--;
				}
			}
		}
		cout << total << endl;
	}
	return 0;
}


const int MaxSize = 1010;
int t[ MaxSize ], q[ MaxSize ];

int main()
{
	int N;
	while ( cin >> N && N != 0 )
	{
		for ( int i = 0; i < N; i++ )
			cin >> t[ i ];
		for ( int i = 0; i < N; i++ )
			cin >> q[ i ];

		sort( t, t+N );
		sort( q, q+N );

		int ans = 0;
		int tSt = 0, tEnd = N-1;
		int qSt = 0, qEnd = N-1;

		while ( tSt <= tEnd )
		{
			if ( t[ tEnd ] > q[ qEnd ] )
			{
				ans += 200;
				tEnd--;
				qEnd--;
			}
			else if ( t[ tSt ] > q[ qSt ] )
			{
				ans += 200;
				tSt++;
				qSt++;
			}
			else
			{
				if ( t[ tSt ] < q[ qEnd ] )
					ans -= 200;
				tSt++;
				qEnd--;
			}
		}
		cout << ans << endl;
	}

	return 0;
}


int main() {
	int n, a[1000], b[1000];
	int i, j, al, ar, bl, br;
	while (cin >> n) {
		if (n == 0)
			break;
		for (i = 0; i < n; i++)
			cin >> a[i];
		for (i = 0; i < n; i++)
			cin >> b[i];
		sort(a, &a[n]);
		sort(b, &b[n]);

		int total = 0;
		al = bl = 0;
		ar = br = n - 1;
		while (al <= ar) {
			if (a[al] > b[bl]) {
				total += 200;
				al++;
				bl++;
			} else if (a[ar] > b[br]) {
				total += 200;
				ar--;
				br--;
			} else {
				if (a[al] < b[br]) {
					total -= 200;
					al++;
					br--;
				} else {
					if (a[al] > b[br])
						total += 200;
					al++;
					br--;
				}
			}
		}
		cout << total << endl;
	}
	return 0;
}


void _qsort ( int a[] , int start , int end )
{
   int i , j , temp;
   i = start , j = end;
   temp = a[i];
   while ( i < j )
    {
     for ( ; temp >= a[j] && i < j ; j -- );
     if ( i < j ) a[i++] = a[j];
     for ( ; a[i] >= temp && i < j ; i ++ );
     if ( i < j ) a[j--] = a[i];
    }
   a[i] = temp;
   if ( start < i-1 ) _qsort ( a , start , i-1 );
   if ( j + 1 < end ) _qsort ( a , j + 1 , end );
}

int main ()
{
   int n , s , max , q[MAXN] , t[MAXN] , i , j;
   for ( ;; )
    {
     scanf ( "%d" , &n );
     if ( n == 0 ) break;
     max = -1001;
     for ( i = 0 ; i < n ; i ++ )
      scanf ( "%d" , &t[i] );
     _qsort ( t , 0 , n-1 );
     for ( i = 0 ; i < n ; i ++ )
      scanf ( "%d" , &q[i] );
     _qsort ( q , 0 , n-1 );
     for ( i = 0 ; i < n ; i ++ )
      {
       s = 0;
       for ( j = 0 ; j < n ; j ++ )
        if ( q[(i+j)%n] > t[j] )
          s --;
         else if ( q[(i+j)%n] < t[j] )
          s ++;
       if ( s > max ) max = s;
      }
     printf ( "%d\n" , max*200 );
    }
 //  getchar (); getchar ();
   return 0;
}


int CMP(const void * ele1, const void * ele2)
{
	return *((int *)ele2) - *((int *)ele1);
}

int main()
{
	int n;
	int i,counter,qiwangleft,qiwangright,tianjileft,tianjiright;
	int tianji[1006],qiwang[1006],ans;
	while (cin>>n)
	{
		if ( n==0 )
			break;
		for ( i=0;i<n;i++ )
			cin>>tianji[i];
		for ( i=0;i<n;i++ )
			cin>>qiwang[i];
		qsort(tianji,n,sizeof(int),CMP);
		qsort(qiwang,n,sizeof(int),CMP);

		qiwangleft = 0;
		tianjileft = 0;
		qiwangright = n-1;
		tianjiright = n-1;
		counter = 0;
		ans = 0;
		while ( counter!=n )
		{
			counter++;
			if ( qiwang[qiwangleft] < tianji[tianjileft] )
			{
				qiwangleft++;
				tianjileft++;
				ans += 200;
			}
			else if ( qiwang[qiwangleft] == tianji[tianjileft] )
			{
				if ( qiwang[qiwangright] < tianji[tianjiright] )
				{
					ans += 200;
					qiwangright--;
					tianjiright--;
				}
				else
				{
					if ( qiwang[qiwangleft] > tianji[tianjiright] )
					{
						ans -= 200;
					}
					qiwangleft++;
					tianjiright--;
				}
			}
			else
			{
				ans -= 200;
				qiwangleft++;
				tianjiright--;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


int *arrange(int a[],int n);
int main()
{
	//money??
	int money;
	//num ???
	int num;
	for(;;)
	{
		money=0;
		scanf("%d",&num);
		if(num==0)
		{
			break;
		}
		else
		{
			//??????
			//king?tianji????????????
			int king[1000];
			int tianji[1000];
			int i1;
			for(i1=0;i1<=num-1;i1++)
			{
				if(i1==0)
				{
					scanf("%d",&tianji[i1]);
				}
				else
				{
					scanf(" %d",&tianji[i1]);
				}
			}
			for(i1=0;i1<=num-1;i1++)
			{
				if(i1==0)
				{
					scanf("%d",&king[i1]);
				}
				else
				{
					scanf(" %d",&king[i1]);
				}
			}
			//??????
			arrange(tianji,num);
			arrange(king,num);
			//??????
			//head,tail????????????????
			int tianhead=0,kinghead=0;
			int tiantail=num-1,kingtail=num-1;
			//flag??????
			int flag=1;
			for(;flag;)
			{
				if(tianhead==tiantail)
				{
					flag=0;
				}
				if(tianji[tianhead]>king[kinghead])
				{
					money+=200;
					tianhead++;
					kinghead++;
				}
				else if(tianji[tiantail]>king[kingtail])
				{
					money+=200;
					tiantail--;
					kingtail--;
				}
				else
				{
					if(tianji[tiantail]<king[kinghead])
					{
						money-=200;
					}
					tiantail--;
					kinghead++;
				}
			}
			printf("%d\n",money);
		}
	}

	return 0;
}
int *arrange(int a[],int n)
{
	//????n-1?
	int i1;
	int position=n-1;
	for(i1=0;i1<=n-1;i1++,position--)
	{
		int i2;
		for(i2=0;i2<=position-1;i2++)
		{
			if(a[i2]<a[i2+1])
			{
				int tmp;
				tmp=a[i2];
				a[i2]=a[i2+1];
				a[i2+1]=tmp;
			}
		}
	}
	return a;
}


int Tian[MAXIN], Qi[MAXIN];

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

int main()
{
	int n;
	while(scanf("%d", &n) && n)
	{
		int i;
		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), MyCompare);
		qsort(Qi, n, sizeof(int), MyCompare);

		int Tp = 0;
		int Qtail = n - 1;
		int Ttail = n - 1;
		int Qp = 0;
		int ans = 0;
		while(Qp <= Qtail)
		{
			if(Tian[Tp] > Qi[Qp])
			{
				Tp ++;
				Qp ++;
				ans += 200;
			}
			else if(Tian[Tp] < Qi[Qp])
			{
				Qtail --;
				Tp ++;
				ans -= 200;
			}
			else // Tian[Tp] == Qi[Qp]
			{
				if(Tian[Ttail] > Qi[Qtail])
				{
					Qtail --;
					Ttail --;
					ans += 200;
				}
				else
				{
					if(Tian[Tp] < Qi[Qtail])
						ans -= 200;
					Qtail --;
					Tp ++;
				}
			}
		}

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


int find(int a[],int i,int j)
{
	int key=a[i],k,flag=0;
	for(k=i+1;k<=j;k++)
		if(a[k]>key)return k;
		else if(a[k]<key)return i;
	return -1;
}
int partition(int a[],int i,int j,int pivot)
{
	int ta,l=i,r=j;
	do{
		ta=a[l];
		a[l]=a[r];
		a[r]=ta;
		while(a[l]>=pivot)l++;
		while(a[r]<pivot)r--;
	}while(l<=r);
	return l;
}
void quicksort(int a[],int i,int j)
{
	int pindex,pivot,k;
	pindex=find(a,i,j);
	if(pindex>=0)
	{
		pivot=a[pindex];
		k=partition(a,i,j,pivot);
		quicksort(a,i,k-1);
		quicksort(a,k,j);
	}
}

int compare(const void * p,const void * q) {
	int * t1 = (int*)p;
	int * t2 = (int*)q;
	return *t2-*t1;
}

int main()
{
	int n,i,j,k,t_max,t_min,q[1000],t[1000],win,loss;
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
			return 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(int),compare);
	    qsort(q,n,sizeof(int),compare);
		t_max=0;
		t_min=n-1;
		win=loss=0;
		for(i=0;i<n;i++)
		{
			if(t[t_max]>q[i])
			{
				win++;
				t_max++;
			}
			else if(t[t_max]<q[i])
			{
				loss++;
				t_min--;
			}
			else if(t[t_max]==q[i])
			{
				for(j=i+1,k=t_max+1;j<n;j++,k++)
				{
					if(t[k]<=q[j]&&t[t_max]>q[j])
						break;
				}
				if(j<n)
				{
					if(t[t_min]<q[i])
						loss++;
					t_min--;
				}
				else t_max++;
			}
		}
		printf("%d\n",200*(win-loss));
	}
	return 0;
}


void sort(int a[],int n);
int money(int t[],int q[],int n);

void main()
{
	int tj[1001], qw[1001], n = 0, i = 0;
	while(1)
	{
		scanf("%d",&n);
		if(n == 0)
			break;
		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);
		printf("%d\n",money(tj, qw, n));
	}
}

void sort(int a[],int n)
{
	int temp = 0,i = 0, j = 0;
	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;
			}
		}
}

int money(int t[],int q[],int n)
{
	int win = 0, draw = 0, lose = 0;
	int w = 0, j = 0;
	int wend = 0, jend = 0, endw = 0, endj = 0;
	int flag = 0;
	wend = jend = n-1;
	for (w = j = 0; j < n; j++)
	{
		if(q[w] < t[j])
		{
			win++;
			w++;
		}
		else if(q[w] > t[j])
		{
			lose++;
			wend--;
		}

		else if(q[w]==t[j]){
			if(j==jend){
				draw++;
				break;
			}
			for(endw=wend,endj=jend;endj>j;endw--,endj--){
				if(q[endw]>=t[endj]){
					flag=1;
					break;
				}
			}
			if(flag&&t[j]!=q[endw]){
				lose++;
				wend--;
			}
			else{
				draw++;
				w++;
			}
		}
		flag=0;
	}
	return 200*(win-lose);
}


const int maxn=1100;
int a[maxn],b[maxn];
int n;
int count(int d)
{
	int i,j;
	int win=0;
	for (i=d;i<n;i++) if (a[i]>b[i-d]) win++;else if (a[i]<b[i-d]) win--;
	return win-d;
}
int main()
{
	int maxwin;
	int i,j,k;
	while (scanf("%d",&n),n)
	{
		for (i=0;i<n;i++) scanf("%d",a+i);
		for (i=0;i<n;i++) scanf("%d",b+i);
		sort(a,a+n);
		sort(b,b+n);
		maxwin=-n;
		for (i=0;i<n;i++)
		{
			k=count(i);
			if (maxwin<k) maxwin=k;
		}
		printf("%d\n",maxwin*200);
	}
	return 0;
}


int T[1000], Q[1000];
int TT[1000];
int Cmp(const void * e1, const void * e2)
{
	int * p1 = (int *)e1, * p2 = (int * ) e2;
	return *p1 - *p2;
}

int main()
{
	int n;
	while(cin>>n && n)
	{
		for(int i = 0;i < n;i ++)
			cin>>T[i];
		for(int i = 0;i < n;i ++)
			cin>>Q[i];
		qsort(T,n,sizeof(int),Cmp);
		qsort(Q,n,sizeof(int),Cmp);
	int pT,qT,pQ,qQ;
	pT = 0,qT = n - 1,pQ = 0,qQ = n - 1;
	int ans = 0;
	for(int i = 0;i < n;i ++)
	{
		if(T[pT] > Q[pQ])
		{
			ans += 200;
			pT ++;
			pQ ++;
			continue;
		}
		if(T[pT] < Q[pQ])
		{
			ans -= 200;
			pT ++;
			qQ --;
			continue;
		}
		if(T[qT] > Q[qQ])
		{
			ans += 200;
			qT --;
			qQ --;
			continue;
		}
		if(T[qT] < Q[qQ])
		{
			ans -= 200;
			pT ++;
			qQ --;
			continue;
		}
		if(T[pT] > Q[qQ])
			ans += 200;
		else if(T[pT] < Q[qQ])
			ans -= 200;
		pT ++;
		qQ --;
	}

		cout<<ans<<endl;
	}
	return 0;
}


int n;
int x[1000],y[1000];

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

int main(){
	int i;
	int *hx,*hy,*rx,*ry;/* h=head, r=rear */
	int win;

	scanf("%d",&n);
	while(n){
		win = 0;

		for(i=0;i<n;i++)
			scanf("%d",&x[i]);
		for(i=0;i<n;i++)
			scanf("%d",&y[i]);

		qsort(x,n,sizeof(int),myCmp);
		qsort(y,n,sizeof(int),myCmp);

		hx = &x[0];
		hy = &y[0];
		rx = &x[n-1];
		ry = &y[n-1];

		while(hx<=rx){
			if(*hx!=*hy){
				if(*hx>*hy){
					win++;
					hx++;
					hy++;
				}
				else{
					win--;
					rx--;
					hy++;
				}
			}
			else if(*rx!=*ry){
				if(*rx>*ry){
					win++;
					rx--;
					ry--;
				}
				else{
					win--;
					rx--;
					hy++;
				}
			}
			else{
				win += *rx<*hy ? -1 : 0;
				rx--;
				hy++;
			}
		}

		printf("%d\n",win*200);
		scanf("%d",&n);
	}

	return 1;
}


void quicksort(int source[],int n)
{int i,j,t;
     for(j=n-1;j>0;j--)
                     {
                                for(i=0;i<j;i++)
                                {
                                 if(source[i]<source[i+1])
                                 {t=source[i];
                                 source[i]=source[i+1];
                                 source[i+1]=t;
                                  }

                                }
                     }

     }
int main()
{

    int n,m,i;
    int t[1001],q[1001];
        while(1)
   {      scanf("%d",&n);
                     if(n==0) break;
                     else{     for(m=0;m<n;m++)
                        scanf("%d",&t[m]);
                        for(m=0;m<n;m++)
                         scanf("%d",&q[m]);
   quicksort(t,n);
   quicksort(q,n);
   int top1=0,trail1=n-1,top2=0,trail2=n-1,sum=0;
   for(i=1;i<=n;i++)
               { if(t[trail1]>q[trail2])
                                      {sum+=200;
                                      trail1--;
                                      trail2--;}
                 else if(t[trail1]<q[trail2])
                                      {sum-=200;
                                      trail1--;
                                      top2++;
                                      }
                 else if(t[top1]>q[top2])
                                    {sum+=200;
                                      top1++;
                                    top2++;}
                 else
                 if(t[trail1]<q[top2])
                     {sum-=200;
                 trail1--;
                 top2++;}

                 else{
                      trail1--;
                      top2++;
                      }
               }
 printf("%d\n",sum);}
  }
   getchar();
   getchar();

   }


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

int main()
{

	 for(;;){
             	int n=1,r=0,h=0,win=0,lose=0,tie=0,money=0,t1=0,t2=0,q1=0,q2=0;
     scanf("%d",&n);
	if(n==0) break;
	else{

	int *a=NULL,*b=NULL;
		a=(int *)malloc(n*sizeof(int));
		b=(int *)malloc(n*sizeof(int));

	    for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
    qsort(a,n,sizeof(int),Compare);
    for(int i=0;i<n;i++)
	{
		scanf("%d",&b[i]);
	}
	qsort(b,n,sizeof(int),Compare);
	t1=0;t2=n-1;q1=0;q2=n-1;
	win=0;lose=0;money=0;tie=0;

	for(;(t1!=t2)&&(q1!=q2);)
	{
		if (a[t1]>b[q1])
		{
			win++;
			t1++;
			q1++;
			continue;
		}
		else if(a[t2]>b[q2])
			{
				win++;
				t2--;
				q2--;
				continue;
			}
		else if(a[t2]==b[q1])
		{
			tie++;
			t2--;
			q1++;
		}
		else if(a[t2]<b[q1])
		{
			lose++;
			t2--;
			q1++;
		}
	}
	if(a[t1]==b[q1])
	{
		tie++;
	}
	else if(a[t1]>b[q1])
	{
		win++;
	}
	else
	{
		lose++;
	}

    	money=200*win-200*lose;

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

				}
			 }

}


int tt[2000],qq[2000],n;
int main()
{
	int i,j,k=0,headt,tailt,headq,tailq,ans;
	while(scanf("%d",&n) && n)
	{
		ans=0;
		headt=headq=0; tailt=tailq=n;
		for(i=0;i<n;i++) scanf("%d",&tt[i]);
		for(i=0;i<n;i++) scanf("%d",&qq[i]);
		sort(tt,tt+n);
		sort(qq,qq+n);
		while(headt!=tailt)
		{
			if(tt[headt]<qq[headq]) { ans--; headt++; tailq--; continue; }
			if(tt[headt]>qq[headq]) { ans++; headt++; headq++; continue; }
			if(tt[tailt-1]>qq[tailq-1]) { ans++; tailt--; tailq--; continue; }
			if(tt[tailt-1]<qq[tailq-1]) { ans--; headt++; tailq--; continue; }
			if(tt[headt]<qq[tailq-1]) ans--; headt++; tailq--;
		}
		printf("%d\n",ans*200);
	}
}


int Compare(const void *a, const void *b) {
	return *(int *)a - *(int *)b;
}
int main() {
	int n;
	int q[1000],t[1000];
	int i,mon,qmax,tmax,qmin,tmin;
	while (cin>>n) {
		if (n==0) return 0;
		for (i=0;i<n;i++)
			cin>>t[i];
		for (i=0;i<n;i++)
			cin>>q[i];
		mon=0;
		qsort(t,n,sizeof(int),Compare);
		qsort(q,n,sizeof(int),Compare);
		tmin=qmin=0;
		tmax=qmax=n-1;
		for (i=0;i<n;i++) {
			if (t[tmax]>q[qmax]) {
				mon+=200;
				tmax--;
				qmax--;
			}
			else if (t[tmin]>q[qmin]) {
				mon+=200;
				tmin++;
				qmin++;
			}
			else {
				if (t[tmin]!=q[qmax])
					mon-=200;
				tmin++;
				qmax--;
			}
		}
		cout<<mon<<endl;
	}
	return 0;
}


void main()
{
	int t[1001];
	int q[1001];
	int n;
	int ts,te,qs,qe;
	int i,j,temp;
	int win,lose,equal;
	for(;;)
	{
	scanf("%d",&n);
	if(n==0)
	{
		break;
	}
	else
	{
	win=lose=equal=0;
	ts=te=qs=qe=0;
	for(i=0;i<n;i++)
	{
		scanf("%d",&t[i]);
	}
	for(i=0;i<n;i++)
	{
		scanf("%d",&q[i]);
	}
	for(j=0;j<n-1;j++)
	{
		for(i=0;i<n-j-1;i++)
		{
			if(t[i]<t[i+1])
			{
				temp=t[i+1];t[i+1]=t[i];t[i]=temp;
			}
			else{}
			if(q[i]<q[i+1])
			{
				temp=q[i+1];q[i+1]=q[i];q[i]=temp;
			}
		}
	}
	while((lose+equal+win)<n)
	{
		if(t[ts]>q[qs])
		{
			win++;
			ts++;
			qs++;
		}
		else if(t[ts]==q[qs])
		{
			if(t[n-te-1]>q[n-qe-1])
			{
				te++;
				qe++;
				win++;
				continue;
			}
			else if(t[n-te-1]==q[n-qe-1])
			{
				if(t[n-te-1]==q[qs])
				{
					equal++;
					qs++;
					te++;
				}
				else
				{
					lose++;
					qs++;
					te++;
				}
			}
			else
			{
				lose++;
				qs++;
				te++;
			}
		}
		else
		{
				lose++;
				te++;
				qs++;
		}
	}
	}
	printf("%d\n",(win-lose)*200);
	}
}


int comp(const void *p, const void *q)
{
    return (*(int *)q - *(int *)p);
}
int main()
{
 int n[50],tianji[50][1000],qiwang[50][1000],result[50],i,j,ii,jj,max,max0,nmax,cmax,cnmax;
 int tb,tm,qb,qm;
 i=0;
 while(1)
 {scanf("%d",&n[i]);
 if (n[i]==0) break;
 for (j=0;j<n[i];j++)
    scanf("%d",&tianji[i][j]);

 for (j=0;j<n[i];j++)
    scanf("%d",&qiwang[i][j]);
  qsort(tianji[i], n[i], sizeof(int), comp);
  qsort(qiwang[i], n[i], sizeof(int), comp);
  i++;
 }

 for (ii=0;ii<i;ii++)
{   result[ii]=0;
    tb=0;
    tm=n[ii]-1;
    qm=n[ii]-1;
    qb=0;
    for (j=n[ii]-1;j>=tb;j--)
    {

        if(tianji[ii][j]>qiwang[ii][qm])
          {
          tm--;
          qm--;
          result[ii]=result[ii]+200;

          }
          else if (tianji[ii][j]<qiwang[ii][qm])
             {tm--;
             qb++;
             result[ii]=result[ii]-200;;
             }
             else if (tianji[ii][j]==qiwang[ii][qm])
             {
                while(tianji[ii][tb]>qiwang[ii][qb])
                   {tb++;
                   qb++;
                   result[ii]=result[ii]+200;
                   }
                  if(tianji[ii][tb]<qiwang[ii][qb])
                      {tm--;
                      qb++;
                      result[ii]=result[ii]-200;
                      }
                  else if(tianji[ii][tb]==qiwang[ii][qb]&&j>tb)
                      {
                       if(tianji[ii][j]<qiwang[ii][qb])
                       result[ii]=result[ii]-200;
                        qb++;tm--;
                       }

                      }
        }
      printf("%d\n",result[ii]);
      getchar();
      getchar();
      getchar();
    }
return 0;
}


void myrank(int *,int );

int kh[1000], th[1000];

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

 void myrank(int *sz,int n)
{
	int i,j,tem;
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(*(sz+i)<*(sz+j)){
				tem=*(sz+i);
				*(sz+i)=*(sz+j);
				*(sz+j)=tem;
			}
		}
	}
}


int n;
int th[1010],qh[1010];

int comp(const void *lhs,const void *rhs)
{
	return *(int*)rhs - *(int*)lhs;
}

int main()
{
	while(1)
	{
		cin>>n;
		if(n == 0)
			break;
		memset(th,0,sizeof(th));
		memset(qh,0,sizeof(qh));
		for(int i  = 0; i < n; ++ i)
			cin>>th[i];
		for(int i = 0; i < n; ++ i)
			cin>>qh[i];

		qsort(qh,n,sizeof(int),comp);
		qsort(th,n,sizeof(int),comp);

		int sum = 0;
		int max = -1000 * 200;
		for(int k = 0; k < n; ++ k)
		{
			sum = 0;
			int count = 0;
			for(int i = 0; i < n; ++ i)
			{
				if(th[(i - k + n) % n] > qh[i])
				{
					sum += 200;
					++ count;
				}
				else if(th[(i - k + n) % n] < qh[i])
					sum -= 200;
			}
			if(sum > max)
				max = sum;
			if(count == n - k)
				break;
		}
		cout<<max<<endl;
	}
}


int n, s1[MN], s2[MN];

int Cmp(int a, int b)
{
    if(s1[a] > s2[b])   return 200;
    if(s1[a] == s2[b]) return 0;
    return -200;
}

int main()
{
    int i , j, ans, k;
    while(scanf("%d", &n), n) {
        for(i = 0; i < n; i++)
            scanf("%d", s1 + i);
        for(i = 0; i < n ;i++)
            scanf("%d", s2 + i);
        sort(s1, s1 + n);
        sort(s2, s2 + n);
        ans = -1000000;

        for(i = 0; i < n; i++) {
            k = 0;
            for(j = i; j < n; j++)
                k += Cmp(j, j - i);
            k -= 200 * i;
            ans = max(ans, k);
        }
        printf("%d\n", ans);
    }
}


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 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 ();
}


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 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 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;
}


int cmpsmall(const void *e1, const void *e2)
{
	const int *i1=(const int *)e1;
	const int *i2=(const int *)e2;
	return *i1-*i2;
}

int main()
{
	int n;
	int tian[1005], king[1005];
	while(cin>>n && n>0)
	{
		for(int i=0; i<n; i++)
			cin>>tian[i];
		for(int i=0; i<n; i++)
			cin>>king[i];

		qsort(tian,n,sizeof(int),cmpsmall);
		qsort(king,n,sizeof(int),cmpsmall);

		int tianSlow=0, tianFast=n-1;
		int kingSlow=0, kingFast=n-1;
		int win=0, lose=0, draw=0;
		while(tianSlow<tianFast && kingSlow<kingFast)
		{
			// ????????????????????
			if(tian[tianSlow]>king[kingSlow])
			{
				win++;
				tianSlow++;
				kingSlow++;
				continue;
			}
			// ????????????????????????????
			else if(tian[tianSlow]<king[kingSlow])
			{
				lose++;
				tianSlow++;
				kingFast--;
				continue;
			}
			// ?????????????????????
			else if(tian[tianFast]>king[kingFast])
			{
				win++;
				tianFast--;
				kingFast--;
				continue;
			}
			// ??????????????????????????????????
			else if(tian[tianFast]<king[kingFast])
			{
				lose++;
				tianSlow++;
				kingFast--;
				continue;
			}
			// ????????????????????????????????
			else
			{
				if(tian[tianSlow]<king[kingFast])
					lose++;
				else
					draw++;
				tianSlow++;
				kingFast--;
				continue;
			}
		}

		if(tian[tianSlow]<king[kingSlow])
			lose++;
		else if(tian[tianSlow]==king[kingSlow])
			draw++;
		else
			win++;

		cout<<(win-lose)*200<<endl;
	}
	return 0;
}


int compare(const void*elem1,const void*elem2)
{
    int *p1;
    int *p2;
    p1=(int*)elem1;
    p2=(int*)elem2;
    return(*p2)-(*p1);
}
main()
{
     for(int j=0;;j++)
   {
   int n,a=0,b=0;
   scanf("%d",&n);
   if(n!=0)
   {
     int*f=(int*)malloc(n*sizeof(int));
     for(int i=0;i<n;i++)
     {
             scanf("%d",&f[i]);
     }
     qsort(f,n,sizeof(int),compare);
     int*g=(int*)malloc(n*sizeof(int));
     for(int i=0;i<n;i++)
     {
             scanf("%d",&g[i]);
     }
      qsort(g,n,sizeof(int),compare);
      int k=0,c=0,h=n-1,x=n-1,s=0;
      for(;(a+b+s)!=n;)
      {
              if(f[k]>g[c])
              {
                a++;
                k++;
                c++;
                }
              else if(f[k]<=g[c])
              {
                   if(f[h]>g[x])
                   {
                      a++;
                      h--;
                      x--;
                   }
                   else if(f[h]<=g[x])
                   {
                      if(f[h]<g[c])
                      {
                      b++;
                      h--;
                      c++;
                      }
                      else
                      {
                      s++;
                      h--;
                      c++;
                      }
                   }
              }
      }
        int y=0;
        y=200*a-200*b;
        printf("%d\n",y);
   }
   if(n==0)
   break;
}
   getchar();
   getchar();
}


int n,k;
int q[1000];
int t[1000];
int res;
int sum = 1;

int mycmp(const void *a,const void * b)
{
	return *((int *)b) - *((int *)a);
}
int main()
{
	while(cin >> n)
	{
		if(n == 0)
			break;
		for(int i = 0;i < n;i++)
			cin >> t[i];
		for(int i = 0;i < n;i++)
			cin >> q[i];
		qsort(t,n,sizeof(int),mycmp);
		qsort(q,n,sizeof(int),mycmp);
		int x = 0;
		int xx = n -1;
		int yy = n - 1;
		int y = 0;
		int p = 0;
		int sum = 0;
		while(p < n)
		{
			if(t[x] <q[y])
			{
				sum -=200;
				y++;
				xx--;
			}
			else if(t[x]==q[y])
			{
				if(t[xx] > q[yy])
				{
					xx--;
					yy--;
					sum += 200;
				}
				else if(t[xx] < q[yy])
				{
					xx--;
					y++;
					sum-=200;
				}
				else if(t[xx] == q[yy])
				{
					if(t[xx] == q[y])
					{
						xx--;
						y++;
					}
					else
					{
						sum-=200;
						xx--;
						y++;
					}
				}
			}
			else if(t[x] > q[y])
			{
				x++;
				y++;
				sum += 200;
			}
			p++;
		}
		cout << sum << endl;
	}
}


int sa[2000];
int sb[2000];

int main()
{
	int n;
	while(scanf("%d",&n) && n)
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&sa[i]);
		}
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&sb[i]);
		}
		sort(&sa[1],&sa[n+1]);
		sort(&sb[1],&sb[n+1]);

		int stpA = 1;
		int edpA = n;
		int stpB = 1;
		int edPB = n;
		int result = 0;

		for(int i=1;i<=n;i++)
		{
			if(sa[stpA] > sb[stpB])
			{
				result += 200;
				stpA++;
				stpB++;
			}
			else if(sa[edpA] > sb[edPB])
			{
				result += 200;
				edpA--;
				edPB--;
			}
			else
			{
				if(sa[stpA] > sb[edPB])
				{
					result += 200;
				}
				else if(sa[stpA] < sb[edPB])
				{
					result -= 200;
				}
				stpA ++;
				edPB --;
			}
		}
		cout<<result<<endl;
	}
	return 0;
}


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

int main()
{
    int n;
    long m[100];
    int a[1000],b[1000];
    int i;
    int win;
    int lose;
    int t=0;
    int flag=0;
    scanf("%d",&n);
    while(n)
    {
        flag++;
        lose=win=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(int),compare);
        qsort(b,n,sizeof(int),compare);

        int *aj=&a[0];
        int *ai=&a[n-1];
        int *bj=&b[0];
        int *bi=&b[n-1];
        while(ai-aj>=0)
        {
            if (*ai>*bi)
            {
                ai--;
                bi--;
                win++;
            }
            else if (*aj>*bj)
            {
                aj++;
                bj++;
                win++;
            }
            else
            {
                if (*aj<*bi)
                lose++;
                aj++;
                bi--;
            }

        }
        m[t]=200*(win-lose);
        t++;
        scanf("%d",&n);
    }
    for (t=0;t<flag;t++)
    {
        printf("%ld\n",m[t]);
    }
    return 0;
}


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

int main (int argc, const char * argv[]) {
    int n;
	int tian[1001];
	int king[1001];
	scanf("%d",&n);
	int finish=0;
	if (n==0) {
		finish=1;
	}
	while (finish==0) {
		if (n==0) {
			finish=1;
			break;
		}
		int i;
		for (i=0; i<n; i++) {
			scanf("%d",&tian[i]);
		}
		for (i=0; i<n; i++) {
			scanf("%d",&king[i]);
		}
		qsort(tian, n, sizeof(int), cmp);
		qsort(king, n, sizeof(int), cmp);
		int ltian,rtian,lking,rking;
		ltian=0;
		rtian=n-1;
		lking=0;
		rking=n-1;
		int money=0;
		for (i=0; i<n; i++) {
			if (tian[rtian]>king[rking]) {
				money+=200;
				rtian--;
				rking--;
			}
			else if(tian[ltian]>king[lking])
			{
				money+=200;
				ltian++;
				lking++;
			}
			else {
				if (tian[ltian]>king[rking]) {
					money+=200;
					ltian++;
					rking--;
				}
				else if(tian[ltian]==king[rking])
				{
					ltian++;
					rking--;
				}
				else if(tian[ltian]<king[rking])
				{
					money-=200;
					ltian++;
					rking--;
				}
			}
		}
		printf("%d",money);
		scanf("%d",&n);
		if (n!=0) {
			printf("\n");
		}
		else {
			finish=1;
		}
	}
    return 0;
}


int a[1000];
int b[1000];
int n;

int mycompare(const void *p1,const void *p2)
{
	int *a1;
	int *a2;

	a1 = (int *)p1;
	a2 = (int *)p2;

	return *a2 - *a1;
}

int main()
{
	int i,j,k1,k2,z;
	int total;
	int num1,num2;
	while (true)
	{
		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),mycompare);
		qsort(b,n,sizeof(int),mycompare);
		total = 0;
		i = 0; j = 0;
		num1 = n - 1;
		num2 = n - 1;

		while (i <= num1)
		{
			if (a[i] > b[j])
			{
				total = total + 200;
				i ++;
				j ++;
			}
			else
			{
				if (a[i] < b[j])
				{
				    total = total - 200;
					num1 --;
					j ++;
				}
				else
				{
					for (k1 = num1,k2 = num2;k1 > i;k1 --,k2 --)
					{
						if (a[k1] > b[k2])
						{
							total = total + 200;
							num1 --;
							num2 --;
						}
						else
						{
							if (a[k1] < b[j]) total = total - 200;
							num1 = k1;
							num2 = k2;
							j ++;
							break;
						}
					}
					num1 --;
				}

			}
		}
		cout << total << endl;
	}
	return 0;
}


/*
 * tianjisaima.cpp
 *
 *  Created on: 2012-3-19
 *      Author: Hijack
 */

const int MAX = 1005;
int a[MAX],b[MAX];
int cmp(int a, int b)
{
	return a > b;
}
int main(){
    int n,i;
    while(cin>>n && n)
    {
    	for(i = 0; i < n; i++)
    		cin>>a[i];
    	for(i = 0; i < n; i++)
    		cin>>b[i];
    	sort(a,a+n,cmp);
    	sort(b,b+n,cmp);
        int num = 0;
        int al = 0, bl = 0;
        int ar = n-1,br = n-1;
    	while(al <= ar)
    	{
    		if(a[ar] > b[br])
    		{
    			ar--;
    			br--;
    			num += 200;
    		}
    		else if(a[ar] < b[br])
    		{
    			ar--;
    			bl++;
    			num -= 200;
    		}
    		else if(a[ar] == b[br])
    		{
    			if(a[al] > b[bl])
    			{
    				al++;
    				bl++;
    				num += 200;
    			}
    			else if(a[al] < b[bl])
    			{
    				ar--;
    				bl++;
    				num -= 200;
    			}
    			else if(a[al] == b[bl])
    			{
    				if(a[ar] == b[bl])
    				{
    					ar--;
    					bl++;
    				}
    				else
    				{
    					ar--;
    					bl++;
    					num -= 200;
    				}
    			}
    		}
    	}
    	cout<<num<<endl;

    }

}


int a[1000],b[1000];

int main()
{
	//freopen("in.txt","r",stdin);
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++)
			cin>>b[i];
		for(int i=0;i<n;i++)
			cin>>a[i];
		sort(a,a+n);
		sort(b,b+n);
		int re=0;
		int a1=0,a2=n-1;
		int b1=0,b2=n-1;
		int pa,pb;
		for(int i=0;i<n;i++){
			if(b[b1]>a[a1]){
				pa=a1++;
				pb=b1++;
			}else if(b[b2]>a[a2]){
				pa=a2--;
				pb=b2--;
			}else{
				pa=a2--;
				pb=b1++;
			}
			if(b[pb]>a[pa]){
				re++;
			}else if(b[pb]<a[pa]){
				re--;
			}
		}
		cout<<re*200<<endl;
	}

	return 1;
}


int Compare(const void*elem1,const void*elem2)
{
    int*p1,*p2;
    p1=(int*)elem1;
    p2=(int*)elem2;
    return(*p2)-(*p1);
}
main()
{
    int i;
    for(i=0;;i++)
    {
        int n;
        scanf("%d",&n);
        if(n==0)
        break;
        else
        {
        int a[n],b[n];
        int j;
        for(j=0;j<n;j++)
        scanf("%d",&a[j]);
        int k;
        for(k=0;k<n;k++)
        scanf("%d",&b[k]);
        qsort(a,n,sizeof(int),Compare);
        qsort(b,n,sizeof(int),Compare);
         j=0;
         k=0;
        int p=0;
        int q=0;
        int t=0;
        int tailt=n-1;
        int tailq=n-1;
        for(;(p+q+t)!=n;)
        {
            if(a[j]>b[k])
            {
                t++;
                j++;
                k++;
            }
            else if(a[j]<b[k])
            {
                tailt--;
                k++;
                q++;
            }
            else if(a[j]==b[k])
            {
                if(a[tailt]>b[tailq])
                {
                    t++;
                    tailt--;
                    tailq--;
                }
                else if(a[tailt]==b[tailq])
                {
                    if(a[tailt]==b[k])
                    {
                        p++;
                        tailt--;
                        k++;
                    }
                    else
                    {
                        q++;
                        tailt--;
                        k++;
                    }
                }
                else if(a[tailt]<b[tailq])
                {
                    q++;
                    tailt--;
                    k++;
                }
            }
        }
        int profit;
        if(t==q)
        printf("0\n");
        else if(t>q)
        {
            profit=200*(t-q);
            printf("%d\n",profit);
        }
        else if(t<q)
        {
            profit=200*(q-t);
            printf("-%d\n",profit);
        }
        }
    }
}


int N,array[2][1001];
int benefit[1001][1001]={0};

int main()
{
	int i,j,cnt=0;
	while(scanf("%d",&N)!=EOF&&N)
	{
		++cnt;
		for(i=0;i<N;i++) scanf("%d",array[0]+i);
		for(i=0;i<N;i++) scanf("%d",array[1]+i);
		sort(array[0],array[0]+N);
		sort(array[1],array[1]+N);
		if(array[0][0]<array[1][N-1]) benefit[1][0]=-200;
		else if(array[0][0]>array[1][N-1]) benefit[1][0]=200;
		else benefit[1][0]=0;
		if(array[0][N-1]<array[1][N-1]) benefit[1][1]=-200;
		else if(array[0][N-1]>array[1][N-1]) benefit[1][1]=200;
		else benefit[1][1]=0;
		for(i=2;i<=N;i++)
			for(j=0;j<=i;j++)
			{
				int tmp1=-INF,tmp2=-INF;
				if(i>j)
				{
					tmp1=benefit[i-1][j];
					if(array[0][i-j-1]>array[1][N-i]) tmp1+=200;
					else if(array[0][i-j-1]<array[1][N-i]) tmp1-=200;
				}
				if(j>0)
				{
					tmp2=benefit[i-1][j-1];
					if(array[0][N-j]>array[1][N-i]) tmp2+=200;
					else if(array[0][N-j]<array[1][N-i]) tmp2-=200;
				}
				benefit[i][j]=tmp1;
				if(benefit[i][j]<tmp2) benefit[i][j]=tmp2;
			}
		int m_benefit=-INF;
		for(j=0;j<=N;j++)
			if(m_benefit<benefit[N][j]) m_benefit=benefit[N][j];
		printf("%d\n",m_benefit);
	}
	return 0;
}


int main()
{
	int n, i, leftJi, leftQi, rightJi, rightQi, tianJi[1000], kingQi[1000], result;

	for (cin >> n;  n > 0; cin >> n)
	{
		for (i = 0; i < n; ++i) cin >> tianJi[i];
		for (i = 0; i < n; ++i) cin >> kingQi[i];

		sort(tianJi, tianJi + n);
		sort(kingQi, kingQi + n);

		result = 0;
		leftJi = leftQi = 0;
		rightJi = rightQi = n - 1;

		while (leftJi <= rightJi)
		{
			if (tianJi[leftJi] > kingQi[leftQi])
			{
				++leftJi;
				++leftQi;
				result += 200;
				continue;
			}

			if (tianJi[rightJi] > kingQi[rightQi])
			{
				--rightJi;
				--rightQi;
				result += 200;
				continue;
			}

			if (tianJi[leftJi] < kingQi[rightQi]) result -= 200;
			++leftJi;
			--rightQi;
		}

		cout << result << endl;
	}
	return 0;
}


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

int match(int* tianji,int* king,int n){
	if(n==0)return 0;
	if(tianji[n-1]>king[n-1])return match(tianji,king,n-1)+200;//??
	else if(tianji[n-1]<king[n-1])return match(tianji,king+1,n-1)-200;//??
	else{//tianji[n-1]==king[n-1]
		if(tianji[0]>king[0])return match(tianji+1,king+1,n-1)+200;//??
		else{
			if(tianji[n-1]==king[0])return 0;
			else return match(tianji,king+1,n-1)-200;//??
		}
	}
}

int main(){
	int tianji[MAX];
	int king[MAX];
	int n;
	int i;

	while(cin>>n){
		if(n==0)break;
		for(i=0;i<n;i++)cin>>tianji[i];
		for(i=0;i<n;i++)cin>>king[i];
		qsort(tianji,n,sizeof(int),mycmp);
		qsort(king,n,sizeof(int),mycmp);
		cout<<match(tianji,king,n)<<endl;
	}
	return 0;
}


int q[1000];
int t[1000];

int main(){
  int n;
  int i;
  int qs,qe;
  int ts,te;
  while(cin>>n && n!=0){
    for(i=0;i<n;i++)
      cin>>t[i];
    for(i=0;i<n;i++)
      cin>>q[i];
    qs=ts=0;
    qe=te=n-1;
    sort(q,q+n);
    sort(t,t+n);
    int price=0;
    while(n--){
      if(t[te]>q[qe]){
        price++;
        te--;
        qe--;
      }
      else if(t[ts]>q[qs]){
        price++;
        qs++;
        ts++;
      }
      else
      {
        if(t[ts]>q[qe]){
          price+=(qe+1-qs);
          break;
        }
        else if(t[ts]<q[qe])
          price--;
        ts++;
        qe--;
      }
    }
    cout<<price*200<<endl;

    }
  return 0;
}


int compare(const void * elem1,const void * elem2)
{
    int *p1,*p2;
    p1=(int*)elem1;
    p2=(int*)elem2;
    return (*p2)-(*p1);
}
main()
{
      int c;
      for(c=1;;c++)
      {
          int n;
          scanf("%d",&n);
          if (n==0)
              break;
          else
          {
              int d,match,f1=0,f2=0,b1=0,b2=0,money,w=0,t=0,l=0;
              int T[n],Q[n];
              for(d=0;d<n;d++)
              {
                  scanf("%d",&T[d]);
              }
              qsort(T,n,sizeof(int),compare);
              for(d=0;d<n;d++)
              {
                  scanf("%d",&Q[d]);
              }
              qsort(Q,n,sizeof(int),compare);
              for(match=0;match<n;match++)
              {
                  if(T[f1]>Q[f2])
                  {
                        w++;
                        f2++;
                        f1++;
                  }
                  else
                  {
                       if(T[n-1-b1]>Q[n-1-b2])
                       {
                             w++;
                             b1++;
                             b2++;
                       }
                       else
                       {
                             if(T[n-1-b1]==Q[f2])
                                  break;
                             else
                             {
                                 l++;
                                 b1++;
                                 f2++;
                             }
                       }
                  }
              }
              money=200*(w-l);
              printf("%d\n",money);
          }
      }
}


int cmp(const void *p1,const void *p2)
{
	return *((int *)p2)-*((int *)p1);
}
int main()
{
	int a[1000],b[1000],la,ra,lb,rb,i,n,ans;
	while(scanf("%d",&n),n)
	{
		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),cmp);
		qsort(b,n,sizeof(int),cmp);

		ans=0;lb=la=0;ra=rb=n-1;
		while(la<=ra)
		{
			if(a[la]>b[lb])ans=ans+200,la++,lb++;
			else if(a[ra]>b[rb])ans+=200,ra--,rb--;
			else
			{
				if(a[ra]<b[lb])ans-=200;
				ra--,lb++;
			}
		}
		printf("%d\n",ans);
	}
}


int main()
{
	int n, a[1002], b[1002], first1, first2, last1, last2, prize, i;
	while(cin>>n)
	{
		if(n == 0)
			break;
		first1 = first2 = 0;
		last1 = last2 = n-1;
		prize = 0;
		for(i = 0; i < n; i++)
			scanf("%d", &a[i]);
		for(i = 0; i < n; i++)
			scanf("%d", &b[i]);
		sort(a, a + n);
		sort(b, b + n);
		while(first1 <= last1)
		{
			if(a[first1] > b[first2])
			{
				prize += 200;
				first1++;
				first2++;
			}
			else if(a[first1] < b[first2])
			{
				prize -= 200;
				first1++;
				last2--;
			}
			else
			{
				while(first1 <= last1)
				{
					if(a[last1] > b[last2])
					{
						prize += 200;
						last1--;
						last2--;
					}
					else if(a[last1] <= b[last2])
					{
						if(a[first1] < b[last2])
							prize -= 200;
						else if(a[first1] > b[last2])
							prize += 200;
						first1++;
						last2--;
						break;
					}
				}
			}
		}
		cout<<prize<<endl;
	}
	return 0;
}


//??????
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;
    scanf("%d",&n);
    if (n==0) break;
      int *tian=(int *)malloc(n*sizeof(int));
      int *qi=(int *)malloc(n*sizeof(int));
      for(int i=0;i<n;i++)
      {
              scanf("%d",tian+i);
      }
      for(int i=0;i<n;i++)
      {
              scanf("%d",qi+i);
      }
      f(tian,n);
      f(qi,n);

      int t=0,q=0,qmax=n-1,tmax=n-1,win=0;
      for(;n>=1;n--)
      {
              if(*(tian+t)>*(qi+q))
              {
                   win++;
                   t++;
                   q++;
              }
              else if(*(tian+t)==*(qi+q))
              {
                   if(*(tian+tmax)>*(qi+qmax))
                   {
                       win++;
                       tmax--;
                       qmax--;
                   }
                   else if(*(tian+tmax)<=*(qi+qmax))
                   {
                       if(*(tian+t)<*(qi+qmax)) win--;
                       qmax--;
                       t++;
                   }

              }
              else if(*(tian+t)<*(qi+q))
              {
                  win--;
                  t++;
                  qmax--;
              }
      }
      printf("%d\n",win*200);
    }

}


int tianji[1000];
int qiwang[1000];

int cmp(const void *a, const void *b)
{
	return -(*(int *)a - *(int *)b);
}
int main()
{
	int n;
	while(cin >> n)
	{
		if (n == 0)
			break;
		int money = 0;
		for (int i = 0; i < n; i++)
			cin >> tianji[i];
		for (int i = 0; i < n; i++)
			cin >> qiwang[i];
		qsort(tianji, n, sizeof(int), cmp);
		qsort(qiwang, n, sizeof(int), cmp);

		int tp = 0, tq = n-1, qp = 0, qq = n-1;

		while (tp <= tq)
		{
			while (tianji[tp] > qiwang[qp] && tp <= tq)
			{
				money += 200;
				tp++;
				qp++;
			}
			while(tianji[tq] > qiwang[qq] && tp <= tq)
			{
				money += 200;
				tq--;
				qq--;
			}
			if (tianji[tp] <= qiwang[qp] && tp <= tq)
			{
				if (tianji[tq] < qiwang[qp])
					money -= 200;
				tq--;
				qp++;
			}
		}
		cout << money << endl;

	}
}


void main()
{

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

		count++;

		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;
		for(i=0;i<n;i++)
		{
			if(a[i]>b[i])
			{
				choose[i]=i;
				bchoose[i]=1;
				win++;
			}
		}
		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;
		/*if(count==9)
		{
			money+=200;
		}*/
		printf("%d\n",money);

	}
}


int main()
{
    int n;
    int a[1005];
    int b[1005];
    int count,i,j,x,y;
    while(cin>>n){
        if(n==0)break;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        count=0;
        for(i=0;i<n;i++)
            cin>>a[i];
        for(i=0;i<n;i++)
            cin>>b[i];
        sort(a,a+n);
        sort(b,b+n);
        x=n-1,y=n-1,i=0,j=0;
        while(n--){
            if(a[x]>b[y]){
                x--;
                y--;
                count++;
            }
            else if(a[i]>b[j]){
                i++;
                j++;
                count++;
            }
            else if(a[i]<b[y]){
                i++;
                y--;
                count--;
            }
        }
        cout<<count*200<<endl;
    }
    return 0;
}


//?????10?2 3 4 5 6 7 8 9 10 11?1 2 3 4 5 6 7 8 9 11????

main ()
{
    int qw[1000],tj[1000];
    int n,i,j,k,num,temp,win,pt,lose,btmtj,btmqw,toptj,topqw;
    scanf("%d",&n);
    while (n!=0)
    {
          n--;
          for (i=0;i<=n;i++) scanf("%d",&tj[i]);
          for (i=0;i<=n;i++) scanf("%d",&qw[i]);

          for (i=0;i<=n;i++)
              for (j=i;j<=n;j++)
              {
                  if (tj[i]>tj[j])
                  {
                     temp=tj[i];
                     tj[i]=tj[j];
                     tj[j]=temp;
                  }
                  if (qw[i]>qw[j])
                  {
                     temp=qw[i];
                     qw[i]=qw[j];
                     qw[j]=temp;
                  }
              }

          win=0;num=0;pt=0;lose=0;

          btmtj=btmqw=0;toptj=topqw=n;
          while ((topqw>=btmqw)&&(toptj>=btmtj))
          {
                if (qw[btmqw]<tj[btmtj])
                {
//printf("%d %d win\n",btmqw,btmtj);
                   btmqw++;
                   btmtj++;
                   win++;
                   continue;
                }
                if (qw[btmqw]>tj[btmtj])
                {
//printf("%d %d lose\n",topqw,btmtj);
                   topqw--;
                   btmtj++;
                   lose++;
                   continue;
                }
                if (qw[topqw]<tj[toptj])
                {
//printf("%d %d win\n",topqw,toptj);
                   topqw--;
                   toptj--;
                   win++;
                   continue;
                }
                if (qw[topqw]>=tj[toptj])
                {
//printf("%d %d lose\n",topqw,btmtj);
                   if (qw[topqw]!=tj[btmtj]) lose++;
                   topqw--;
                   btmtj++;
                   continue;
                }
          }

          /*for (i=0;i<=n;i++)
          {
              for (j=pt;j<=n;j++)
              {
                  if (qw[i]<tj[j])
                  {
                     pt=j+1;
                     num++;
                     if(qw[i]!=tj[j]) win++;
                     break;
                  }
              }
              if (pt==n+1) break;
          }*/

          n++;
          printf("%d\n",win*200-lose*200);
          scanf("%d",&n);
    }
}


int n,tj[1000],qw[1000];

void input(int a[])
{
	int i,j,t;
	for (i=0;i<n;i++)
	{
		scanf ("%d",a+i);
		for (j=i;j>0;j--)
			if (a[j]>a[j-1]) { t=a[j]; a[j]=a[j-1]; a[j-1]=t; }
			else break;
	}
}

horse()
{
	int m=0,tf=0,qf=0,ts=n-1,qs=n-1;
	while (tf<=ts)
	{
		if (tj[tf]>qw[qf]) { m++; tf++; qf++; }
		else if (tj[tf]<qw[qf]) { m--; ts--; qf++; }
		else
		{
			if (tj[ts]>qw[qs]) { m++; ts--; qs--; }
			else if (tj[ts]<qw[qs]) { m--; ts--; qf++; }
			else
			{
                if (tj[ts]<qw[qf]) { m--; ts--; qf++; }
                else return m;
			}
		}
	}
	return m;
}

main()
{
	int money;
	scanf ("%d",&n);
	while (n)
	{
		input (tj);
		input (qw);
		money = horse ()*200;
		printf ("%d\n",money);
		scanf ("%d",&n);
	}
}


int src[1000], tgt[1000];

int main()
{
	int n;
	while(scanf("%d", &n) == 1 && n > 0)
	{
		for(int i = 0; i < n; ++i)
			scanf("%d", &src[i]);
		for(int i = 0; i < n; ++i)
			scanf("%d", &tgt[i]);
		sort(src, src + n);
		sort(tgt, tgt + n);
		int si = 0, sj = n-1;
		int ti = 0, tj = n-1;
		int gain = 0;
		while(si <= sj)
		{
			int a = src[si], b = src[sj];
			int c = tgt[ti], d = tgt[tj];
			if(a < c)
			{
				--gain;
				++si;
				--tj;
			}
			else if(a > c)
			{
				++gain;
				++si;
				++ti;
			}
			else if(b < d)
			{
				--gain;
				++si;
				--tj;
			}
			else if(b > d)
			{
				++gain;
				--sj;
				--tj;
			}
			else
			{
				if(a < d)
					--gain;
				++si;
				--tj;
			}
		}
		printf("%d\n", gain * 200);
	}
}