int kh[1000], th[1000];

int cmp(const void *a, const void *b)
{
    return (*(int *)b-*(int *)a);
}
int main(void)
{
    int N, i, j, k, mxt, mxk, w;
    while(scanf("%d", &N),N)
    {
        for(i = 0; i < N; ++i)
            scanf("%d", &th[i]);
        qsort(th, i, sizeof(th[0]), cmp);
        for(i = 0; i < N; ++i)
            scanf("%d", &kh[i]);
        qsort(kh, i, sizeof(kh[0]), cmp);

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


static int cmp(const void *a, const void *b)
{
	return *(int *)b - *(int *)a;
}
int main()
{
	int n=1;

	while(n!=0)
	{
		int *a,*b,t,s,j,p,c,tk,tm,qk,qm;
		int *p3,*p4;
		scanf("%d",&n);
		if (n==0) break;
		a=(int *)malloc((n)*sizeof(int));
		b=(int *)malloc((n)*sizeof(int));
		p3=(int *)malloc((n)*sizeof(int));
		p4=(int *)malloc((n)*sizeof(int));
		t=0;
		p=0;
		j=0;
		s=0;
		for(int i=0;i<n;i++) scanf("%d",&a[i]);
		for(int i=0;i<n;i++) scanf("%d",&b[i]);
		qsort(a,n,sizeof(int),cmp);
		qsort(b,n,sizeof(int),cmp);
		tk=0;
		tm=n-1;
		qk=0;
		qm=n-1;
		for (;tk<=tm;)
		{
			if (a[tm]>b[qm])
			{
				t++;
				tm--;
				qm--;
			}
			else if(a[tm]<b[qm])
			{
				s++;
				tm--;
				qk++;
			}
			else if(a[tk]>b[qk])
			{
				t++;
				tk++;
				qk++;
			}
			else if (a[tk]<b[qk])
			{
				s++;
				tm--;
				qk++;
			}
			else if(a[tm]<b[qk])
			{
				s++;
				tm--;
				qk++;
			}

			else
			{
				tm--;
				qk++;
			}
		}
		printf("%d\n",t*200-s*200);
		free(a);
		free(b);
		free(p3);
		free(p4);
	}
	return 0;
}


int main()
{
	int ma(int n);
	int n;
	for(;1;){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		ma(n);
	}
	return 0;
}
int ma(int n){
	int paixu(int tian[],int wang[],int n);
	int sum=0,i,a=1;
	int wang[1001],tian[1001];
	int endw,endt,staw=0,stat=0;
	endw=n-1;
	endt=n-1;
	for(i=0;i<n;i++){
		scanf("%d",&tian[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&wang[i]);
	}
	paixu(tian,wang,n);
	for(;stat<=endt;){
		if(tian[stat]>wang[staw]){
			sum+=200;
			staw++;
			stat++;
		}
		else if(tian[stat]<wang[staw]){
			sum-=200;
			endt--;
			staw++;
		}
		else if(tian[stat]==wang[staw]){
			for(;(a==1);){
				if(tian[endt]>wang[endw]){
					sum+=200;
					endt--;
					endw--;
				}
				else if(tian[endt]<=wang[endw]){
					if(tian[endt]<wang[staw]){
						sum-=200;
					}
					staw++;
					endt--;
					a=0;
				}
			}
			a=1;
		}
	}
	printf("%d\n",sum);
	return 0;
}
int paixu(int tian[],int wang[],int n){
	int i,j,b;
	for(i=0;i<n;i++){
		for(j=n-1;j>i;j--){
			if(tian[j]>tian[j-1]){
				b=tian[j];
				tian[j]=tian[j-1];
				tian[j-1]=b;
			}
			if(wang[j]>wang[j-1]){
				b=wang[j];
				wang[j]=wang[j-1];
				wang[j-1]=b;
			}
		}
	}
	return 0;
}


long a[1000],b[1000];
int cmp(const void *a,const void *b )
{
    return(*(long*)a)-(*(long*)b);
}

main()
{
   long n;
   while(1)
   {
      long sum=0,i,j,end1,end2;
      scanf("%ld",&n);
      if(n==0) break;
      for(i=0;i<n;i++)
      scanf("%ld",&a[i]);
      for(i=0;i<n;i++)
      scanf("%ld",&b[i]);
      qsort(a,n,sizeof(long),cmp);
      qsort(b,n,sizeof(long),cmp);
      j=0;
      for(i=j=n-1,end1=end2=0;j>=end2&&i>=end1;j--)
      {
      if(a[i]>b[j])
      {
      sum++;
      i--;
      }
      else if(a[i]<b[j])
      {
      sum--;end1++;
      }
      else
      {
         if(a[end1]>b[end2])//a??????b????
         {
         sum++;end1++;end2++; j++;
         }
         else if(a[end1]<b[end2])
         {
         sum--;end1++;
         }
         else
         {
            if(a[end1]==b[j])
            {
            end1++;
            }
            else
            {
            sum--;
            end1++;
            }
         }
      }
   }
printf("%d\n",sum*200);
}
return 0;
}


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

main()
{
    int *p1,*p2;
    int n,i,j,k,s;
    do {
        scanf("%d",&n);
        if(n!=0)
        {
                  p1=(int*)malloc(n*sizeof(int));
                  p2=(int*)malloc(n*sizeof(int));
                  for(i=0;i<n;i++)scanf("%d",&p1[i]);
                  for(i=0;i<n;i++)scanf("%d",&p2[i]);
                  qsort(p1, n, sizeof(int), compare);
                  qsort(p2, n, sizeof(int), compare);
                  for(i=0,s=0;i<n;i++)
                  {
                                  if(p1[i]>p2[i])s++;
                                  else if(p1[i]==p2[i])
                                  {
                                       if(i==n-1)break;
                                       else {
                                            for(k=n-1;k>i;k--)
                                       {
                                            if(p1[k]>p2[k])
                                            {
                                                           s++;
                                                           for(j=n-2;j>=i;j--)p1[j+1]=p1[j];
                                                           for(j=n-2;j>=i;j--)p2[j+1]=p2[j];
                                                           i++;
                                            }
                                            else
                                            {
                                                 if(p1[i]<p2[k])s--;
                                                 for(j=n-2;j>=i;j--)p2[j+1]=p2[j];
                                                 break;
                                            }
                                       }
                                       }
                                       }
                                  else{
                                       s--;
                                       for(j=n-2;j>=i;j--)p2[j+1]=p2[j];
                                  }
                  }
                  printf("%d\n",s*200);
        }
        }
    while(n!=0);
}


short int n;
short int tianji[1010];
short int qiwang[1010];
int main()
{
	while(scanf("%d",&n))
	{
		if(n == 0)
			break;
		for(int i = 0 ;i < n; i++)
			scanf("%d",&tianji[i]);
		for(int i = 0 ;i < n; i++)
			scanf("%d",&qiwang[i]);
		sort(tianji,tianji+n);
		sort(qiwang,qiwang+n);
		short int tianjigood, qiwanggood, tianjibad,qiwangbad;
		tianjigood = qiwanggood= n-1;
		tianjibad = qiwangbad = 0;
		short int cnt = 0;
		while(tianjigood >= tianjibad)
		{
			if(tianji[tianjibad] > qiwang[qiwangbad])
			{
				cnt++;
				tianjibad++;
				qiwangbad++;
				continue;
			}
			if(tianji[tianjibad] < qiwang[qiwangbad])
			{
				cnt--;
				tianjibad++;
				qiwanggood--;
				continue;
			}
			if(tianji[tianjigood] > qiwang[qiwanggood])
			{
				cnt++;
				tianjigood--;
				qiwanggood--;
				continue;
			}
			if(tianji[tianjigood] < qiwang[qiwanggood])
			{
				cnt--;
				tianjibad++;
				qiwanggood--;
				continue;
			}
			if(tianji[tianjibad] < qiwang[qiwanggood])
				cnt--;
			tianjibad++;
			qiwanggood--;
		}
		printf("%d\n",200*cnt);
	}
}


int tian[1010],qi[1010],n;
int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int i,j,k=0,headt,tailt,headq,tailq,ans;
	while(in(n) && n)
	{
		ans=0;
		headt=headq=0; tailt=tailq=n;
		for(i=0;i<n;i++) in(tian[i]);
		for(i=0;i<n;i++) in(qi[i]);
		sort(tian,tian+n);
		sort(qi,qi+n);
		while(headt!=tailt)
		{
			if(tian[headt]<qi[headq]) { ans--; headt++; tailq--; continue; }
			if(tian[headt]>qi[headq]) { ans++; headt++; headq++; continue; }
			if(tian[tailt-1]>qi[tailq-1]) { ans++; tailt--; tailq--; continue; }
			if(tian[tailt-1]<qi[tailq-1]) { ans--; headt++; tailq--; continue; }
			if(tian[headt]<qi[tailq-1]) ans--; headt++; tailq--;
		}
		printf("%d\n",ans*200);
	}
}


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

main()
{
int j;
for(j=1;;j++)
{

    int n,count=0,tout,weit,touq,weiq;
    int t[1010],q[1010];
    scanf("%d",&n);
    if(n==0){break;}
    else
    tout=0,weit=n-1,touq=0,weiq=n-1;
       for(int i=0;i<=n-1;i++)
        {
        scanf("%d",&t[i]);
        }
       for(int i=0;i<=n-1;i++)
        {
        scanf("%d",&q[i]);
        }

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

    for(int i=1;i<=n;i++)
      {
          if(t[tout]>q[touq])
          {
          count=count+1;
          tout=tout+1;
          touq=touq+1;
          }
          else if(t[tout]<q[touq])
          {
          weit=weit-1;
          touq=touq+1;
          count=count-1;
          }
          else if(t[tout]==q[touq])
          {
            if(t[weit]>q[weiq])
                {
                count+=1;
                weit-=1;
                weiq-=1;
                }
            else if(t[weit]<q[weiq]||t[weit]==q[weiq])
                {
                if(t[weit]<q[touq])
                {count-=1;
                weit-=1;
                touq+=1;}
                else if(t[weit]==q[touq])
                {
                weit-=1;
                touq+=1;
                }
                }

          }

        }

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

}


int tj[1000],qw[1000];

int main(){
	//freopen("data.txt","r",stdin);
	int n,i,j,w,win,c;
	while(scanf("%d",&n)&&n)
	{
		for(i=0;i<n;i++)
			scanf("%d",tj+i);
		for(i=0;i<n;i++)
			scanf("%d",qw+i);
		sort(tj,tj+n);
		sort(qw,qw+n);
		win=0;
		for(j=w=0;j<n;j++)
		{
			if(tj[j]>qw[w])
			{
				w++;
				win++;
			}
			else if(w==0)
			{
				if(tj[j]==qw[w])
					w++;
				else
					win--;
			}
			else
			{
				c=-1;
				for(i=1;w-i>=0;i++)
					if(qw[w-i]==tj[j-i]&&qw[w-i]<tj[j-i+1])
						c++;
				if(tj[j]==qw[w]&&c<=0)
					w++;
				else
					win+=c;
			}
		}
//		win-=n-w;
		printf("%d\n",win*200);
	}
	return 0;
}


int mycompare(const void*e1,const void*e2)
{
	if(*(int*)e1<*(int*)e2)
		return 1;
	else
		return -1;
}
int main()
{
	int n;
	while(cin>>n)
	{
		if(n==0)
			break;
		int a[1000];
		int b[1000];
		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]),mycompare);
		qsort(b,n,sizeof(b[0]),mycompare);

		int begin_a=0;
		int begin_b=0;
		int end_a=n-1;
		int end_b=n-1;
		int win=0;

		while(begin_a<=end_a)
		{
			if(a[end_a]>b[end_b])
			{
				win++;
				end_a--;
				end_b--;
			}
			else if(a[end_a]<b[end_b])
			{
				win--;
				end_a--;
				begin_b++;
			}
			else
			{
				if(a[begin_a]>b[begin_b])
				{
					win++;
					begin_a++;
					begin_b++;
				}
				else
				{
					if(a[end_a]<b[begin_b])
						win--;
					end_a--;
					begin_b++;
				}

			}
		}
		cout<<win*200<<endl;
	}
}


int a[1010],b[1010];
int comp(const void * elem1, const void * elem2)
{
	return (*(int *) elem1) - (*(int *)elem2);
}
int main()
{
	int n, i, j, heada, taila, headb, tailb, win;
	cin >> n;
	while( n!= 0){
		for( i = 0 ; i < n ; i++) cin >> a[i];
		for( i = 0 ; i < n ; i ++) cin >> b[i];
		qsort(a,n,sizeof(int),comp);
		qsort(b,n,sizeof(int),comp);
		heada = headb = 0;
		taila = tailb = n-1;
		win = 0;
		while(tailb >= headb){
			if(a[taila] > b[tailb]){
				taila--;
				tailb--;
				win++;
			}
			else if(a[heada] > b[headb]){
				heada++;
				headb++;
				win++;
			}
			else{
				if(a[heada] < b[tailb]) win --;
				heada++;
				tailb--;
			}
		}
		cout << win * 200 <<endl;
		cin >> n;
	}
}


int swap(int n,int *a,int *b)
{
    int win;
    int lost;
    int money;
    int i,j,k;
    i=0;
    j=0;
    int *c=(int*)malloc(n*sizeof(int));
    for(j=0;j<n;j++)
    {
             win=0;
             lost=0;
             for(i=0;i<n;i++)
             {

                             if(a[i]>b[i]) {win++;}
                             else if(a[i]<b[i]) {lost++;}

             }
             c[j]=win*200-lost*200;

             k=a[0];
             for(i=0;i<n-1;i++)
             {
                            a[i]=a[i+1];
             }
             a[n-1]=k;

    }
    money=c[0];
    for(j=0;j<n;j++)
    {
                    if(money<c[j]){money=c[j];}
    }

    return money;
}
main()
{
    int i;
    for(i=1;;i++)
    {
        int n;
        scanf("%d",&n);
        if(n==0) break;
        else
        {
            int *a=(int*)malloc(n*sizeof(int));/*tianji*/
            int l,k;
            for(l=0;l<n;l++)
            {
                scanf("%d",&a[l]);
            }
            scanf("\n");

            for(l=0;l<n-1;l++)   /*??????*/
            {
                for(k=0;k<n-1-l;k++)
                {
                    if(a[k]<a[k+1])
                    {
                        int temp;
                        temp=a[k];
                        a[k]=a[k+1];
                        a[k+1]=temp;
                    }
                }

            }
            int *b=(int*)malloc(n*sizeof(int));/*qiwang*/

            for(l=0;l<n;l++)
            {
                scanf("%d",&b[l]);

            }

            //scanf("\n");

            for(l=0;l<n-1;l++)   /*??????*/
            {
                for(k=0;k<n-1-l;k++)
                {
                    if(b[k]<b[k+1])
                    {
                        int temp;
                        temp=b[k];
                        b[k]=b[k+1];
                        b[k+1]=temp;

                    }

                }

            }

            printf("%d\n",swap(n,a,b));
        }
    }
    getchar;
    getchar;
}


int main()
{
	int n;
	while(1)
	{
		int tian[1000];
		int qi[1000];
		cin >> n;
		if (n == 0)
			break;
		for (int i = 0; i < n; i++)
			cin >> tian[i];
		for (int i = 0; i < n; i++)
			cin >> qi[i];
		sort(tian,tian+n);
		sort(qi,qi+n);
		int ans = 0;
		int tianbig = n-1,tiansmall = 0,qibig = n-1,qismall = 0;
		while(n--)
		{
			if (tian[tianbig] > qi[qibig])
			{
				tianbig--;
				qibig--;
				ans+=200;
			}
			else if (tian[tiansmall] > qi[qismall])
			{
				qismall++;
				tiansmall++;
				ans+= 200;
			}
			else
			{
				if (qi[qibig]>tian[tiansmall])
					ans -= 200;
				tiansmall++;
				qibig--;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


int main()
{
    int n;
    int a[1005];
    int b[1005];
    int count,i,j,x,y,start,temp;
    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;
}


int n;
int tjdm[1000],qwdm[1000];

int main()
{
	while(cin >> n)
	{
		if(n == 0)
			return 0;
		for(int i = 0;i < n;i++)
			cin >> tjdm[i];
		for(int i = 0;i < n;i++)
			cin >> qwdm[i];
		sort(tjdm,tjdm + n);
		sort(qwdm,qwdm + n);
		int sum = 0;
		int tmin = 0;
		int qmin = 0;
		int tmax = n - 1;
		int qmax = n - 1;
		while(tmin < n)
		{
			if(tjdm[tmin] > qwdm[qmin])
			{
				sum += 200;
				tmin++;
				qmin++;
			}
			else if(tjdm[tmin] < qwdm[qmin])
			{
				sum -= 200;
				tmin++;
				qmax--;
			}
			else if(tjdm[tmin] == qwdm[qmin])
			{
				if(tjdm[tmax] > qwdm[qmax])
				{
					tmax--;
					qmax--;
					sum += 200;
				}
				else if(tjdm[tmax] < qwdm[qmax])
				{
					sum -= 200;
					tmin++;
					qmax--;
				}
				else if(tjdm[tmax] == qwdm[qmax])
				{
					if(tjdm[tmin] > qwdm[qmax])
					{
						sum += 200;
					}
					if(tjdm[tmin] < qwdm[qmax])
						sum -= 200;
					tmin++;
					qmax--;
				}
			}
			if(tmax < tmin)
				break;
		}
		cout << sum << endl;
	}
}


int TianJi[1000]={0},QiWang[1000]={0};
int cmp(const void * elem1, const void * elem2)
{
	int * p1=(int *)elem1;
	int * p2=(int *)elem2;
	if(*p1<*p2)
		return -1;
	else if(*p1==*p2)
		return 0;
	else return 1;
}
int main()
{
	int n,i,j,sum,equalnum,equalhorse;
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
			break;
		for(i=0;i<n;i++)
			scanf("%d",&TianJi[i]);
		for(i=0;i<n;i++)
			scanf("%d",&QiWang[i]);
		qsort(TianJi,n,sizeof(int),cmp);
		qsort(QiWang,n,sizeof(int),cmp);
		j=0;
		sum=0;
		equalnum=0;
		equalhorse=0;
		for(i=0;i<n;i++)
		{
			if(TianJi[i]>QiWang[j])
			{
				sum+=200;
				j++;
			}
			else if(TianJi[i]==QiWang[j])
			{
				if(equalnum>0)
				{
					if(TianJi[i]>equalhorse)
					{
						equalnum--;
						sum+=200;
						continue;
					}
				}
				equalhorse=TianJi[i];
				equalnum++;
				j++;
			}
			else
			{
				if(equalnum>0)
				{
					if(TianJi[i]>equalhorse)
					{
						equalnum--;
						sum+=200;
					}
				}
			}
		}
		sum=sum-(n-j)*200;
		printf("%d\n",sum);
	}
	return 0;
}


int Tian[MAXIN], Qi[MAXIN];
int N;

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

int main()
{
	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 Qp = 0;
		int ans;
		while(Tian[0] < Qi[Qp] && Qp < N) Qp ++;

		for(ans = -200 * N; Qp < N; Qp ++)
		{
			int temp = -200 * Qp;
			for(int j = Qp, Tp = 0; j < N; j ++, Tp ++)
			{
				if(Tian[Tp] > Qi[j])
				{
					temp += 200;
				}
				else if(Tian[Tp] < Qi[j])
					temp -= 200;
			}

			if(temp > ans)
				ans = temp;
		}

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


int main()
{
	int n;
	int i,j,k;
	int temp;
	int win=0;
	int tie=0;
	int lose=0;
	int tianji[1000];
	int qiwang[1000];
	while(1)
	{
		win=0;
		tie=0;
		lose=0;
		scanf("%d",&n);
		if(n==0)
		{
			break;
		}
		for(i=0;i<n;i++)
		{
			scanf("%d",tianji+i);
		}
		for(i=0;i<n;i++)
		{
			scanf("%d",qiwang+i);
		}
		for(i=0;i<n;i++)
		{
			for(j=0;j<n-i-1;j++)
			{
				if(tianji[j]<tianji[j+1])
				{
					temp=tianji[j];
					tianji[j]=tianji[j+1];
					tianji[j+1]=temp;
				}
			}
			for(j=0;j<n-i-1;j++)
			{
				if(qiwang[j]<qiwang[j+1])
				{
					temp=qiwang[j];
					qiwang[j]=qiwang[j+1];
					qiwang[j+1]=temp;
				}
			}
		}
		for(j=0;j<n;j++)
		{
			if(qiwang[j]==-1)
			{
				continue;
			}
			for(i=n-1;i>=0;i--)
			{
				if(tianji[i]==-1)
				{
					continue;
				}
				if(tianji[i]>qiwang[j])
				{
					tianji[i]=-1;
					qiwang[j]=-1;
					win++;
					break;
				}
			}
		}
		for(i=0;i<n;i++)
		{
			if(tianji[i]==-1)
			{
				continue;
			}
			for(j=0;j<n;j++)
			{
				if(qiwang[j]==-1)
				{
					continue;
				}
				if(tianji[i]==qiwang[j])
				{
					tianji[i]==-1;
					qiwang[j]==-1;
					tie++;
					break;
				}
			}
		}
		lose=n-win-tie;
		printf("%d\n",(win-lose)*200);
	}
	return 0;
}


const int MAX=1010;

int n;
int a[MAX];
int b[MAX];

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

int main()
{
  int i,j,s1,s2;
  while(cin>>n,n>0)
  {
    s1=0;
    s2=-200*n;
    for(i=0;i<n;i++)
      cin>>a[i];
    for(i=0;i<n;i++)
      cin>>b[i];
    qsort(a,n,sizeof(int),cmp);
    qsort(b,n,sizeof(int),cmp);
    //new
    for(j=0;j<n;j++)
    {
      s1=0;
      for(i=0;i+j<n;i++)
      {
        if(a[i]>b[i+j])
          s1++;
        if(a[i]<b[i+j])
          s1--;
      }
      s2=max(s2,s1-j);
    }
    cout<<s2*200<<endl;
  }
  return 0;
}


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

int main()
{
	int na[1010];
	int nb[1010];
	int n;
	while(cin>>n,n!=0)
	{
		int i,j,r;
		int head=0, t_tail=n-1, q_tail=n-1;
		int result=0;

		for(i=0;i<n;i++)
			cin>>na[i];
		for(i=0;i<n;i++)
			cin>>nb[i];
		qsort(na,n,sizeof(na[0]),cmp);
		qsort(nb,n,sizeof(nb[0]),cmp);
		for(i=0;i<n;i++)
		{
			if(na[head] > nb[i])
			{
				head++;
				result++;
			}
			else if(na[head] < nb[i])
			{
				result--;
				t_tail--;
			}
			else
			{
				while(t_tail >= head)
				{
					if(na[t_tail] > nb[q_tail])
					{
						result++;
						t_tail--;
						q_tail--;
					}
					else
					{
						if(na[t_tail] < nb[i])
							result--;
						t_tail--;

						break;
					}
				}
			}
			if(head > t_tail)
				break;
		}
		cout<<200*result<<endl;
	}
	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 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]);
		}
		quicksort(t,0,n-1);
		quicksort(q,0,n-1);
		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));
	}
}


int main()
{
    int saima(int n,int qiwang[1000],int tianji[1000]);
    int n,i,j;
    int tianji[1000]={0},qiwang[1000]={0};
    scanf("%d",&n);
    for (i=0;n!=0;i++){
        for (j=0;j<n;j++){
            scanf("%d",&tianji[j]);
            }
        for (j=0;j<n;j++){
            scanf("%d",&qiwang[j]);
            }
        printf("%d\n",saima(n,qiwang,tianji));
        scanf("%d",&n);
        }
    return 0;
}
int saima(int n,int qiwang[1000],int tianji[1000])
{
    void seq(int n,int a[1000]);
    void del(int i, int n, int a[1000]);
    int i,win;
    seq(n,tianji);
    seq(n,qiwang);
    win=0;
    while (n>0){
         if ((tianji[n-1]!=qiwang[n-1])&&(n>0)){
            if (tianji[n-1]>qiwang[n-1]){
                win=win+200;
                del(n-1,n,tianji);
                del(n-1,n,qiwang);
                n=n-1;
                }
            else{
                 win=win-200;
                 del(n-1,n,tianji);
                 del(0,n,qiwang);
                 n=n-1;
                 }
            }
        if ((tianji[0]!=qiwang[0])&&(n>0)){
            if (tianji[0]>qiwang[0]){
                win=win+200;
                del(0,n,tianji);
                del(0,n,qiwang);
                n=n-1;
                }
            else{
                 win=win-200;
                 del(n-1,n,tianji);
                 del(0,n,qiwang);
                 n=n-1;
                 }
            }
        if ((tianji[0]==qiwang[0])&&(tianji[n-1]==qiwang[n-1])&&(n>0)){
            if (tianji[n-1]<qiwang[0]){
                win=win-200;
                }
            del(n-1,n,tianji);
            del(0,n,qiwang);
            n=n-1;
            }

        }
        return(win);
}
void seq(int n,int a[1000])
{
       int i,j,temp;
       for (i=0;i<n;i++){
        for (j=0;j<n-1-i;j++){
            if (a[j]<a[j+1]){
                             temp=a[j];
                             a[j]=a[j+1];
                             a[j+1]=temp;
                             }
            }
        }
     }
void del(int i,int n,int a[1000])
{
     int j;
     for (j=i;j<n;j++){
         a[j]=a[j+1];
         }
     }


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

int main(){
  int n;
  int data1[1005];
  int data2[1005];
  int i;
  int i1, i2, j1, j2;
  int result;
  while(true){
    cin>>n;
    if(n==0) break;
    for(i=0; i<n; i++)
      cin>>data1[i];
    for(i=0; i<n; i++)
      cin>>data2[i];
    qsort(data1, n, sizeof(int), cmp);
    qsort(data2, n, sizeof(int), cmp);
    i1=0;
    j1=0;
    i2=n-1;
    j2=n-1;
    result=0;
    while(i1!=i2+1){
      while(data1[i1]!=data2[j1] && i1!=i2+1){
	if(data1[i1]<data2[j1]){
	  i2--;
	  j1++;
	  result-=200;
	}
	else if(data1[i1]>data2[j1]){
	  i1++;
	  j1++;
	  result+=200;
	}
	else break;
      }
      while(data1[i2]!=data2[j2] && i1!=i2+1){
	if(data1[i2]<data2[j2]){
	  j1++;
	  i2--;
	  result-=200;
	}
	else if(data1[i2]>data2[j2]){
	  i2--;
	  j2--;
	  result+=200;
	}
	else break;
      }
      if(data1[i1]==data2[j1] && data1[i2]==data2[j2] && i1!=i2+1){
	if(data1[i2]!=data2[j1])
	  result-=200;
	i2--;
	j1++;
      }
    }
    cout<<result<<endl;
  }
  return 0;
}


int n;
int a[1001];
int b[1001];

int mycompare(const void *p1,const void *p2)
{
	int *a1,*a2;
	a1 = (int *)p1;
	a2 = (int *)p2;
	return *a2 - *a1;
}

int main()
{
	int i,j,k1,k2;
	int la,lb,ra,rb;
	int total;

	while(true)
	{
		cin >> 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;
		la = 0; lb = 0;
		ra = n - 1; rb = n - 1;

		while (la <= ra)
		{
			if (a[la] > b[lb])
			{
				total = total + 200;
				la ++;
				lb ++;
			}
			else
			{
				if (a[la] < b[lb])
				{
					total = total - 200;
					lb ++;
					ra --;
				}
				else
				{

					for (k1 = ra,k2 = rb;la <= k1; k1 --,k2 --)
					{
						if (a[k1] > b[k2])
						{
							total = total + 200;
							ra --;
							rb --;
						}
						else
						{
							if (a[k1] < b[lb]) total = total - 200;
							ra = k1;
							rb = k2;
							ra --;
							lb ++;
							break;
						}
					}
				}
			}
		}
		cout << total << endl;
	}
	return 0;
}


int a[1010],b[1010];
int main()
{
    int n;
    while(scanf("%d",&n),n)
    {
        for(int i=1; i<=n; i++)  scanf("%d",&a[i]);
        for(int i=1; i<=n; i++)  scanf("%d",&b[i]);
        sort(a+1,a+1+n);
        sort(b+1,b+1+n);
        int tl=1,tr=n,ql=1,qr=n;
        int sum=0;
        while(tl<=tr)
        {
            if(a[tl]<b[ql])
            {
                qr--;
                tl++;
                sum=sum-200;
            }
            else if(a[tl]==b[ql])
            {
                while(tl<=tr&&ql<=qr)
                {
                    if(a[tr]>b[qr])
                    {
                        sum+=200;
                        tr--;
                        qr--;
                    }
                    else
                    {
                        if(a[tl]<b[qr])  sum-=200;
                        tl++;
                        qr--;
                        break;
                    }
                }
            }
            else
            {
                tl++;
                ql++;
                sum=sum+200;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}


int mycompare(const void *q1,const void *q2);

int t[1000],q[1000];
int n;

int main()
{
	int i,j;
    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];
	}
    qsort(t,n,sizeof(int),mycompare);
	qsort(q,n,sizeof(int),mycompare);
    int ans=0;
	int tf=0,tl=n-1,qf=0,ql=n-1;
	while(qf<=ql)
	{
      if(t[tf]>q[qf])
      {
		  ans++;
		  tf++;
		  qf++;
      }
	  else if(t[tl]>q[ql])
	  {
		  ans++;
		  tl--;
		  ql--;
	  }
	  else
	  {
		  if(t[tf]>q[ql])
		    ans++;
		  else if(t[tf]<q[ql])
			  ans--;
		  tf++;
		  ql--;
	  }
	}
	cout<<ans*200<<endl;
	}
	return 0;
}

int mycompare(const void *q1,const void *q2)
{
	int * p1=(int *)q1;
	int * p2=(int *)q2;
	return *p1-*p2;
}


int N;
int TJ[MAX];
int QW[MAX];
int main()
{
	int i, j, lt, rt, lq, rq;
	while( 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,TJ+N);
		sort(QW,QW+N);
		lt = 0; rt = N-1; lq = 0; rq = N-1; j = 0;
		while( lt <= rt )
		{
			if( TJ[lt] > QW[lq] )
			{
				j += 200;
				lq++;
				lt++;
			}
			else if( TJ[rt] > QW[rq] )
			{
				j += 200;
				rt--;
				rq--;
			}
			else
			{
				if( TJ[lt] < QW[rq] )  j -= 200;
				lt++;
				rq--;
			}
		}
		printf("%d\n",j);
	}
}


const int MAXN=1005;
main()
{
     int n;
     int t[MAXN], k[MAXN];
     while(cin>>n, n)
      {
               int i;
               for(i=0; i<n; i++) cin>>t[i];
               for(i=0; i<n; i++) cin>>k[i];
               sort(t, t+n); sort(k, k+n);
               int fastT=n-1, slowT=0, fastK=n-1, slowK=0;
               int total=0;
               while(slowK<=fastK)
               {
                            if(t[fastT] > k[fastK])
                            {
                                             total += 200;
                                             fastT--;
                                             fastK--;
                            }
                            else if(t[fastT] < k[fastK])
                            {
                                             total -= 200;
                                             slowT++;
                                             fastK--;
                            }
                            else
                            {
                                             while(slowK<=fastK)
                                             {
                                                                  if(t[slowT] > k[slowK])
                                                                  {
                                                                                total += 200;
                                                                                slowT++;
                                                                                slowK++;
                                                                  }
                                                                  else
                                                                  {
                                                                                if(t[slowT] < k[fastK]) total -= 200;
                                                                                slowT++;
                                                                                fastK--;
                                                                                break;
                                                                  }
                                             }
                            }
               }
               cout<<total<<endl;
      }
      return 0;
}


void main()
{int n,*tian,*lord;
	int i,j,x[500]={0},t,sumnum=0,sum;
	int ta,tb,la,lb;

	scanf("%d",&n);
	while(n!=0)
	{
	tian=(int *)malloc(n*sizeof(int));
	lord=(int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++) scanf("%d",tian+i);
	for(i=0;i<n;i++) scanf("%d",lord+i);
	for(j=0;j<n-1;j++)
		for(i=0;i<n-1-j;i++)
			if(*(tian+i)<*(tian+i+1))
			{
				t=*(tian+i);
				*(tian+i)=*(tian+i+1);
				*(tian+i+1)=t;
			}

	for(j=0;j<n-1;j++)
		for(i=0;i<n-1-j;i++)
			if(*(lord+i)<*(lord+i+1))
			{
				t=*(lord+i);
				*(lord+i)=*(lord+i+1);
				*(lord+i+1)=t;
			}
			ta=0,la=0,tb=n-1,lb=n-1;sum=0;
			while(ta!=tb)
			{
				if(*(tian+tb)<*(lord+lb)) {tb--;la++;sum--;}
				else if(*(tian+tb)>*(lord+lb)) {tb--;lb--;sum++;}
				else if(*(tian+ta)<*(lord+la)) {tb--;la++;sum--;}
				else if(*(tian+ta)>*(lord+la)) {ta++;la++;sum++;}
				else if(*(tian+tb)<*(lord+la)) {tb--;la++;sum--;}
				else if(*(tian+tb)>*(lord+la)) {tb--;la++;sum++;}
				else {tb--;la++;}
			}
			if(*(tian+ta)>*(lord+la)) sum++;
			else if(*(tian+ta)<*(lord+la))sum--;

	x[sumnum]=sum;
	sumnum++;
	scanf("%d",&n);
	}

	for(i=0;i<sumnum;i++)
	printf("%d\n",x[i]*200);
}


int n=0,cnt=0;
int visit[2000][2000];
int dp[2000][2000];
int a[2000];
int b[2000];
void qsort(int i,int j,int *a)
{
  int l=i,r=j,mid=a[(i+j)/2];
  while (l<=r)
  {
    while (a[l]>mid) l++;
    while (a[r]<mid) r--;
    if (l<=r)
    {
      int temp=a[l]; a[l]=a[r]; a[r]=temp;
      l++; r--;
    }
  }
  if (l<j) qsort(l,j,a);
  if (i<r) qsort(i,r,a);
}
int f(int i,int j)
{
  if (visit[i][j]!=cnt)
  {
    visit[i][j]=cnt;
    if (j>n) dp[i][j]=0;
    else
    {
      int a1=0;
      if (a[i]>b[j]) a1=200; else if (a[i]==b[j]) a1=0; else a1=-200;
      int k1=f(i+1,j+1)+a1;
      int a2=0;
      if (a[n-(j-i)]>b[j]) a2=200; else if (a[n-(j-i)]==b[j]) a2=0; else a2=-200;
      int k2=f(i,j+1)+a2;
      dp[i][j]=k1;
      if (k2>k1) dp[i][j]=k2;
    }
  }
  return dp[i][j];
}
int main()
{
    //freopen("zozo.in","r",stdin);
    //freopen("zozo.out","w",stdout);
    scanf("%d",&n);
    while (n!=0)
    {
      for (int i=1; i<=n; i++) scanf("%d",&a[i]);
      for (int i=1; i<=n; i++) scanf("%d",&b[i]);
      qsort(1,n,a);
      qsort(1,n,b);
      cnt++;
      int ans=f(1,1);
      printf("%d\n",ans);
      scanf("%d",&n);
    }
}


int mycompare(const void *elem1, const void *elem2)
{
	return *((int *)elem2) - *((int *)elem1);
}
int main()
{
	int n;
	while (cin >> n, n != 0)
	{
		int a[1000] = {0};
		int b[1000] = {0};
		for (int i = 0; i < n; i++)
			cin >> a[i];
		for (int i = 0; i < n; i++)
			cin >> b[i];
		qsort(a, n, sizeof(int), mycompare);
		qsort(b, n, sizeof(int), mycompare);
		int index1_head = 0, index1_tail = n-1;
		int index2_head = 0, index2_tail = n-1;
		int money = 0;
		while (index1_head <= index1_tail)
		{
			if (a[index1_head] > b[index2_head])
			{
				index1_head++;
				index2_head++;
				money += 200;
			}
			else if (a[index1_tail] > b[index2_tail])
			{
				index1_tail--;
				index2_tail--;
				money += 200;
			}
			else
			{
				if (b[index2_head] > a[index1_tail]) money -= 200;
				index1_tail--;
				index2_head++;
			}
		}
		cout << money << endl;
	}
return 0;
}


main()
{
      int wang[1000],tian[1000];
      int head,tailw,tailt,i,j,m,n,t,sum;
      for(;;)
      {
             sum=0;
             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",&wang[i]);
             for(i=0;i<n-1;i++)
             for(j=i+1;j<n;j++)
             {
                               if(tian[j]>tian[i])
                               {
                                                  t=tian[j];
                                                  tian[j]=tian[i];
                                                  tian[i]=t;
                               }
                               if(wang[j]>wang[i])
                               {
                                                  t=wang[j];
                                                  wang[j]=wang[i];
                                                  wang[i]=t;
                               }
             }
             head=0;
             tailw=n-1;
             tailt=n-1;
             for(i=0;i<n;i++)
             {
                             if(tian[head]>wang[i])
                             {
                                                   sum++;
                                                   head++;
                             }
                             else if(tian[head]<wang[i])
                             {
                                  tailt--;
                                  sum--;
                             }
                             else if(tian[head]==wang[i])
                             {
                                  for(j=tailt,m=tailw;j>=head;j--,m--)
                                  {
                                                                      if(tian[j]>wang[m])
                                                                      {
                                                                                tailt--;
                                                                                tailw--;
                                                                                sum++;
                                                                      }
                                                                      else
                                                                      {
                                                                           if(tian[j]<wang[i]) sum--;
                                                                           tailt--;
                                                                           tailw=m;
                                                                           break;
                                                                      }
                                  }
                             }
                             if(head>tailt) break;
             }
             printf("%d\n",sum*200);
      }
    }


int myfunc(const void *a, const void *b)
{
	return *(int *)a-*(int *)b;
}
int max(int a, int b)
{
	return a>b?a:b;
}
int main()
{
	int t[2000];
	int q[1000];
	int n;
	int i, start;
	int sum, tmp;
	while (1) {
		scanf("%d", &n);
		if (n == 0)
			break;
		for (i = 0; i < n; i ++)
			scanf("%d", t+i);
		for (i = 0; i < n; i ++)
			scanf("%d", q+i);
		qsort(t, n, sizeof(int), myfunc);
		qsort(q, n, sizeof(int), myfunc);
		memcpy(t+n, t, n);
		sum = -0xFFFFFFF;
		for (start = 0; start < n; start ++) {
			tmp = 0;
			for (i = 0; i < n; i ++) {
				if (t[start+i] < q[i])
					tmp -= 200;
				if (t[start+i] > q[i])
					tmp += 200;
			}
			sum = max(sum, tmp);
		}
		printf("%d\n", sum);
	}
	return 0;
}


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


int main()
{
    int n[100];
    int tianji[100][1000];
    int qiwang[100][1000];
    int i;
    for(i=0;;i++)
    {
        scanf("%d",&n[i]);
        if(n[i]==0)
        {
            break;
        }
        else
        {
            for(int j=0;j<=n[i]-1;j++)
            {
                scanf("%d",&tianji[i][j]);
            }
            for(int k=0;k<=n[i]-1;k++)
            {
                scanf("%d",&qiwang[i][k]);
            }
        }
    }
    for(int l=0;l<=i-1;l++)
    {
        for(int j=n[l]-1;j>0;j--)
        {
            for(int k=0;k<j;k++)
            {
                if(tianji[l][k]>tianji[l][k+1])
                {
                    int temp;
                    temp=tianji[l][k+1];
                    tianji[l][k+1]=tianji[l][k];
                    tianji[l][k]=temp;
                }
                if(qiwang[l][k]>qiwang[l][k+1])
                {
                    int temp;
                    temp=qiwang[l][k+1];
                    qiwang[l][k+1]=qiwang[l][k];
                    qiwang[l][k]=temp;
                }
            }
        }
    }
    for(int l=0;l<=i-1;l++)
    {
        int t1=0,t2=n[l]-1;
        int q1=0,q2=n[l]-1;
        int count=0;
        for(;t1<=t2;)
        {
            if(tianji[l][t2]>qiwang[l][q2])
            {
                count++;
                t2--;
                q2--;
            }
            else if(tianji[l][t1]>qiwang[l][q1])
            {
                count++;
                t1++;
                q1++;
            }
            else if(tianji[l][t1]<qiwang[l][q2])
            {
                count--;
                t1++;
                q2--;
            }
            else
            {
                t1++;
                q2--;
            }
        }
        printf("%d\n",200*count);
    }
    return 0;
}


int vs[MaxN][MaxN];
int f[MaxN][MaxN];
int qiwang[MaxN] , tianji[MaxN];

int max(int x, int y)
{
	if (x > y) return x;
	else return y;
}

int vs1(int x, int y)
{

    if (tianji[x] > qiwang[y]) return 200;
    else if (tianji[x] < qiwang[y]) return -200;
        else return 0;
}

int sort(int a[MaxN],int l, int r)
{

    int i = l, j = r, k = a[(i+j)/2];

    while (i <= j)
    {
        while (a[i] > k) ++i;
        while (k > a[j]) --j;
        if (i <= j)
        {

            int x = a[i];
            a[i] = a[j];
            a[j] = x;
            ++i;
            --j;
        }
    }
    if (l < j) sort(a,l,j);
    if (i < r) sort(a,i,r);
}
int main()
{
  //  freopen("1.in","r",stdin);
   // printf("2\n");

    int k, L, n , i , j , a ;
	scanf("%d" , &n );
	while (n)
	{

		//qiwang = (int*)malloc(n*sizeof(int));
	//	tianji = (int*)malloc(n*sizeof(int));
		for ( i = 0 ; i < n ; i ++ )  scanf("%d" , &tianji[i] );
		for ( i = 0 ; i < n ; i ++ ) { scanf("%d" , &qiwang[i] );}//printf(" %d ",i);}

        sort(tianji,0,n-1);
        sort(qiwang,0,n-1);

    for (i = 0; i < n; ++i) f[i][i] = vs1(i,n-1);
       for (L = 1; L < n; ++L)
            for (i = 0; i < n-L; ++i)
            {
                j = i + L;
                f[i][j] = max ( f[i+1][j] + vs1(i,n-1-L) , f[i][j-1] + vs1(j,n-1-L) );
            }
		printf("%d\n",f[0][n-1]);
	scanf("%d" , &n );
	}
	return 0;
}


int cmp(const void * a, const void * b) {
        return *(int *)a - *(int *)b;
}
int a[1000], b[1000], queue[1001];
int head, tail;
void enqueue(int elem) {
    queue[head ++] = elem;
    if (head == MAX) head = 0;
}
int top() {
    return queue[tail];
}
int dequeue() {
    int ret = queue[tail ++];
    if (tail == MAX) tail = 0;
    return ret;
}
int empty() {
    return head == tail;
}
int size() {
    if (head < tail)
        return head + MAX - tail;
    else return head - tail;
}
int main() {
        int n, i, j, draw, win;
        int ans;
        while (scanf("%d", &n) != EOF && n != 0) {
        head = tail = 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), cmp);
                qsort(b, n, sizeof(int), cmp);
                win = draw  = 0;
                for (i = n - 1, j = n - 1; j >= 0; j --) {
                        if (a[i] > b[j]) i --, win ++;
            else {
                if (!empty() && top() > b[j]) {
                    dequeue();
            //        printf("dequeue: %d\n", dequeue());
                    win ++;
                }
                else {
                                if (a[i] == b[j])
                        enqueue(a[i --]);
                }
            }
                }
        draw = size();
                ans = (2 * win - n + draw) * 200;
                printf("%d\n", ans);
//              printf("ans : %d\n", ans);
//              printf("win : %d\n", win);
//              printf("draw: %d\n", draw);
        }
        return 0;
}


int n;
int q[M];
int p[M];
int map[M][M];
int vis[M][M];

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

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

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

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

    return 0;
}


int speed[1024], ano[1024];

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

int main()
{
	int n;
	while(scanf("%d", &n) == 1 && n != 0)
	{
		int sum = 0;
		for(int i = 0; i < n; ++i)
			scanf("%d", speed + i);
		for(int i = 0; i < n; ++i)
			scanf("%d", ano + i);
		sort(speed, speed + n);
		sort(ano, ano + n);
		int myLow = 0, myHigh = n - 1, anoLow = 0, anoHigh = n - 1;
		while(myLow <= myHigh)
		{
			if(speed[myLow] > ano[anoLow])
			{
				sum += fight(myLow, anoLow);
				++myLow, ++anoLow;
			}
			else if(speed[myLow] < ano[anoLow])
			{
				sum += fight(myLow, anoHigh);
				++myLow, --anoHigh;
			}
			else if(speed[myHigh] > ano[anoHigh])
			{
				sum += fight(myHigh, anoHigh);
				--myHigh, --anoHigh;
			}
			else if(speed[myHigh] <= ano[anoHigh])
			{
				sum += fight(myLow, anoHigh);
				++myLow, --anoHigh;
			}
		}
		printf("%d\n", sum * 200);
	}
}


int main(){
    int n,i;
    int tianji[10100],king[10100];
    while(cin>>n){
        if(!n)break;
        i=0;
        while(i<n){
            cin>>tianji[i++];
        }
        i=0;
        while(i<n){
            cin>>king[i++];
        }
        sort(tianji,tianji+n);
        sort(king,king+n);
        int b1,e1,b2,e2,score=0;
       // cout<<"%"<<score<<endl;
        b1=0;e1=n-1;b2=0;e2=n-1;
        while(b1<=e1){
            if(tianji[e1]>king[e2]){
                score+=200;e1--;e2--;
            }
            else if(tianji[e1]<king[e2]){
                score-=200;e2--;b1++;
            }
            else{
                if(tianji[b1]!=king[b2]&&b1<=e1)
                                while(tianji[b1]!=king[b2]&&b1<=e1){
                    if(tianji[b1]>king[b2]){
                        b1++;b2++;score+=200;
                    }
                    else{
                        b1++;e2--;score-=200;
                    }
                }
                else if(b1<e1&&tianji[b1]==king[b2]){
                    if(tianji[b1]<king[e2])score-=200;
                    b1++;e2--;
                }
                else if(b1==e1)break;
            }
        }
        cout<<score<<endl;
    }
    return 0;
}


void paixu(int*p,int k);
main()
{
      int tian[2020],qi[1010];
      int n,i,j,k,m,max;
      for(;;)
      {
             scanf("%d",&n);
             if(n!=0)
             {
                     for(i=0;i<n;i++)
                     scanf("%d",&tian[i]);
                     for(j=0;j<n;j++)
                     scanf("%d",&qi[j]);
                     paixu(tian,n);
                     paixu(qi,n);
                     max=-n;
                     for(k=0;k<n;k++)
                     tian[n+k]=tian[k];
                     for(i=0;i<n;i++)
                     {
                          m=0;
                          for(j=0;j<n;j++)
                          {
                                if(tian[j+i]>qi[j])
                                m=m+1;
                                if(tian[j+i]<qi[j])
                                m=m-1;
                          }
                          if(m>max)
                          max=m;
                     }
                     printf("%d\n",200*max);
             }
             else
             break;
      }
      getchar();getchar();
}
void paixu(int*p,int k)
{
     int i,j,t;
     for(i=0;i<k-1;i++)
     {
          for(j=0;j<k-1-i;j++)
          {
                if (p[j]<p[j+1])
                {
                       t=p[j];
                       p[j]=p[j+1];
                       p[j+1]=t;
                }
          }
     }
}


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

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

main()
{
	int n,i,j,tianji[1000],qiwang[1000],money=0,fast=0,slowt,slowq,st,sq;
	for(i=0;1;i++)
	{
		scanf("%d",&n);
		if(n==0)
		{
			return 0;
		}else{
			Input(tianji,n);
			Order(tianji,n);
			Input(qiwang,n);
			Order(qiwang,n);
			money=0;
			fast=0;
			slowt=n-1;
			slowq=n-1;
			for(j=0;j<n;j++)
			{
				if(tianji[fast]>qiwang[j])
				{
					money++;
					fast++;
				}else if(tianji[fast]<qiwang[j]){
					money--;
					slowt--;
				}else if(tianji[fast]==qiwang[j]){
					for(st=slowt,sq=slowq;st>fast;st--,sq--)
					{
						if(tianji[st]>qiwang[sq])
						{
							money++;
							slowt--;
							slowq--;
							n--;
						}else if(tianji[st]<=qiwang[sq]){
							if(tianji[st]<qiwang[j])
							{
								money--;
								slowt=st-1;
								slowq=sq;
								break;
							}else{
								slowt=st-1;
								slowq=sq;
							}
						}
					}
				}
				if(fast>slowt)
				{
					break;
				}
			}
			printf("%d\n",money*200);
		}
	}
	return 0;
}


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


int ans = 0;
int n;
int horses1[1001], horses2[1001];
void cal ()
{
	int pos;
	if (horses1[n -1] == -1) return;
	for (int i = 0 ; i < n ; i ++)
	{
		if (horses1[i] != -1)
		{
			pos = i;
			break;
		}
	}
	if (horses1[pos] > horses2[pos])
	{
		ans += 200;
		horses1[pos] = -1;
		horses2[pos] = -1;
		cal ();
		return;
	}
	if (horses1[pos] < horses2[pos])
	{
		ans -= 200;
		horses1[pos] = -1;
		for (int i = n - 1 ; i >= 1 ; i --)
			horses2[i] = horses2[i - 1];
		horses2[0] = -1;
		cal ();
		return;
	}
	if (horses1[n - 1] > horses2[n - 1])
	{
		ans += 200;
		for (int i = n - 1 ; i >= 1 ; i --)
			horses1[i] = horses1[i - 1];
		horses1[0] = -1;
		for (int i = n - 1 ; i >= 1 ; i --)
			horses2[i] = horses2[i - 1];
		horses2[0] = -1;
		cal ();
		return;
	}
	if (horses1[n - 1] < horses2[n - 1])
	{
		ans -= 200;
		horses1[pos] = -1;
		for (int i = n - 1 ; i >= 1 ; i --)
			horses2[i] = horses2[i - 1];
		horses2[0] = -1;
		cal ();
		return;
	}
	if (horses1[n - 1] == horses2[n - 1])
	{
		if (horses1[pos] < horses2[n - 1])
			ans -= 200;
		horses1[pos] = -1;
		for (int i = n - 1 ; i >= 1 ; i --)
			horses2[i] = horses2[i - 1];
		horses2[0] = -1;
		cal ();
		return;
	}
}
int main ()
{
	while (1)
	{
		cin >> n;
		if (n == 0) break;
		for (int i = 0 ; i < n ; i ++)
			cin >> horses1[i];
		for (int i = 0 ; i < n ; i ++)
			cin >> horses2[i];
		sort (horses1, horses1 + n);
		sort (horses2, horses2 + n);
		cal ();
		cout << ans << endl;
		ans = 0;
		/*
		for (int i = 0 ; i < n ; i ++)
			cout << horses1[i] << ' ';
		cout << endl;
		for (int i = 0 ; i < n ; i ++)
			cout << horses2[i] << ' ';
		cout << endl;
		*/
	}
	return 0;
}


int a[1001];
int b[1001];
int f[1001][1001];

int cmp(const void *x,const void *y){
	return *((int *)y)-*((int *)x);
}
int find(int i,int j){
	if(a[i] > b[j]) return 200;
	if(a[i] == b[j]) return 0;
	return -200;
}
int maxS(int aa,int bb){
	return aa>bb?aa:bb;
}

int main(){
	int n,i,j;

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

		for(i = 0;i < n;i++)
			f[i][0] = find(0,i);
		for(i = n-2;i >= 0;i--)
			for(j = 1;j < n-i;j++)
				if(b[i+j] > a[j])
					f[i][j] = f[i+1][j-1] - 200;
				else if(b[i+j] < a[j])
					f[i][j] = f[i][j-1] + 200;
				else if(f[i+1][j-1] - 200 > f[i][j-1])
					f[i][j] = f[i+1][j-1] - 200;
				else f[i][j] = f[i][j-1];

		printf("%d\n",f[0][n-1]);
	}
	return 0;
}


int sort(int x[], int m){
  int i, j, k;
  for (i=0;i<m;i++)
        for (j=i+1;j<m;j++)
            if (x[i]<x[j])
            {
               k = x[i];
               x[i] = x[j];
               x[j] = k;
                          }
}

int main(){
    while (1)
    {

    int num;
    int a[1000];
    int b[1000];
    int i,j,shadow,k;
    int temp_gain=0, temp_tie=0, temp_lose=0;
    int gain=0, lose=0, tie=0;
    int total_gain=0;
    scanf("%d",&num);

    if (num==0)
       break;

    for (i=0;i<num;i++)
        scanf("%d",&a[i]);
    for (i=0;i<num;i++)
        scanf("%d",&b[i]);
    sort(a,num);
    sort(b,num);

    for (i=0;i<num;i++)
    {
        shadow = i;
        i=0;
        for (j=shadow;j<num;j++,i++)
        {
            if (a[i]>b[j])
               temp_gain++;
            else if (a[i]<b[j])
               temp_lose++;
            else
               temp_tie++;
            }
        temp_lose += shadow;
        if ((temp_gain - temp_lose)>(gain - lose) || shadow==0)
           {
                       gain = temp_gain;
                       lose = temp_lose;
                       tie = temp_tie;
                       }
        i = shadow;
        temp_gain = 0;
        temp_lose = 0;
        temp_tie = 0;
        }

    total_gain = (gain-lose)*200;
    printf("%d\n",total_gain);
}
getchar();
getchar();
    }


int thorse[1002];
int qhorse[1002];
int match[1002];
int compare(const void *p1,const void *p2)
{
	int *p=(int *) p1;
	int *q = (int *)p2;
	return (*q)-(*p);
}
int main()
{
	int n;
	while(cin>>n)
	{
		if(n==0){break;}
		memset(thorse,0,sizeof(thorse));
		memset(qhorse,0,sizeof(qhorse));
		memset(match,0,sizeof(match));
		for(int i=0;i<n;i++)
		{
			cin>>thorse[i];
		}
		for(int i=0;i<n;i++)
		{
			cin>>qhorse[i];
		}
		qsort(thorse,n,sizeof(int),compare);
		qsort(qhorse,n,sizeof(int),compare);
		int fast=0, slow=n-1, head=0, tail=n-1;
		int win=0, lose=0;
		while(fast<=slow)
		{
			if(thorse[tail]>qhorse[slow])
			{
				match[slow]=tail;
				slow--;tail--;
			}
			else if(thorse[tail]<qhorse[slow])
			{
				match[fast]=tail;
				fast++;tail--;
			}
			else
			{
				if(thorse[head]>qhorse[fast])
				{
					match[fast]=head;
					fast++;head++;
				}
				else
				{
					match[fast]=tail;
					tail--;fast++;
				}
			}
		}
		for(int i=0;i<n;i++)
		{
			if(qhorse[i]>thorse[match[i]]){lose++;}
			else if(qhorse[i]<thorse[match[i]]){win++;}
		}
		int money=win*200-200*lose;
		cout<<money<<endl;
	}
	return 0;
}


int count1;
int a[1010] ;
int b[1010];
int n;
int cmp(const void *a,const void *b)
{
    return *(int *)b - *(int *)a;
}
int dfs(int *a,int *b)
{
    int x,y,i,j;
    x=y=0;
    i=j=n-1;
    while(true)
    {
    if(x>i)
    break;
    if(a[x]>b[y])
    {
    count1+=1;
    x++;
    y++;
    }
    else
    if(a[i]>b[j])
    {
    count1+=1;
    i--;
    j--;
    }
    else
    {
    if(a[i]<b[y])
    count1-=1;
    i--;
    y++;
    }
    }
}
int main()
{
    while(true)
    {
    cin>>n;
    if(n==0)
    break;
    for(int i=0;i<n;i++)
    cin>>a[i];
    qsort(a,n,sizeof(int),cmp);
  //  for(int i=0;i<n;i++)
  //  cout<<a[i]<<' ';
  //  cout<<endl;
    for(int i=0;i<n;i++)
    cin>>b[i];
    qsort(b,n,sizeof(int),cmp);
    count1=0;
  //  i_count=0;
    dfs(a,b);
    cout<<200*(count1)<<endl;
    }
    return 0;
}


const int maxn = 1200;

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

int
main(void)	{
	int n;
	int a[maxn], b[maxn];

	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(int), cmp);
		qsort(b, n, sizeof(int), cmp);

		int la, lb, ra, rb;

		la = lb = 0;
		ra = rb = n - 1;

		int ans = 0;

		for (int i = 0; i <n; i ++)	{
			if (a[ra] > b[rb])	{
				ans ++;
				ra --, rb --;
				continue;
			}
			if (a[la] > b[lb])	{
				ans ++;
				la ++, lb ++;
				continue;
			}
			if (a[la] < b[rb])	ans --;
			la ++, rb --;
		}

		cout << ans * 200 << endl;

	}

	return 0;
}


main()
{
    int n,h,i=0,j=0,temp,re,iLAST,jLAST;
    int t[1000],q[1000];
    for (h=1;;h++)
    {
        scanf("%d",&n);
        if (n==0)
        break;
        else
        {
            for (i=0;i<n;i++)
            {
                scanf("%d",t+i);
            }
            for (j=0;j<n;j++)
            {
                scanf("%d",q+j);
            }
            for (i=0;i<n;i++)//ÅÅDòìï¼é
            {
                for (j=i;j<n;j++)
                {
                    if (t[j]<t[i])
                    {
                        temp=t[j];
                        t[j]=t[i];
                        t[i]=temp;
                    }
                }
            }
            for (i=0;i<n;i++)//ÅÅDòÆëíõ
            {
                for (j=i;j<n;j++)
                {
                    if (q[j]<q[i])
                    {
                        temp=q[j];
                        q[j]=q[i];
                        q[i]=temp;
                    }
                }
            }

            re=0;
            j=0;
            iLAST=n-1;
            jLAST=n-1;
            for (i=0;i<=iLAST;i++)
            {
                if (t[i]>q[j])
                {
                    re++;
                }
                else if (t[i]<q[j])
                {
                    re--;
                    j--;
                    jLAST--;
                }
                else
                {
                    for (;;jLAST--)
                    {
                        if (t[iLAST]>q[jLAST])
                        {
                            re++;
                            iLAST--;
                        }
                        else if (t[iLAST]<q[jLAST])
                        {
                            re--;
                            j--;
                            jLAST--;
                            break;
                        }
                        else
                        {
                            if (t[i]==t[iLAST])
                            break;
                            else
                            {
                                re--;
                                j--;
                                jLAST--;
                                break;
                            }
                        }
                    }
                    if (t[i]==t[iLAST]&&q[j]==q[jLAST])
                    break;
                }
                j++;
            }
            printf("%d\n",200*re);
        }
    }

}


int main()
{
	int ma(int n);
	int n;
	for(;1;){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		ma(n);
	}
	return 0;
}
int ma(int n){
	int paixu(int tian[],int wang[],int n);
	int sum=0,i,a=1;
	int wang[1001],tian[1001];
	int endw,endt,staw=0,stat=0;
	endw=n-1;
	endt=n-1;
	for(i=0;i<n;i++){
		scanf("%d",&tian[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&wang[i]);
	}
	paixu(tian,wang,n);
	for(;stat<=endt;){
		if(tian[stat]>wang[staw]){
			sum+=200;
			staw++;
			stat++;
		}
		else if(tian[stat]<wang[staw]){
			sum-=200;
			endt--;
			staw++;
		}
		else if(tian[stat]==wang[staw]){
			for(;(a==1);){
				if(tian[endt]>wang[endw]){
					sum+=200;
					endt--;
					endw--;
				}
				else if(tian[endt]<=wang[endw]){
					if(tian[endt]<wang[staw]){
						sum-=200;
					}
					staw++;
					endt--;
					a=0;
				}
			}
			a=1;
		}
	}
	printf("%d\n",sum);
	return 0;
}
int paixu(int tian[],int wang[],int n){
	int change(int *a,int *b);
	int i,j,b;
	for(i=0;i<n;i++){
		for(j=n-1;j>i;j--){
			if(tian[j]>tian[j-1]){
				b=tian[j];
				tian[j]=tian[j-1];
				tian[j-1]=b;
			}
			if(wang[j]>wang[j-1]){
				b=wang[j];
				wang[j]=wang[j-1];
				wang[j-1]=b;
			}
		}
	}
	return 0;
}
int change(int *a,int *b){
	int c;
	c=*a;
	*a=*b;
	*a=c;
	return 0;
}


int main()
{
	int i;
	int tj[NUM], qw[NUM], n;

	while (cin >> n && n)
	{
		for (i = 0; i < n; i++)
			cin >> tj[i];
		for (i = 0; i < n; i++)
			cin >> qw[i];
		sort(tj, tj + n);
		sort(qw, qw + n);

		int sum = 0, tjl = 0, tjr = n - 1, qwl = 0, qwr = n - 1;
		while (tjl <= tjr)
		{
			while (tjl <= tjr && tj[tjl] > qw[qwl])
			{
				sum += 200;
				tjl++;
				qwl++;
			}
			while (tjl <= tjr && tj[tjr] > qw[qwr])
			{
				sum += 200;
				tjr--;
				qwr--;
			}

			if (tjl <= tjr)
			{
				if (tj[tjl] < qw[qwr])
					sum -= 200;
				tjl++;
				qwr--;
			}
		}

		cout << sum << endl;
	}

	return 0;
}


const int MAX = 1005;
int main(void)
{
 int n;
 int tian[MAX], king[MAX];
 while(scanf("%d", &n), n)
 {
  for(int i=0; i<n; i++)
   scanf("%d", &tian[i]);
  for(int i=0; i<n; i++)
   scanf("%d", &king[i]);
  sort(tian, tian+n);
  sort(king, king+n);

  int tian_fast = n-1, king_fast = n-1, result = 0;
  int tian_slow = 0, king_slow = 0;
  while(tian_slow <= tian_fast && king_slow <= king_fast)
  {
   if(tian[tian_slow] < king[king_slow])
   {
    king_fast--;
    tian_slow++;
    result--;
   }
   else if(tian[tian_slow] > king[king_slow])
   {
    tian_slow++;
    king_slow++;
    result++;
   }
   else
   {
    if(tian[tian_fast] > king[king_fast])
    {
     result++;
     tian_fast--; king_fast--;
    }
    else if(tian[tian_fast] < king[king_fast])
    {
     result--;
     tian_slow++;
     king_fast--;
    }
    else
    {
     if(tian[tian_slow] < king[king_fast])
     {
      result--;
      tian_slow++;
      king_fast--;
     }
     else
     {
      break;//??????
     }
    }
   }
  }
  printf("%d\n", result*200);
 }
 return 0;
}


int tian[1000],wang[1000],temp[1000];

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

int main()
{
	int n;
	while(1)
	{
		int i,num = 0,t_first,q_first,t_last,q_last;
		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",&wang[i]);

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

		t_first = q_first = 0;
		t_last = q_last = n-1;
		while( t_last >= t_first )
		{
			if( tian[t_first] > wang[q_first] )
			{
				num++;
				t_first++;
				q_first++;
			}
			else if( tian[t_first] < wang[q_first] )
			{
				num--;
				t_first++;
				q_last--;
			}
			else
			{
				if( tian[t_last] > wang[q_last] )
				{
					num++;
					t_last--;
					q_last--;
				}
				else if( tian[t_last] < wang[q_last] )
				{
					num--;
					t_first++;
					q_last--;
				}
				else
				{
					if( tian[t_first] < wang[q_last] )
						num--;
					t_first++;
					q_last--;
				}
			}
		}

		printf("%d\n",num*200);
	}
	return 0;
}


int main()
{

int n,i,j,k,a[1001],b[1001],sum=0,win,draw,t,as,ae,bs,be;

for(k=0;;k++){

   sum=0;

win=0;

draw=0;

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]);

    for(i=0;i<n;i++)
    {

       for(j=i+1;j<n;j++)
        {

            if(a[i]<a[j]){

                t=a[j];

                a[j]=a[i];

                a[i]=t;

 }

if(b[i]<b[j])

{

 t=b[j];

  b[j]=b[i];

                b[i]=t;

 }

}

 }

 //cong da dao xiao

   //test sort
    //for(i=0;i<n;i++)
    //    printf("a:%d,b:%d\n",a[i],b[i]);
    //test end
    as=0;//amax
    ae=n-1;//amin
    bs=0;//bmax
    be=n-1;//bmin
    while(as<=ae)
    {
        if(a[as]>b[bs])
        {
            as++;
            bs++;
            win++;
        }
        else if(a[ae]>b[be])
        {
            ae--;
            be--;
            win++;
        }
        else
        {
            if(a[ae]==b[bs])
            {
                ae--;
                bs++;
                draw++;
            }
            else
            {
                ae--;
                bs++;
            }
        }

    }
    sum=win*200-(n-win-draw)*200;
    //printf("win:%d;draw:%d;\n",win,draw);
    printf("%d\n",sum);
}
return 0;
}


int main()
{
	int a[1000]={0},b[1000]={0};
	void move(int x[],int y);
	void list(int x[],int y);
	while(true)
	{
		int t,j,i,max;
		cin>>t;
		if(t!=0)
		{
			for(i=0;i<=t-1;i++)
				cin>>a[i];
			for(i=0;i<=t-1;i++)
				cin>>b[i];
			list(a,t);
			list(b,t);
			for(j=0;j<=(t-1)/2;j++)
			{
				int money=0;
				for(i=0;i<=t-1;i++)
				{
					if(a[i]<b[i])
						money--;
					if(a[i]>b[i])
						money++;
				}
				if(j==0)
					max=money;
				if(max<money)
					max=money;
				move(a,t-1);
			}
			cout<<max*200<<endl;
		}
		else
			return 0;
	}
}

void move(int x[],int y)
{
	int temp,i;
	temp=x[y];
	for(i=y-1;i>=0;i--)
		x[i+1]=x[i];
	x[0]=temp;
}
void list(int x[],int y)
{
	int i,j,temp;
	for(i=0;i<=y-1;i++)
		for(j=i;j<=y-1;j++)
		{
			if(x[i]<x[j])
			{
				temp=x[j];
				x[j]=x[i];
				x[i]=temp;
			}
		}
}


int n;
int fun(int a[],int b[])
{
	int min1=0;
	int min2=0;
	int max1=n-1;
	int max2=n-1;
	int count=0;
	int sum=0;
	while(count<n)
	{
		count++;
		if(a[max1]>b[max2])
		{
			max1--;
			max2--;
			sum+=200;
		}
		else if(a[max1]<b[max2])
		{
			sum-=200;
			min1++;
			max2--;
		}
		else
		{
			if(a[min1]>b[min2])
			{
				sum+=200;
				min1++;
				min2++;
			}
			else if(a[min1]<b[max2])
			{
				sum-=200;
				min1++;
				max2--;
			}
			else if(a[min1]==b[max2])
			{
				sum+=0;
				min1++;
				max2--;
			}
		}

	}
	return sum;
}

int main()
{
	int i;
	int a[1005],b[1005];
	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);
		printf("%d\n",fun(a,b));
	}
	return 0;
}


int n;
int a[1002],b[1002];
int solve(int start);
int main(){
	int i;
	while(scanf("%d",&n) &&n){
		for(i=0;i<n;i++)
			scanf("%d",b+i);
		for(i=0;i<n;i++)
			scanf("%d",a+i);
		sort(a,a+n);
		sort(b,b+n);
		int maxp=-99999999;
		for(i=0;i<n;i++){
			int temp=solve(i);
			if(maxp<temp)maxp=temp;
		}
		printf("%d\n",maxp);
	}
	return 0;
}

int solve(int start){
	int i;
	int sum=0;
	for(i=start;i<n;i++){
		if(b[i]>a[i-start])sum+=200;
		else if(b[i]<a[i-start])sum-=200;
		else;
	}
	for(i=0;i<start;i++){
		if(b[i]>a[n-start+i])sum+=200;
		else if(b[i]<a[n-start+i])sum-=200;
		else;
	}
	return sum;
}


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

void main()
{
    int i;
    for(scanf("%d",&n);n>0;scanf("%d",&n))
    {
          for(i=0;i<n;i++)
          {
              scanf("%d",&tian[i]);
          }
           for(i=0;i<n;i++)
          {
            scanf("%d",&king[i]);
           }
         sort(tian);sort(king);
         int begin_tian=0,end_tian=n-1;
         int begin_king=0,end_king=n-1;
         int money=0;
        while(begin_tian<=end_tian)
        {
            while((tian[begin_tian]>king[begin_king])&&(begin_tian<=end_tian))
            {
                      money=money+200;
                      begin_tian++;begin_king++;
            }
            while((tian[end_tian]>king[end_king])&&(begin_tian<=end_tian))
            {
                     money=money+200;
                     end_tian--;end_king--;
            }
            if(begin_tian<=end_tian)
            {
                   if(tian[begin_tian]<king[end_king])
                    money=money-200;
                    begin_tian++;end_king--;
            }
         }
    printf("%d\n",money);
  }
}


int compare(const void*a1,const void*a2)
{
    int*p1,*p2;
    p1=(int*)a1;
    p2=(int*)a2;
    return(*p2)-(*p1);
}
main()
{
      int k;
      for(k=1; ;k++)
      {
            int n,j,i,c=0,p=200,money,m;
            scanf("%d",&n);
            if(n==0) break;
            int*t=(int*)malloc(n*sizeof(int));
            int*q=(int*)malloc(n*sizeof(int));
            for(j=0;j<n;j++)
              {     scanf("%d",&t[j]);  }
             for(j=0;j<n;j++)

                  {scanf("%d",&q[j]);}

             qsort(t,n,sizeof(int),compare);
             qsort(q,n,sizeof(int),compare);
             for(i=0;i<n;i++)
             {
                      if(t[i]>q[i])/*????*/
                      c++;
                      else
                      {
                          if(t[n-1]>q[n-1])/*??????????????????*/
                          {
                               c++;
                               for(j=n-2;j>=i;j--)
                                {t[j+1]=t[j];
                                q[j+1]=q[j];}
                           }
                          else
                          {
                              if(t[n-1]<q[i])
                              {
                                             c--;
                                             for(j=n-2;j>=i;j--)
                                             t[j+1]=t[j];
                               }
                          }
                       }

                       money=c*p;

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

}

                      return(0);

                       getchar();getchar();getchar();getchar();getchar();getchar();getchar();

}


int comp(void const *a,void const *b)
{return  (*(int *)a-*(int *)b);}
main()
{
      int n,w[1001],t[1001],sum;
      int tfast,tslow,wfast,wslow;
      scanf("%d",&n);
      while (n!=0)
      {
            for (int i=0;i<n;i++) scanf("%d",&t[i]);
            for (int i=0;i<n;i++) scanf("%d",&w[i]);
            tfast=n-1;tslow=0;wfast=n-1;wslow=0;sum=0;
            qsort(t,n,sizeof(t[0]),comp);
            qsort(w,n,sizeof(w[0]),comp);
            for (int i=0;i<n;i++)
            {
                if (w[wfast]<t[tfast])     {wfast--;tfast--;sum++;}
                else if (w[wfast]>t[tfast]){wfast--;tslow++;sum--;}
                else if (w[wfast]==t[tfast])

                {
//
//                 if(th[tslow]>wh[wslow]){sum++;tslow++;wslow++;}//sub???????
//		           else if(th[tslow]<wh[wslow]){sum--;tslow++;wfast--;}//???????????????????????????????????????????
//                   else if(th[tslow] == wh[wslow])
//	               {
//			       if(th[tslow]<wh[wfast]){sum--;tslow++;wfast--;}// ???????????????????????????????????????????????????????
//                   else if(th[tslow]==wh[wfast]){break;}//????????????????????????
//                   }
                         if(w[wslow]==t[tslow])
                         {
                              if(w[wfast]==w[wslow])break;
                              else if(w[wfast]>t[tslow]){tslow++;wfast--;sum--;}
                         }
                         else if (w[wslow]>t[tslow]){wfast--;tslow++;sum--;}
                         else if (w[wslow]<t[tslow]){wslow++;tslow++;sum++;}
                }
            }
            printf("%d\n",sum*200);
            scanf("%d",&n);
      }
}


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

int main()
{
	int n,i,ql,qr,tl,tr,total=0;
	int t[1000],q[1000];
	while(cin>>n && n)
{
total=0;
	for (i=0;i<n;i++)	cin>>t[i];
	for (i=0;i<n;i++)	cin>>q[i];
	qsort(t,n,sizeof(int),compare);
	qsort(q,n,sizeof(int),compare);
	ql=0;
	qr=n-1;
	tl=0;
	tr=n-1;
	while(ql<=qr)
	{
		if (q[ql]>t[tl]){
			tr--;
			ql++;
			total-=200;
			continue;
		}
		if (q[ql]<t[tl]){
			ql++;
			tl++;
			total+=200;
			continue;
		}
		if (q[qr]>t[tr])
		{
			ql++;
			tr--;
			total-=200;
			continue;
		}
		if (q[qr]<t[tr])
		{
			qr--;
			tr--;
			total+=200;
			continue;
		}
		if (q[qr]==q[ql])	break;
		ql++;
		tr--;
		total-=200;
	}
	cout<<total<<endl;
}
	return 0;
}


void order(int *p,int n){
	int i,k,e;
	for(k=1;k<n;k++){
		for(i=0;i<n-k;i++){
			if(*(p+i)<*(p+i+1)){
				e=*(p+i);
				*(p+i)=*(p+i+1);
				*(p+i+1)=e;
			}
		}
	}
}
int main(int argc, char* argv[])
{
	int n,king[1000],minister[1000],i,k,money=0,money_plus=0;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%d",&minister[i]);
		}
		for(i=0;i<n;i++){
			scanf("%d",&king[i]);
		}
		order(king,n);
		order(minister,n);
		i=0;
		k=0;
		int m=n;
		while(i<n&&k<m){
			if(king[i]>minister[k]){
				i++;
				m--;
				money-=200;
			}else if(king[i]==minister[k]){
				if(king[n-1]>minister[m-1]){
					i++;
					m--;
					money-=200;
				}else if(king[n-1]<minister[m-1]){
					n--;
					m--;
					money+=200;
				}else{
					if(king[i]==king[n-1]){
						break;
					}else{
						i++;
						m--;
						money-=200;
					}
				}
			}else{
				i++;
				k++;
				money+=200;
			}
		}
		printf("%d\n",money);
                money=0;
	}
	return 0;
}


void main()
{
	int tianfast,tianslow,qifast,qislow,tianhorse[1000],qihorse[1000];
	int button,swap,i,j,n;
	long win,lost,money;
	button=0;
	while (1)
	{
	scanf("%d",&n);
	if (n>0)
	{
		for (i=0;i<=n-1;i++) scanf("%d",&tianhorse[i]);
		for (i=0;i<=n-1;i++) scanf("%d",&qihorse[i]);

		for (i=0;i<n-1;i++)
		for (j=0;j<n-1-i;j++)
		{
			if (tianhorse[j]<tianhorse[j+1])
			{
				swap=tianhorse[j];
				tianhorse[j]=tianhorse[j+1];
				tianhorse[j+1]=swap;
			}
			if (qihorse[j]<qihorse[j+1])
			{
				swap=qihorse[j];
				qihorse[j]=qihorse[j+1];
				qihorse[j+1]=swap;
			}
		}

		win=lost=0;
		tianfast=qifast=0;
		tianslow=qislow=n-1;
		while (tianfast<=tianslow)
		{
			if (tianhorse[tianfast]>qihorse[qifast])
			{
				tianfast++;
				qifast++;
				win++;
			}
			else
				if (tianhorse[tianfast]<qihorse[qifast])
				{
					tianslow--;
					qifast++;
					lost++;
				}
				else
					if (tianhorse[tianslow]>qihorse[qislow])
					{
						tianslow--;
						qislow--;
						win++;
					}
					else
						if (tianhorse[tianslow]<qihorse[qislow])
						{
							tianslow--;
							qifast++;
							lost++;
						}
						else
						{
							if (tianhorse[tianslow]<qihorse[qifast]) lost++;
							else if (tianhorse[tianslow]>qihorse[qifast]) win++;
							tianslow--;
							qifast++;
						}
		}
		money=(win-lost)*200;
		if (button==0)
		{
			printf("%d",money);
			button=1;
		}
		else printf("\n%d",money);
	}
	if (n==0) break;
	}
}


int result(int n,int tianji[1000],int qiwang[1000]){
	int i,k,e,m=0,sum=0,tailt,tailq,a,b;

	tailt=tailq=n-1;

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

	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(i=0;i<n;i++){
		if(tianji[m]>qiwang[i]){
			m++;
			sum+=200;
		}else if(tianji[m]<qiwang[i]){
			sum-=200;
			tailt--;
		}else if(tianji[m]==qiwang[i]){
			for(a=tailt,b=tailq;a>=m;a--,b--){
				if(tianji[a]>qiwang[b]){
					sum+=200;
					tailt--;
					tailq--;
				}else if(tianji[a]<qiwang[b]){
					sum-=200;
					tailt--;
					break;
				}else if(tianji[a]==qiwang[b]){
					if(tianji[tailt]<qiwang[i]){
						sum-=200;
					}
					tailt--;

					break;
				}
			}
		}
		if(m>tailt){
			break;
		}
	}
	return sum;
}

int main(){
	int n,tianji[1000],qiwang[1000],i,j,sum;

	for(i=0;;i++){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(j=0;j<n;j++){
			scanf("%d",&tianji[j]);
		}
		for(j=0;j<n;j++){
			scanf("%d",&qiwang[j]);
		}
		sum=result(n,tianji,qiwang);
		printf("%d\n",sum);
	}

	return 0;
}


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

int main()
{
	int n,i,ql,qr,tl,tr,total=0;
	int t[1000],q[1000];
	while(cin>>n && n)
{
total=0;
	for (i=0;i<n;i++)	cin>>t[i];
	for (i=0;i<n;i++)	cin>>q[i];
	qsort(t,n,sizeof(int),compare);
	qsort(q,n,sizeof(int),compare);
	ql=0;
	qr=n-1;
	tl=0;
	tr=n-1;
	while(ql<=qr)
	{
		if (q[ql]>t[tl]){
			tr--;
			ql++;
			total-=200;
			continue;
		}
		if (q[ql]<t[tl]){
			ql++;
			tl++;
			total+=200;
			continue;
		}
		if (q[qr]>t[tr])
		{
			ql++;
			tr--;
			total-=200;
			continue;
		}
		if (q[qr]<t[tr])
		{
			qr--;
			tr--;
			total+=200;
			continue;
		}
		int flag=0;
		for (i=ql;i+1<=qr;i++)
		{
			if (q[i]!=q[i+1]){
				flag=1;
				break;
			}
		}
		if (flag==0)	break;
		ql++;
		tr--;
		total-=200;
	}
	cout<<total<<endl;
}
	return 0;
}


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

void match(int a[],int b[],int n){
	int num=0;
	int money=0;
	int afr=0,bfr=0;
	int ata=n-1;
	int bta=n-1;
	int c=1;
	for(;afr<=ata;){
		if(a[afr]>b[bfr]){
			money+=200;
			bfr++;
			afr++;
		}else if(a[afr]<b[bfr]){
			money-=200;
			bfr++;
			ata--;
		}else if(a[afr]==b[bfr]){
			for(;c==1;){
				if(a[ata]>b[bta]){
					money+=200;
					ata--;
					bta--;
				}else if(a[ata]<=b[bta]){
					if(a[ata]<b[bfr]){
						money-=200;
					}
					ata--;
					bfr++;
					c=0;
				}
			}
			c=1;
		}
	}
	printf("%d\n",money);
}

int main()
{
	int n,i;
	int qi[1000];
	int tian[1000];
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}else{
			for(i=0;i<n;i++){
				scanf("%d",&tian[i]);
			}
			paixu(tian,n);
			for(i=0;i<n;i++){
				scanf("%d",&qi[i]);
			}
			paixu(qi,n);
			match(tian,qi,n);
		}
	}
	return 0;
}


void main()
{
	int tianfast,tianslow,qifast,qislow,tianhorse[1000],qihorse[1000];
	int button,swap,i,j,n;
	long win,lost,money;
	button=0;
	while (1)
	{
	scanf("%d",&n);
	if (n>0)
	{
		for (i=0;i<=n-1;i++) scanf("%d",&tianhorse[i]);
		for (i=0;i<=n-1;i++) scanf("%d",&qihorse[i]);

		for (i=0;i<n-1;i++)
		for (j=0;j<n-1-i;j++)
		{
			if (tianhorse[j]<tianhorse[j+1])
			{
				swap=tianhorse[j];
				tianhorse[j]=tianhorse[j+1];
				tianhorse[j+1]=swap;
			}
			if (qihorse[j]<qihorse[j+1])
			{
				swap=qihorse[j];
				qihorse[j]=qihorse[j+1];
				qihorse[j+1]=swap;
			}
		}

		win=lost=0;
		tianfast=qifast=0;
		tianslow=qislow=n-1;
		while (tianfast<=tianslow)
		{
			if (tianhorse[tianslow]>qihorse[qislow])
			{
				tianslow--;
				qislow--;
				win++;
			}
			else
				if (tianhorse[tianslow]<qihorse[qislow])
				{
					tianslow--;
					qifast++;
					lost++;
				}
				else
				{
					if (tianhorse[tianfast]>qihorse[qifast])
					{
						tianfast++;
						qifast++;
						win++;
					}
					else
						if (tianhorse[tianfast]<qihorse[qifast])
						{
							tianslow--;
							qifast++;
							lost++;
						}
						else
						{
							if (tianhorse[tianslow]>qihorse[qifast])
							{
								win++;
							}
							else
								if (tianhorse[tianslow]<qihorse[qifast])
								{
									lost++;
								}
							tianslow--;
							qifast++;
						}
				}
		}
		money=(win-lost)*200;
		if (button==0)
		{
			printf("%d",money);
			button=1;
		}
		else printf("\n%d",money);
	}
	if (n==0) break;
	}
}


void merge(int* array,int* temp,int left,int right,int middle){
     int i,j,k,index1,index2;
     for(i = left; i <= middle; i++){
           temp[i] = array[i];
     }
     for(j = 1; j <= right - middle; j++){
           temp[right - j + 1] = array[j + middle];
     }
     for(index1 = left,index2 = right, k = left; k <= right; k++){
                if(temp[index1] <= temp[index2]){
                     array[k] = temp[index1++];
                }
                else{
                     array[k] = temp[index2--];
                }
     }
}
void mergesort(int* array,int* temp,int left,int right){
     if(left < right){
             int middle = (left + right) / 2;
             mergesort(array,temp,left,middle);
             mergesort(array,temp,middle + 1,right);
             merge(array,temp,left,right,middle);
     }
}
int main(){
    int n;
    scanf("%d",&n);
    if(n == 0){return 0;}
    int horse_q[1005] = {0};      //????
    int horse_t[1005] = {0};     //????
    int i;
    for(i = 0; i < n; i++){
            scanf("%d",&horse_t[i]);
    }
    for(i = 0; i < n; i++){
            scanf("%d",&horse_q[i]);
    }
    int temp_t[1005] = {0};
    mergesort(horse_t,temp_t,0,n - 1);
    int temp_q[1005] = {0};
    mergesort(horse_q,temp_q,0,n - 1);
    int t_head = n - 1;        //??????????
    int t_last = 0;            //??????????
    int q_head = n - 1;           //??????????
    int q_last = 0;       //??????????
    int ans = 0;              //??
    while(q_head >= q_last){     //??????????
         if(horse_t[t_head] > horse_q[q_head]){
                       ans += 200;
                       t_head--;
                       q_head--;
         }
         else if(horse_t[t_head] < horse_q[q_head]){
              ans -= 200;
              t_last++;
              q_head--;
         }
         else{
              if(horse_t[t_last] > horse_q[q_last]){
                        ans += 200;
                        t_last++;
                        q_last++;
              }
              else{
                   if(horse_t[t_last] < horse_q[q_head]){
                                      ans -= 200;
                   }
                   t_last++;
                   q_head--;
              }
         }
    }
    printf("%d\n",ans);
    main();
}


int mycomp(const void *a,const void *b)
{return *(int*)a-*(int*)b;}
int main()
{
	int n,iw,ib,re,jw,jb;
	int tj[1000],qw[1000];
	scanf("%d",&n);
	while(n!=0)
	{
		for(iw=0;iw<n;iw++)
			scanf("%d",&tj[iw]);
		for(iw=0;iw<n;iw++)
			scanf("%d",&qw[iw]);
		qsort(tj,n,sizeof(int),mycomp);
		qsort(qw,n,sizeof(int),mycomp);
		iw=0;jw=0;re=0;ib=n-1;jb=n-1;
		while(iw<=ib)
		{
			if(tj[iw]>qw[jw])
			{
				re+=200;
				iw++;jw++;
			}
			else if(tj[iw]<qw[jw])
			{
				if(tj[iw]<qw[jb])
					re-=200;
				else if(tj[iw]>qw[jb])
					re+=200;
				iw++;jb--;
			}
			else if(tj[ib]>qw[jb])
			{
				re+=200;
				ib--;jb--;
			}
			else if(tj[ib]<qw[jb])
			{
				re-=200;
				iw++;jb--;
			}
			else
			{
				if(tj[iw]<qw[jb])
					re-=200;
				iw++;jb--;
			}
		}
		printf("%d\n",re);
        scanf("%d",&n);
	}
	return 0;
}


int main()
{
      int t[1010],w[1010];
      int n,i,j,k,m,ans,w1,w2,head,tailt,tailw;

      while (1)
      {
            scanf("%d",&n);
            ans=0;
            if (n==0)
                break;
            for (i=1;i<=n;i++)
                scanf("%d",&t[i]);
            for (i=1;i<=n;i++)
                scanf("%d",&w[i]);
            for (i=1;i<n;i++)
                for (j=i+1;j<=n;j++)
                {
                    if (t[i]<t[j])
                    {
                        k=t[i]; t[i]=t[j]; t[j]=k;
                    }
                    if (w[i]<w[j])
                    {
                        k=w[i]; w[i]=w[j]; w[j]=k;
                    }
                }
            head=1;
tailt=n;
tailw=n;
for (i=1;i<=n;i++)
{
if (t[head]>w[i])
{
head++;
ans+=200;
}
else if (t[head]<w[i])
{
tailt--;
ans-=200;
}
else if (t[head]==w[i])
{
for (j=tailt,m=tailw;j>=head;)
{
if (t[j]>w[m])
{
ans+=200;
tailt--;
tailw--;
j--;
m--;
}
else
{
if (t[j]<w[i])
ans-=200;
tailt--;
j--;
break;
}
}
}
if (head>tailt)
break;
}

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


const int MAX_N = 1000;
int n, w[MAX_N], t[MAX_N];

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

int main()
{
	while (scanf("%d", &n), n)
	{
		for (int i = 0; i < n; ++i)
			scanf("%d", t + i);
		for (int i = 0; i < n; ++i)
			scanf("%d", w + i);
		qsort(t, n, sizeof(int), cmpInt);
		qsort(w, n, sizeof(int), cmpInt);

		int win = INT_MIN;
		for (int i = 0; i < n; ++i)
		{
			int twin = 0;
			for (int j = 0; j < n; ++j)
				if (t[j] > w[(i + j) % n])
					twin += 200;
				else if (t[j] < w[(i + j) % n])
					twin -= 200;
			if (twin > win)
				win = twin;
		}
		printf("%d\n", win);
	}
	return 0;
}


void main()
{int n,*tian,*lord;
	int i,j,m=0,x[500]={0},t,sumnum=0,sum;
	int ta,tb,la,lb;

	scanf("%d",&n);
	while(n!=0)
	{
	tian=(int *)malloc(n*sizeof(int));
	lord=(int *)malloc(n*sizeof(int));
	//sum=(int *)malloc(n*sizeof(int));
	for(i=0;i<n;i++) scanf("%d",tian+i);
	for(i=0;i<n;i++) scanf("%d",lord+i);

	//maopao1;maopao2;
	for(j=0;j<n-1;j++)
		for(i=0;i<n-1-j;i++)
			if(*(tian+i)<*(tian+i+1))
			{m++;
				t=*(tian+i);
				*(tian+i)=*(tian+i+1);
				*(tian+i+1)=t;
			}

	for(j=0;j<n-1;j++)
		for(i=0;i<n-1-j;i++)
			if(*(lord+i)<*(lord+i+1))
			{m++;
				t=*(lord+i);
				*(lord+i)=*(lord+i+1);
				*(lord+i+1)=t;
			}

/*	for(i=0;i<n;i++)//i???
	{
			*(sum+i)=0;
			for(j=0;j<n;j++)
			{m++;
			if(*(tian+j)>*(lord+(i+j)%n)) (*(sum+i))++;
			else if(*(tian+j)<*(lord+(i+j)%n)) (*(sum+i))--;
			}printf("*(sum+%d)=%d\n",i,*(sum+i));
			if(i!=0&&*(sum+i)<*(sum+i-1)) {m=i-1;break;}
			else if(i==n-1) m=n-1;
	}*/
			//ta,tb,la,lb:tian's tail,lord's head/tail
			ta=0,la=0,tb=n-1,lb=n-1;sum=0;
			while(ta!=tb)
			{
				if(*(tian+tb)<*(lord+lb)) {tb--;la++;sum--;}
				else if(*(tian+tb)>*(lord+lb)) {tb--;lb--;sum++;}
				else if(*(tian+ta)<*(lord+la)) {tb--;la++;sum--;}
				else if(*(tian+ta)>*(lord+la)) {ta++;la++;sum++;}
				else if(*(tian+tb)<*(lord+la)) {tb--;la++;sum--;}
				else if(*(tian+tb)>*(lord+la)) {tb--;la++;sum++;}
				else {tb--;la++;}

			}

			if(*(tian+ta)>*(lord+la)) sum++;
			else if(*(tian+ta)<*(lord+la))sum--;
	//maxsum
	//x[sumnum]=*sum;
	x[sumnum]=sum;
	//for(i=0;i<n;i++)
	//	x[sumnum]=(x[sumnum]>*(sum+i))?x[sumnum]:*(sum+i);
	sumnum++;
	scanf("%d",&n);
	}
	for(i=0;i<sumnum;i++)
	printf("%d\n",x[i]*200);
	//printf("%d",m);
}


int Compare(const void* e1,const void* e2)
{
    return *(int*)e1 - *(int*)e2;
}
int main()
{
	int n;
	while(cin>>n)
	{
		if(n==0)
			break;
		else
		{
	    	int qi[1100],tian[1100];
	     	int qhead=1,qtail=n,thead=1,ttail=n,i,num=0;
	    	for(i=1;i<=n;i++)
			{
		    	cin>>tian[i];
			}
	    	for(i=1;i<=n;i++)
			{
		    	cin>>qi[i];
			}
	    	qsort(tian+1,n,sizeof(int),Compare);
	    	qsort(qi+1,n,sizeof(int),Compare);
	    	while(thead<=ttail)
			{
				if(tian[thead]>qi[qhead])
				{
					num+=200;
					thead++;
					qhead++;
				}
				else if(tian[thead]<qi[qhead])
				{
				    num-=200;
				   	thead++;
				   	qtail--;
				}
				else
				{
					if(tian[ttail]>qi[qtail])
					{
						ttail--;
					    qtail--;
						num+=200;
					}
					else if(tian[ttail]==qi[qtail])
					{
						if(tian[thead]==qi[qtail])
						{
							thead++;
					        qtail--;
						}
						else if(tian[thead]<qi[qtail])
						{
							num-=200;
				     	    thead++;
				        	qtail--;
						}
					}
					else
					{
						if(tian[thead]<qi[qtail])
						{
							num-=200;
				        	thead++;
				            qtail--;
						}
					}
				}
			}
			cout<<num<<endl;
		}
	}
	return 0;
}


int divide(int a[],int low,int high)
{
    int tmp = a[low];
    do{
        while(low != high && a[high] >= tmp)  --high;
        if(low != high && a[high] < tmp)
        {
            a[low] = a[high];
            ++low;
        }
        while(low != high && a[low] <= tmp)   ++low;
        if(low != high && a[low] > tmp)
        {
            a[high] = a[low];
            --high;
        }
    }while(low!=high);
    a[low] = tmp;
    return low;
}

void quickSort(int a[],int low,int high)
{
    if(low >= high) return;
    int mid = divide(a,low,high);
    quickSort(a,low,mid - 1);
    quickSort(a,mid + 1,high);
}

void QuickSort(int a[],int size)
{
    quickSort(a,0,size - 1);
}

//?????????????????????????????????????????????????????????????????????????????????????????????
/*
int main()
{
    int num = 1;    //?????num???????do while??????
    //cout << "hello?!!"<<endl;
    while(1)
    {
        cin >> num;
        if(0 == num)      break;
        int money = 0;
        int tian[num];
        int qi[num];
        //cout << "even here?!!" << endl;
        for(int i = 0;i < num;++i)  cin >> tian[i];
        for(int j = 0;j < num;++j)  cin >> qi[j];
        QuickSort(tian,num);
        QuickSort(qi,num);
        //for(int i = 0;i < num;++i)  cout << tian[i] << "n";
        //for(int i = 0;i < num;++i)  cout << endl << qi[i] << "n";

        //cout << "here!" << endl;
        int low_t = 0;
        int high_t = num - 1,high_q = num - 1;
        do{
            while(high_t >= low_t && qi[high_q] >= tian[high_t])
            {
                money = (qi[high_q]==tian[low_t])?money:money-200;
                --high_q;
                ++low_t;
            }
            while(high_t >= low_t && qi[high_q] < tian[high_t])    {   --high_q;   --high_t;   money+=200; }
        }while(high_t>=low_t);

        low_t = 0;
        high_t = high_q = num-1;
        int money2 = 0;
        do{
            while(high_t >= low_t && qi[high_q] == tian[high_t])    {   --high_q;   --high_t;  }
            while(high_t >= low_t && qi[high_q] > tian[high_t])
            {
                money2 = money2-200;
                --high_q;
                ++low_t;
            }
            while(high_t >= low_t && qi[high_q] < tian[high_t])    {   --high_q;   --high_t;   money2+=200; }
        }while(high_t>=low_t);
        money = (money>money2)?money:money2;
        cout << money << endl;

    }

    //int a[3] = {92,83,71};    //????????
    //int b[3] = {95,87,74};
    //QuickSort(a,3);
    //QuickSort(b,3);
    //for(int i = 0;i < 3;++i)
    //    cout << a[i] << "\t" << b[i] << endl;

    return 0;
}
*/

//?????????????????????????????????????????????(??????)???????????????
int main()
{
    while(1)
    {
        int num,money = 0;
        cin >> num;
        if(0 == num)    break;
        int tian[num],qi[num];
        for(int i = 0;i < num;++i)  cin >> tian[i];
        for(int i = 0;i < num;++i)  cin >> qi[i];
        QuickSort(tian,num);
        QuickSort(qi,num);

        int t_slow = 0,t_fast = num - 1;
        int q_slow = 0,q_fast = num - 1;
        while(t_slow <= t_fast)
        {
            if(tian[t_fast] > qi[q_fast])
            {
                ++money;
                --t_fast;
                --q_fast;
            }
            else if(tian[t_slow] > qi[q_slow])
            {
                ++money;
                ++t_slow;
                ++q_slow;
            }
            else
            {
                if(tian[t_slow] < qi[q_fast])   --money;    //?????????????????????????????????????--money;
                --q_fast;
                ++t_slow;
            }
        }
        cout << money*200 << endl;

    }

}


int n;
int cmp(const void *x,const void *y)
{
	return *(int *)y - *(int *)x;//
}
int pk(int a[],int b[])
{
	int i=0,j=0,k=n-1,l=n-1;
	int sum=0;
	int w=0,lose=0;
	while(i<=k)
	{

		if(a[k]>b[l])
		{
			sum+=200;
			w++;
			k--;
			l--;
		}
		else if(a[k]<b[l])
		{
			sum-=200;
			lose++;
			k--;
			j++;
		}
		else
		{
			if(a[i]>b[j])
			{
				sum+=200;
				w++;
				i++;
				j++;
			}
			else
			{
				if(a[k]<b[j])
				{
					sum-=200;
					lose++;
				}
				k--;
				j++;
			}

		}
	}
	return sum;
}
int main()
{
	int a[1001],b[1001];
	while(cin>>n&&n!=0)
	{
		memset(a,0,sizeof a);
		memset(b,0,sizeof b);
		int i;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
		}
		for(i=0;i<n;i++)
		{
			cin>>b[i];
		}
		qsort(a,n,sizeof a[0],cmp);
		qsort(b,n,sizeof b[0],cmp);
		cout<<pk(a,b)<<endl;
	}
	return 0;
}


int paixu(const void*a, const void*b)
{
    return(*(int*)b-*(int*)a);
}
int main()
{
    int n,i,j,money=0;
    int s;
    for  (s=0;s<50;s++)
    {
     scanf ("%d",&n);
     if (n>0)
     {
      int a[n],b[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(a[0]),paixu);
    qsort(b,n, sizeof(b[0]),paixu);
    i=0;
    j=0;
    int x,y,t=0;
    x=n-1;
    y=n-1;
    while (t<n)
    {
     if (a[i]>b[j])
     {
       i++;
       j++;
       money+=200;
       t++;
     }

    else if (a[x]>b[y])
    {
       x--;
       y--;
       money+=200;
       t++;
    }

    else if (a[x]==b[j])
    {
         x--;
         j++;
         t++;
    }
    else
    {
        money=money-200;
        x--;
        j++;
        t++;
    }
   }

    printf("%d\n",money);
    money=0;
   }
  }

  return 0;
}


int cmp(const void *a, const void *b)
{
	return *(int*)b - *(int*)a;
}
int main()
{
	int n,flag,i,j,bonus,mmax,draw;
	int b[1001],a[1001];

	while (cin>>n)
	{
		if (n==0) break;

		for (i=0;i<n;i++)
			cin>>b[i];
		for(i=0;i<n;i++)
			cin>>a[i];

		mmax=-n;

		qsort(a, n, sizeof(int), cmp);
		qsort(b, n, sizeof(int), cmp);

		for (i=0;i<n;i++)
		{
			flag = 0;draw = 0;

			for(j=0;j<=i;j++)
			{
				if (b[j] < a[n-i-1+j]) flag = 1;
				else if (b[j] == a[n-i-1+j]) draw++;
			}
			if (flag==1) continue;

			bonus = i+1-draw - (n-i-1);

			if (bonus>mmax) mmax = bonus;
		}

		cout<<mmax*200<<endl;
	}
	return 0;
}


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

int main()
{
	void sort(int speed[]);
    int i;
    for(scanf("%d",&n);n>0;scanf("%d",&n))
    {
          for(i=0;i<n;i++)
          {
              scanf("%d",&tj[i]);
          }
           for(i=0;i<n;i++)
          {
            scanf("%d",&qw[i]);
           }
         sort(tj);
         sort(qw);
         int start_tj=0,end_tj=n-1;
         int start_qw=0,end_qw=n-1;
         int money=0;
        while(start_tj<=end_tj)
        {
            while((tj[start_tj]>qw[start_qw])&&(start_tj<=end_tj))
            {
                      money=money+200;
                      start_tj++;
                      start_qw++;
            }
            while((tj[end_tj]>qw[end_qw])&&(start_tj<=end_tj))
            {
                     money=money+200;
                     end_tj--;
                     end_qw--;
            }
            if(start_tj<=end_tj)
            {
                   if(tj[start_tj]<qw[end_qw])
                    money=money-200;
                    start_tj++;
                    end_qw--;
            }
         }
    printf("%d\n",money);
  }
	return 0;
}
void sort(int speed[])
{
    int i,j,temp;
    for(i=0;i<n-1;i++)
    {
         for(j=i+1;j<=n-1;j++)
         {
                if(speed[j]<speed[i])
                {
                      temp=speed[j];
                      speed[j]=speed[i];
                      speed[i]=temp;
                 }
         }
    }
}


// #define SKIP_HORSERACING

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

int main() {
	int n, yourspeed[1000], myspeed[1000], match[1000];
	while(1) {
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < n; i++) {
			scanf("%d", &myspeed[i]);
		}
		for(int i = 0; i < n; i++) {
			scanf("%d", &yourspeed[i]);
		}

		qsort(myspeed, n, sizeof(int), cmp);
		qsort(yourspeed, n, sizeof(int), cmp);

		int cnt = 0, myfirst = 0, mylast = n-1, yourfirst = 0, yourlast = n-1;
		while(myfirst <= mylast) {
			if(myspeed[myfirst] <= yourspeed[yourfirst] && myspeed[mylast] <= yourspeed[yourlast]) {
				match[mylast--] = yourfirst++;
			}
			else if(myspeed[myfirst] > yourspeed[yourfirst]){
				match[myfirst++] = yourfirst++;
			}
			else {
				match[mylast--] = yourlast--;
			}
		}
		for(int i = 0; i < n; i++) {
			if(myspeed[i] > yourspeed[match[i]]) cnt++;
			else if(myspeed[i] < yourspeed[match[i]]) cnt--;
		}

		int gain = 200 * cnt;
		printf("%d\n", gain);
	}
	return 0;
}


int qi[1002];
int tian[1002];
int n;
int myCompare(const void*a,const void *b)
{
   int *p,*q;
   p = (int*)a;
   q = (int*)b;
   return *q - *p;
}
int main()
{
    while(1)
    {
      cin >> 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),myCompare);
      qsort(qi,n,sizeof(int),myCompare);
      int qif=0,qis=n-1;
      int tianf=0,tians=n-1;
      int wins=0,ping=0;
      while(tianf<=tians)
      {
         if(tian[tianf]<qi[qif])
         {
            qif++;
            tians--;
            continue;
         }
         else if(tian[tianf]>qi[qif])
         {
            tianf++;
            qif++;
            wins++;
         }
         else
         {
            if(tian[tians]>qi[qis])
            {
               tians--;
               qis--;
               wins++;
            }
            else
            {
               if(tian[tians]==qi[qif])
                  ping++;
               tians--;
               qif++;
            }
         }
      }
      cout << 200*wins - (n-wins-ping)*200 << endl;
    }
    return 0;
}


const int MAXN=1010;
int n,ans,sum;
int a[MAXN],b[MAXN];

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

int main()
{
    while (1)
      {
        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];
        sort(a,a+n);
        sort(b,b+n);
        for (int i=0;i<n/2;++i)
          {
            swap(a[i],a[n-i-1]);
            swap(b[i],b[n-i-1]);
          }
        ans=-2147483647;
        for (int i=0;i<=n;++i)
          {
            sum=0;
            for (int j=0;j<i;++j)
              sum+=battle(a[j],b[n-i+j]);
            for (int j=0;j<n-i;++j)
              sum+=battle(a[n-j-1],b[j]);
            if (sum>ans)   ans=sum;
          }
        cout<<ans*200<<endl;
      }
}


long a[10000],b[10000];
int cmp( const void *a, const void *b )
{
    return ( *( long *)a) - ( *( long *)b);
}
int main()
{
   long n;
while(1)
{
long sum=0,i,j,end1,end2;
   scanf("%ld",&n);
   if(n==0) break;
   for(i=0;i<n;i++)
    scanf("%ld",&a[i]);
   for(i=0;i<n;i++)
    scanf("%ld",&b[i]);
        qsort( a, n, sizeof( long ), cmp );
   qsort(b, n, sizeof( long ), cmp );
   j=0;
     for(i=j=n-1,end1=end2=0;j>=end2&&i>=end1;j--)
   {
     if(a[i]>b[j])
     {
       sum++;
    i--;
     }
     else if(a[i]<b[j])
     {
        sum--;end1++;
     }
     else
     {
         if(a[end1]>b[end2])//a??????b????
      {
        sum++;end1++;end2++; j++;
      }
      else if(a[end1]<b[end2])
      {
         sum--;end1++;
      }
      else
      {
         if(a[end1]==b[j])
      {
       end1++;
      }
      else
      {
          sum--;end1++;

      }

      }
     }
   }
   cout<<sum*200<<endl;
}
return 0;
}


int bijiao(const void*x,const void*y)
{
return *((int*)y)-*((int*)x);    //???
}

int main()
{
  int n;
  while(scanf("%d",&n)&&(n!=0)) //?????
  {
   int i,*tj,*qw,sum=0;
   tj=(int*)malloc(4*n);
   qw=(int*)malloc(4*n);
   for(i=0;i<n;i++)
   scanf("%d",tj+i);
   for(i=0;i<n;i++)
   scanf("%d",qw+i);
   qsort(tj,n,4,bijiao);
   qsort(qw,n,4,bijiao);

   int tmax=0,qmax=0,tmin=n-1,qmin=n-1;
   for(i=0;i<n;i++)
   {
      if(*(tj+tmax)>*(qw+qmax))
      {sum+=200;tmax++;qmax++;}
      else if(*(tj+tmax)<*(qw+qmax))
      {sum-=200;tmin--;qmax++;}
      else
      {
        if(*(tj+tmin)>*(qw+qmin))
        {sum+=200;tmin--;qmin--;}
        else if(*(tj+tmin)<*(qw+qmin))
        {sum-=200;tmin--;qmax++;}
        else
             {
               if(*(tj+tmax)==*(qw+qmin))
               break;
               else
               {sum-=200;tmin--;qmax++;}
             }
      }

   }
   printf("%d\n",sum);
   free(tj);
   free(qw);
  }

return 0;
}