int speedK[1000];
int speedT[1000];
int horseNum;
int search();
int main()
{
    while (true)
    {
	scanf("%d", &horseNum);
	if (horseNum == 0)
	    break;
	for (int i = 0; i < horseNum; i++)
	     scanf("%d", speedT + i);
	for (int i = 0; i < horseNum; i++)
	     scanf("%d", speedK + i);
	sort (speedT, speedT + horseNum);
	sort (speedK, speedK + horseNum);
	int count = search();
	printf("%d\n", count * 200);
     }
     return 0;
}
int search()
{
    int leftIndexK = 0, rightIndexK = horseNum - 1, leftIndexT = 0, rightIndexT = horseNum - 1, resultCount = 0;
    while (leftIndexT != rightIndexT)
    {
        if (speedT[rightIndexT] > speedK[rightIndexK])
	{
	    resultCount++;
	    rightIndexT--;
	    rightIndexK--;
	}
	else if (speedT[leftIndexT] > speedK[leftIndexK])
	     {
		 resultCount++;
		 leftIndexT++;
		 leftIndexK++;
	     }
	     else
	     {
		 if (speedK[rightIndexK] - speedT[leftIndexT] > 0)
	            resultCount--;
		 rightIndexK--;
		 leftIndexT++;
	     }
     }
     if (speedK[leftIndexK] - speedT[leftIndexT] > 0)
	resultCount--;
     else if (speedK[leftIndexK] - speedT[leftIndexT] < 0)
	     resultCount++;
     return resultCount;
}


int main()
{
	int n;
	int count=0;
	int a[1000];
	int b[1000];
	int min1,min2,max1,max2;
	int i,num;
	while(scanf("%d",&n)&&n)
	{
		min1=0;
		min2=0;
		max1=n-1;
		max2=n-1;
		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);
		count=0;
		num=0;
		while(++count)
		{
			if(count==n+1)
				break;
			if(a[max1]>b[max2])
			{
				num+=200;
				max1--;
				max2--;
			}
			else if(a[max1]<b[max2])
			{
				num-=200;
				min1++;
				max2--;
			}
			else
			{
				if(a[min1]>b[min2])
				{
					min1++;
					min2++;
					num+=200;
				}
				else if(a[min1]==b[max2])
				{
					min1++;
					max2--;
				}
				else
				{
					min1++;
					max2--;
					num-=200;
				}
			}
		}
		printf("%d\n",num);
	}
	return 0;
}


static int cmp(const void *a, const void *b)
{
	return *(int *)b - *(int *)a;
}
int main()
{
	int n,a[1000]={0},b[1000]={0},t,s,j,p,c,tk,tm,qk,qm;
	for(;;)
	{
		scanf("%d",&n);
		if (n==0) break;
		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);
	}
	return 0;
}


// greedy.cpp : Defines the entry point for the console application.
//

int compare(const void *a, const void *b)
{
	int *x=(int *)a;
	int *y=(int *)b;
	return (*y)-(*x);

}
int main()
{

	int n;
	int i=0,j=0,k=0;
	int king[1000];
	int tianji[1000];
	int win=0, lose=0, equal=0;
	int game=0;
	int count=0;
	while(cin>>n)
	{
		if(n==0)
			break;
		for(i=0;i<n;i++)
			cin>>tianji[i];
		for(i=0;i<n;i++)
			cin>>king[i];
		qsort(tianji, n, sizeof(tianji[0]),compare);
		qsort(king, n, sizeof(king[0]), compare);//?????
	//	int game=0;//game= ????????, game ?? ??????? n???????
	//	int count=0;//
	//	int ans=0;
		j=0;
		i=0;
		while( j<game && tianji[j]<king[i])
				i++;
		int max=-1000000;
		for(k=i;k<n;k++)
		{
			game=-200*k;
			count=0;
			for(j=k;j<n;j++)
			{
				if(tianji[count]<king[j])
					game+=-200;
				else
					if(tianji[count]==king[j])
						game+=0;
					else
						game+=200;
					count++;

			}
			if(game>max)
				max=game;
			//cout<<"game"<<game<<endl;
		}
		cout<<max<<endl;

	}
	return 0;
}


int a[1004],b[1004];

void main()
{
	void qsorta(int n);
	void qsortb(int n);
	int n=1,i,j,k,max=0,one,ll[3000],l=1;
	while (n!=0)
	{
		scanf("%d",&n);
		if (n==0) break;
		for (i=1;i<=n;i++) scanf("%d",&a[i]);
		qsorta(n);
		for (i=1;i<=n;i++) scanf("%d",&b[i]);
		qsortb(n);
		max=-100000000;
		for (i=0;i<=n-1;i++)
		{
			one=0;
			for (j=1;j<=n;j++)
			{
				k=j+i;
				if (k>n) k=k-n;
				if (a[j]>b[k]) one=one+200;
				else if (a[j]<b[k]) one=one-200;
			}
			if (one>max) max=one;
		}
		ll[l]=max;
		l=l+1;
	}
	for (i=1;i<=l-1;i++)
		printf("%d\n",ll[i]);
}

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

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


void sort(int a[],int n);
main()
{
      int n,i,j,k,t,money,r,qwf,qws,tjf,tjs;
      int win=0,lose=0;
      int tj[1001],qw[1001];
      for(r=0;;r++)
      {
      scanf("%d",&n);
      if(n==0)
          goto label;
      for(i=0;i<n;i++)
          scanf("%d",&tj[i]);
      for(i=0;i<n;i++)
          scanf("%d",&qw[i]);
      sort(tj,n);
      sort(qw,n);
      qwf=0;qws=n-1;
      tjf=0;tjs=n-1;
      for(i=0;i<n;i++)
      {
          if(tj[tjf]>qw[qwf])
          {
               win++;
               tjf++;
               qwf++;
          }
          else if(tj[tjs]>qw[qws])
          {
               win++;
               tjs--;
               qws--;
          }
          else
          {
               if(tj[tjs]!=qw[qwf])
                   lose++;
               qwf++;
               tjs--;
          }
      }
      money=(win-lose)*200;
      printf("%d\n",money);
      win=0;
      lose=0;
      }
      label:;

}

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


int tianji[1001], qiwang[1001], n;

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

int solve()
{
	int score = 0;
	int p1 = 0;
	int p2 = 0;
	int e1 = n-1;
	int e2 = n-1;
	while(p2 <= e2)
	{
		if (tianji[p1] > qiwang[p2])
		{
			score += 200;
			p1++;
			p2++;
			continue;
		}
		if (tianji[e1] > qiwang[e2])
		{
			score += 200;
			e1--;
			e2--;
			continue;
		}
		if (tianji[e1] < qiwang[p2])
		{
			score -= 200;
			e1--;
			p2++;
			continue;
		}
		if (tianji[e1] == qiwang[p2])
		{
			e1--;
			p2++;
		}
		else
		{
			cout << "err!" << endl;
			break;
		}
	}
	return score;
}

int main()
{
	while(cin >> n)
	{
		if (n == 0)
			break;
		for (int i = 0; i < n; i ++)
			cin >> tianji[i];
		qsort(tianji, n, sizeof(int), cmp);
		for (int i = 0; i < n; i ++)
			cin >> qiwang[i];
		qsort(qiwang, n, sizeof(int), cmp);
		cout << solve() << endl;
	}
	return 0;
}


main()
{
    int n=1;
    int tianji[1002],qiwang[1002];
    while(n!=0)
    {
    scanf("%d\n",&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]);
    for(int i=0;i<n-1;i++)            //?????
      for(int k=n-2;k>=i;k--)
      {
          if(tianji[k]>tianji[k+1])
          {
               int m=tianji[k];
               tianji[k]=tianji[k+1];
               tianji[k+1]=m;
          }
      }
     for(int i=0;i<n-1;i++)            //?????
      for(int k=n-2;k>=i;k--)
      {
          if(qiwang[k]>qiwang[k+1])
          {
               int m=qiwang[k];
               qiwang[k]=qiwang[k+1];
               qiwang[k+1]=m;
          }
      }
    int win=0,ping=0;        //????????
    int t[1002],q[1002];    //????????
    for(int i=0;i<n;i++)
    {
        t[i]=1;q[i]=1;
    }
    for(int i=0;i<n;i++)            //?tianji?????qiwang??????????
    {
        for(int j=n-1;j>=0;j--)
        {
             if(q[j]==0)continue;
             if(tianji[i]>qiwang[j])
             {
                 win++;
                 t[i]=0;
                 q[j]=0;
                 break;
             }
        }
    }
     int i,j;
     for(i=0;i<n;i++)
     {
         if(t[i]==0) continue;
         for(j=0;j<n;j++)
         {
              if(q[j]==1)
             {
                if(tianji[i]==qiwang[j])
               {
                  ping++;
                  t[i]=0;
                  q[j]=0;
                  break;
                 }
             }
         }
     }
    long sum=win*200-(n-win-ping)*200;
    printf("%d\n",sum);

    }
    return 0;
}


int n;
int a[MAX],b[MAX];
int i,j,k,ans;

int main(){

	while(1){
		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);
		sort(a,a+n);
		sort(b,b+n);
		ans=-200*n;
		for(j=0;j<n;++j){
			k=0;
			for(i=0;i<n;++i){
				if(a[i]>b[(i+j)%n])k+=200;
				if(a[i]<b[(i+j)%n])k-=200;
			}
			if(k>ans)ans=k;
		}
		printf("%d\n",ans);
	}

	return 0;
}


int MyCmp(const void * e1,const void * e2)
{
	int * p1=(int *)e1;
	int * p2 = ( int * )e2 ;
	return (*p2) - (*p1);
}
int main ()
{
	int n,i,sum;
	int front2,back2,front,back;
	int a[1010],b[1010];
	while(cin>>n)
	{
		if(n==0)
			break;
		sum=0;
		for(i=0;i<n;i++)
			cin>>a[i];
		for(i=0;i<n;i++)
			cin>>b[i];
		qsort(a,n,sizeof(int),MyCmp);
		qsort(b,n,sizeof(int),MyCmp);
		front2=front=0;
		back2=back=n-1;
		while(front2<=back2)
		{
			if(a[front]>b[front2])
			{
				front++;
				front2++;
				sum+=200;
			}
			else if(a[front]==b[front2] )
			{
				while(front <= back)
				{
					if(a[back]>b[back2])
					{
						sum+=200;
						back--;
						back2--;
					}
					else
					{
						if(a[back]<b[front2])
							sum-=200;
						back--;
						front2++;
						break;
					}
				}
			}
			else
			{
				//if(a[back]<b[counter])
					sum-=200;
				back--;
				front2++;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}


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

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


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

}


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

int main()
{
	int i, n, a[1000], b[1000];

	while(scanf("%d", &n) && n!=0)
	{
		int res=0, a1=0, a2=n-1, b1=0, b2=n-1;

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

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

		for(i=0; i<n; i++)
		{
			if(a[a1] > b[b1])
			{
				res++;
				a1++;
				b1++;
			}
			else if(a[a2] > b[b2])
			{
				res++;
				a2--;
				b2--;
			}
			else
			{
				if(a[a1] > b[b2])
					res++;
				else if(a[a1] < b[b2])
					res--;
				else
					;
				a1++;
				b2--;

			}
		}

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


int qw[MAX],tj[MAX];
int n;
int cmp(const void* a,const void*b)
{return *((int*)b)-*((int*)a);}
int main()
{
  for(scanf("%d",&n);n!=0;scanf("%d",&n))
    {
      for(int i=0;i<n;i++)
	scanf("%d",&tj[i]);
      for(int i=0;i<n;i++)
	scanf("%d",&qw[i]);
      qsort(qw,n,sizeof(int),cmp);
      qsort(tj,n,sizeof(int),cmp);
      int tjs,tje=n-1,qws=0,qwe=n-1;
      for(tjs=0;qw[qws]>tj[tjs];tje--,qws++);
      int win=0,lose=qws;
      for(;tjs<=tje;)
	{
	  if(tj[tjs]>qw[qws])
	    win++,tjs++,qws++;
	  else if(tj[tjs]<qw[qws])
	    lose++,tje--,qws++;
	  else
	    {
	      if(tj[tje]>qw[qwe])
		win++,tje--,qwe--;
	      else
		{
		  if(tj[tje]<qw[qws])
		    lose++,tje--,qws++;
		  else //draw
		    tje--,qws++;
		}

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


int main()
{
	int n,i,j,temp,r=0,thead,ttail,khead,ktail;
	int vtj[1100],vqw[1100];
	while(1)
	{
		r=0;
		scanf("%d",&n);
		if(n==0)
		break;
		for(i=0;i<n;i++)
			scanf("%d",&vtj[i]);
		for(i=0;i<n;i++)
			scanf("%d",&vqw[i]);
		for(i=0;i<n;i++)
			for(j=i;j<n;j++)
			{
				if(vqw[j]>vqw[i])
				{
					temp=vqw[i];
					vqw[i]=vqw[j];
					vqw[j]=temp;
				}
				if(vtj[j]>vtj[i])
				{
					temp=vtj[i];
					vtj[i]=vtj[j];
					vtj[j]=temp;
				}
			}
		ttail=ktail=n-1;
		thead=khead=0;
		while(ttail>=thead)
		{
			if(vtj[ttail]>vqw[ktail])
			{
				ttail--;
				ktail--;
				r+=200;
				continue;
			}
			else if(vtj[ttail]<vqw[ktail])
			{
				r-=200;
				ttail--;
				khead++;
				continue;
			}
			else
			{
				if(vtj[thead]>vqw[khead])
				{
					r+=200;
					thead++;
					khead++;
				}
				else if(vtj[thead]<vqw[khead])
				{
					r-=200;
					ttail--;
					khead++;
				}
				else
				{
					if(vtj[ttail]<vqw[khead])
					{
						r-=200;
						ttail--;
						khead++;
					}
					else
					{
						ttail--;
						khead++;
					}
				}
				continue;
			}
		}
	printf("%d\n",r);
	}
	getchar();
	getchar();
}


int main()
{
	int i,j,k,tl,ql,m,n,ans;
	int tian[1100],qi[1100];

	while (scanf("%d",&n) && n!=0)
	{
		ans=0;
		for (i=0;i<n;i++)	scanf("%d",&tian[i]);
		for (i=0;i<n;i++)	scanf("%d",&qi[i]);

		sort(tian,tian+n);
		sort(qi,qi+n);
		i=n-1; j=n-1;
		tl=0; ql=0;
		while (i>=tl && j>=ql)
		{

			if (tian[i]>qi[j])
			{
				ans++;
				i--;
				j--;
			}
			else if (tian[i]<qi[j])
			{
				ans--;
				tl++;
				j--;
			}
			else
			{
				if(tian[tl]<=qi[ql])
				{
					if (tian[tl]<qi[j]) ans--;
					tl++;
					j--;
				}
				else
				{
					while (tian[tl]>qi[ql] && tl<=i && ql<=j)
					{
						tl++;
						ql++;
						ans++;
					}
					if (tl>i || ql >j) break;
				}
			}
		}
		printf("%d\n",ans*200);
	}
}


// horse_race.cpp : ??????????????
//

int tian[1001],king[1001];
int horses;
int f[1001][1001];
void init()
{
 int i;
 memset(f,0xff,sizeof(f));
    for(i=0;i<horses;i++)
  cin>>tian[i];
    for(i=0;i<horses;i++)
  cin>>king[i];
 sort(tian,tian+horses);
 sort(king,king+horses);
}
int getf(int x,int y)
{
    if(f[x][y]!=-1)
  return f[x][y];
    if(x>=horses||y>=horses)
  return f[x][y]=0;
    if(tian[x]>king[y])
  return f[x][y]=getf(x+1,y+1)+200;
    if(tian[x]<king[y])
  return f[x][y]=getf(x+1,y)-200;
    if(tian[x]==king[y])
  return f[x][y]=max(getf(x+1,y+1),getf(x+1,y)-200);
    return 0;
}
int main()
{
 while(cin>>horses)
    {
		if(horses == 0)
			break;
    init();
       cout<<getf(0,0)<<endl;
    }
    return 0;
}


const int maxn=1005;

int tj[maxn], qw[maxn];

int main()
{
    int n, i, res, max1, max2, min1, min2, cnt;
    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);

        res=0;
        max1=max2=n-1;
        min1=min2=0;
        cnt=0;
        while((cnt++)<n)
        {
            if(tj[max1]>qw[max2])
            {
                res += 200;
                max1--;
                max2--;
            }
            else if(tj[max1]<qw[max2])
            {
                res -= 200;
                min1++;
                max2--;
            }
            else
            {
                if(tj[min1]>qw[min2])
                {
                    res += 200;
                    min1++;
                    min2++;
                }
                else
                {
                    if(tj[min1]<qw[max2]) res -= 200;
                    min1++;
                    max2--;
                }
            }
        }
        printf("%d\n", res);
    }
    return 0;
}


main()
{
      int n,i,j,t,tian[1000],qi[1000],vic=0;
      scanf("%d",&n);
      while(n!=0)
      {
           int head1=0,head2=0,end1=n-1,end2=n-1;
           for(i=0;i<n;i++) scanf("%d",&tian[i]);
           for(i=0;i<n;i++) scanf("%d",&qi[i]);
           for(i=0;i<n-1;i++) for(j=i;j<n;j++) {if(tian[i]<tian[j]) {t=tian[i];tian[i]=tian[j];tian[j]=t;} if(qi[i]<qi[j]) {t=qi[i];qi[i]=qi[j];qi[j]=t;}}
           for(i=0;i<n;i++)
           {
                if(tian[head1]>qi[head2]) {vic++;head1++;head2++;}
                else if(tian[end1]>qi[end2]) {vic++;end1--;end2--;}
                else if(tian[head1]<=qi[head2]) { if(tian[end1]<qi[head2]) {vic--;end1--;head2++;} else {end1--;head2++;} }
                else if(tian[end1]<=qi[end2]) {vic--;end1--;head2++;}
           }
           printf("%d\n",vic*200);
           scanf("%d",&n);
           vic=0;
      }
}


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
					{
							num-=200;
				        	thead++;
				            qtail--;

					}
				}
			}
			cout<<num<<endl;
		}
	}
	return 0;
}


int getcmp(int a,int b){
	if(a>b)return 1;
	else if(a<b)return -1;
	else return 0;
}
int cmp(const void *a, const void *b){
	return *(int*)b - *(int*)a;
}

int main(){
    int n,i,temp,khorse[1000],thorse[1000],profit,profitold,k;
    for(;;){
		profitold=-1000000;
		k=0;
        memset(khorse,0,sizeof(khorse));
        memset(thorse,0,sizeof(thorse));
        scanf("%d",&n);
        if(n==0){break;}
        for(i=0;i<n;++i)
           scanf("%d",&thorse[i]);
        for(i=0;i<n;++i)
           scanf("%d",&khorse[i]);
        qsort(thorse,n,sizeof(thorse[0]),cmp);
		qsort(khorse,n,sizeof(khorse[0]),cmp);
        for(;k<=n;){
			profit=0;
			for(i=0;i<k;++i)
			    profit+=getcmp(thorse[n-1-i],khorse[i])*200;
			for(i=0;i<n-k;++i)
				profit+=getcmp(thorse[i],khorse[i+k])*200;
			if(profit<profitold)
				break;
			profitold=profit;
			k++;
        }
        printf("%d\n",profitold);
    }
}


void sort(int sz[], int n)
{
	int k,e,i;
	for(k=1;k<n;k++){
		for(i=0;i<n-k;i++){
			if(sz[i]<sz[i+1]){
				e=sz[i+1];
				sz[i+1]=sz[i];
				sz[i]=e;
			}
		}
	}
}
int main()
{
	while(1){
	int n,i,j;
	scanf("%d",&n);
	if(n==0) break;
	int *tian=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		scanf("%d",&tian[i]);
	}
	int *king=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		scanf("%d",&king[i]);
	}
	sort(tian,n);
	sort(king,n);
	int win=0,twin=0,even=0,teven=0,lose=10000,tlose=0;
	int temp;
	for(i=0;i<n; i++)
    {
        temp=i;
        i=0;
        for(j=temp;j<n;j++,i++)
        {
            if(tian[i]>king[j])
            {
                twin++;
            }
            else if(tian[i]<king[j])
            {
                tlose++;
            }
            else
            {
                teven++;
            }
        }
        tlose+=temp;
        if((twin-tlose)>(win-lose))
        {
            win=twin;
            lose=tlose;
            even=teven;
        }
        i=temp;
        twin=0;
        tlose=0;
        teven=0;
    }
	printf("%d\n",200*(win-lose));
	free(tian);
	free(king);
	}
	return 0;
}


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

int main()
{
	int n;
	int i;
	while (cin >> n, n > 0){
	int t[1000], q[1000];
	for (i = 0;i < n;i++)
		cin >> t[i];
	for (i = 0;i < n;i++)
		cin >> q[i];
	qsort(t,n,sizeof(int),cmp);
	qsort(q,n,sizeof(int),cmp);
	int t1 = 0, t2 = n-1;
	int q1 = 0, q2 = n-1;
	int cnt = 0;
	for (i = 0;i < n;i++)
	{
		if (t[t1] > q[q1])
		{
			t1++;
			q1++;
			cnt += 200;
		}
		else
		{
			if (t[t2] > q[q2])
			{
				t2--;
				q2--;
				cnt += 200;
			}
			else
			{
				if (t[t2] < q[q1])
					cnt -= 200;
				t2--;
				q1++;
			}
		}
	}
	cout << cnt << endl;
	}
	return 0;
}


const int MAXN = 1010;

int n, a[MAXN], b[MAXN], f[MAXN][MAXN];

void init()
{
	int i;

	for (i=1; i<=n; i++)
		scanf("%d", &a[i]);
	for (i=1; i<=n; i++)
		scanf("%d", &b[i]);
	sort(a+1, a+n+1);
	sort(b+1, b+n+1);
}

int game(int x, int y)
{
	if (x>y) return 200; else
	if (x<y) return -200; else return 0;
}

void work()
{
	int i, j, k;

	for (i=1; i<=n; i++)
		f[i][i]=game(a[i], b[1]);
	for (k=1; k<n; k++)
		for (i=1; i<=n-k; i++){
			j=i+k;
			f[i][j]=max(f[i][j-1]+game(a[j], b[j-i+1]), f[i+1][j]+game(a[i], b[j-i+1]));
		}
	printf("%d\n", f[1][n]);
}

int main()
{
	while (scanf("%d", &n), n!=0){
		init();
		work();
	}

	return 0;
}


void main ()
{
	int jud(int x[1000],int y[1000],int m);
	int n,a[1000],b[1000],c[1000],i=0,j,re;
	scanf ("%d",&n);
	while (n!=0)
	{
		for (j=0;j<n;j++)
		scanf ("%d",&a[j]);
		for (j=0;j<n;j++)
		scanf ("%d",&b[j]);
		c[i]= jud (b,a,n);
		i++;
		scanf ("%d",&n);
	}
	for (j=0;j<i;j++)
	{
		 printf ("%d\n",c[j]);
	}

}

int jud (int x[1000],int y[1000],int m)
{
	int s,i,j;
	void  arrange (int p[1000],int k);
	int result (int a[1000],int b[1000],int n,int i);
	arrange (x,m);
	arrange (y,m);
	s=result (x,y,m,0);
	for (i=1;i<m;i++)
	{
		j=result (x,y,m,i);
		if (s<j) s=j;
	}
	return (s);
}

void arrange (int p[1000],int k)
{
	int i,j,mid;
	for (i=0;i<k;i++)
	   for (j=i+1;j<k;j++)
	   {
	   	   if (p[i]<p[j])
	   	   {
	   	   	mid=p[i];
	   	   	p[i]=p[j];
	   	   	p[j]=mid;
			  }
	   }
}

int result (int a[1000],int b[1000],int n,int i)
{
    int p,q,s=0;
    for (p=0;p<n;p++)
      {
      	    q=p+i;
			if (q>=n) q=q-n;
			if (a[p]>b[q]) s=s-200;
			 else if (a[p]<b[q]) s=s+200;
	  	  }
 	  return (s);
}


int main()
{  	int n,i,j,k,e,total,sum,afast,bfast,aslow,bslow;
         int a[1000],b[1000];
	while(1)
	{
	  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(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;}
	           if(b[i]<=b[i+1]){
                 e=b[i+1];
                 b[i+1]=b[i];
                 b[i]=e;}
	  }}
	    sum=0;
	    total=0;
	    afast=0;
	    bfast=0;
	    aslow=n-1;
	    bslow=n-1;
	    for(;;)
		   {
		      if(a[aslow]>b[bslow]){
		        sum+=200;
	                 total++;
		        aslow--;
		        bslow--;
		      }else if(a[aslow]<b[bslow]){
		     	sum-=200;
		    	total++;
			aslow--;
			bfast++;
		     }else if(a[aslow]==b[bslow]){
		         if(a[afast]>b[bfast]){
			   sum+=200;
	                     total++;
		            afast++;
		            bfast++;
			}else if(a[afast]<b[bfast]){
			   sum-=200;
		            total++;
			   aslow--;
			   bfast++;
		        }else if(a[aslow]==b[bfast]){
			   sum+=0;
			   total++;
			   aslow--;
			   bfast++;
	                 }else if(a[aslow]<b[bfast]){
			   sum-=200;
			   total++;
			   aslow--;
			   bfast++;
		       }
	            }
	    if(total==n)
	     break;
	}
    	printf("%d\n",sum);
	}
 return 0;
}


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

int main(){
	int n;
	while(cin>>n && n != 0){
		int i,j;
		for(i = 0;i < n;i++)

			cin>>tianji[i];
		for(i = 0;i < n;i++)
			cin>>qiwang[i];
		sort(tianji,tianji + n);
		sort(qiwang,qiwang + n);
		int money = 0;
		i = 0,j = n - 1;
		int k = i,l = j;
		while(true){
			while(tianji[i] > qiwang[k] && i <= j){
				money += 200;
				i++;
				k++;
			}
			while(tianji[j] > qiwang[l] && j >= i){
				money += 200;
				j--;
				l--;
			}
			if(i > j)
				break;
			else{
				if(tianji[i] != qiwang[l])
					money -= 200;
				i++;
				l--;
			}
		}
		cout<<money<<endl;
	}
	return 0;
}


int T[1010], Q[1010];
int main()
{
	int n;
	while(cin >> n && n)
	{
		int ret = 0;
		for (int i = 0; i< n; i++)
			cin >> T[i];
		for (int i = 0; i< n; i++)
			cin >> Q[i];
		sort(T, T + n);
		sort(Q, Q + n);
		int T_begin = 0, Q_begin = 0;
		int T_end = n - 1, Q_end = n - 1;
		while (T_begin <= T_end && Q_begin <= Q_end)
		{
			if (T[T_end] > Q[Q_end])
			{
				T_end--;
				Q_end--;
				ret++;
			}
			else if (T[T_begin] > Q[Q_begin])
			{
				T_begin++;
				Q_begin++;
				ret++;
			}
			else
			{
				if (T[T_begin] < Q[Q_end])
					ret--;
				T_begin++;
				Q_end--;
			}

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


int cmp(void const* a,void const* b)
{
	return *(int*)a-*(int*)b;
}
int main()
{
	int n;
	while(cin>>n)
	{
		int sum=0;
		if(n==0)
			break;
		int i;int a[1005];int b[1005];
		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);
		int p,q,c,d;
		p=0;c=0;q=n-1;d=n-1;
		while(n--)
		{
			if(a[p]>b[c])
			{

				sum=sum+200;
				p++;
				c++;

			}
			else if(a[q]>b[d])
			{

				sum=sum+200;
				q--;
				d--;

			}
			else
			{

				if(a[p]<b[d])
				{
				sum=sum-200;

				}

				if(a[p]>b[d])
				{
					sum=sum+200;
				}
				p++;
				d--;

			}
		}

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


int tianji[1010];
int qiwang[1010];

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

int main()
{
	int n;
	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]);
		qsort(tianji, n, sizeof(int), mycomp);
		qsort(qiwang, n, sizeof(int), mycomp);
		int ts = 0;
		int te = n-1;
		int qs = 0;
		int qe = n-1;
		int win = 0;
		while (ts<=te)
		{
			if (tianji[ts]>qiwang[qs])
			{
				win++;
				ts++;
				qs++;
			}
			else if (tianji[ts]<qiwang[qs])
			{
				win--;
				te--;
				qs++;
			}
			else if (tianji[te]>qiwang[qe])
			{
				win++;
				te--;
				qe--;
			}
			else if (tianji[te]<qiwang[qe])
			{
				win--;
				te--;
				qs++;
			}
			else
			{
				if (tianji[te]<qiwang[qs])
					win--;
				te--;
				qs++;
			}
		}
		printf("%d\n", win*200);
	}
	return 0;
}


const int SIZE=1005;
int tianji[SIZE];
int qiwang[SIZE];
int win=0;
int mycmp(const void * arg1, const void * arg2){
	return *(int*)arg2-*(int*)arg1;
}
int main()
{
	int n=0;
	int i;
	int b1,b2,e1,e2;
	while (cin>>n&&n!=0){
		win=0;
		for (i=0;i<n;i++)
			cin>>tianji[i];
		for (i=0;i<n;i++)
			cin>>qiwang[i];
		qsort(tianji,n,sizeof(int),mycmp);
		qsort(qiwang,n,sizeof(int),mycmp);
		b1=0,b2=0,e1=n-1,e2=n-1;
		while (true){
			if (tianji[b1]>qiwang[b2]){
				b1++;
				b2++;
				win+=200;
			}
			else if (tianji[e1]>qiwang[e2]){
				e1--;
				e2--;
				win+=200;
			}
			else{
				if (tianji[e1]<qiwang[b2])
					win-=200;
				e1--;
				b2++;
			}
			if (b1>e1)
				break;
		}
		cout<<win<<endl;
	}
	return 0;
}


int n;
int qiwang[1000];
int qiwangs,qiwange;
int tianji[1000];
int tianjis,tianjie;

int main(){
	int i;
	while(cin>>n && n != 0){
		for(i = 0;i < n;i++)
			cin>>tianji[i];
		for(i = 0;i < n;i++)
			cin>>qiwang[i];
		sort(tianji,tianji + n);
		sort(qiwang,qiwang + n);
		qiwangs = 0;
		qiwange = n - 1;
		tianjis = 0;
		tianjie = n - 1;
		int yinzi = 0;
		while(qiwangs <= qiwange){
			while(tianji[tianjis] > qiwang[qiwangs] && qiwangs <= qiwange){
				yinzi += 200;
				tianjis++;
				qiwangs++;
			}
			while(tianji[tianjie] > qiwang[qiwange] && qiwangs <= qiwange){
				yinzi += 200;
				tianjie--;
				qiwange--;
			}
			if(tianji[tianjis] < qiwang[qiwange] && qiwangs <= qiwange)
				yinzi -= 200;
			qiwange--;
			tianjis++;
		}
		cout<<yinzi<<endl;
	}
	return 0;
}


int e[1000],f[1000];
int main() {
	int n, i, p, w, d, m;
	while(scanf("%d",&n)!=EOF) {
		if(n==0)break;
		m=-n;
		for(i=0;i<n;i++)scanf("%d",e+i);
		for(i=0;i<n;i++)scanf("%d",f+i);
		sort(e, e+n); sort(f, f+n);
		for(p=0;p<n;p++) {
			w=d=0;
			for(i=p;i<n;i++) {
				if(e[i]==f[i-p]) d=1;
				else if(e[i]>f[i-p]) w++;
				else goto cnt;
			}
			if(w-p>m) m=w-p;
			if(!d) break;
cnt:;
		}
		printf("%d\n", m*200);
	}
}


int check (int n,int *a,int *b)
{
    int i,j,x,y,*k;
    k=(int *)malloc(n*sizeof(int));
    for (j=0;j<n;j++)
    {
        k[j]=0;
        x=a[0];
        for (i=0;i<n;i++)
        {
            a[i]=a[i+1];
        }
        a[n-1]=x;
        for (i=0;i<n;i++)
        {
          if (a[i]>b[i])  {k[j]++;}
          if (a[i]<b[i])  {k[j]--;}
        }
    }
    x=0;
    y=k[0];
    for (j=1;j<n;j++)
    {
      if (k[j]>y)
      {x=j;
      y=k[j];}
    }
    return y;
}
int com (const void *e1,const void *e2)
{
    int *p1,*p2;
    p1=(int *)e1;
    p2=(int *)e2;
    return (*p1-*p2);
}
int main()
{
    int s;
    for(s=0;;s++)
    {
        int n,*a,*b,i,m;
        scanf ("%d",&n);
        if (n==0)  break;
        else {a=(int*)malloc(n*sizeof(int));
        b=(int*)malloc(n*sizeof(int));
        for (i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        for (i=0;i<n;i++)
        {
            scanf("%d",&b[i]);
        }
        qsort (a,n,sizeof(int),com);
        qsort (b,n,sizeof(int),com);
        m=200*(check (n,a,b));
        printf("%d\n",m);}
    }
    getchar();
    getchar();
    getchar();
    return 0;
}


int vd(const void*t1,const void*t2)
{
   return *((int*)t1)>*((int*)t2)?-1:1;
}
main()
{
  int n;
  scanf("%d",&n);
  while(n!=0)
  {
   int i,j,m;
   int head=0;
   int ans=0;
   int tailt=n-1;
   int tailk=n-1;
   int*t=(int*)malloc(n*sizeof(int));
   int*k=(int*)malloc(n*sizeof(int));
   for(i=0;i<n;i++)
   {
     scanf("%d",&t[i]);
   }
   qsort(t,n,sizeof(int),vd);
   for(i=0;i<n;i++)
   {
     scanf("%d",&k[i]);
   }
   qsort(k,n,sizeof(int),vd);
   for(i=0;i<n;i++)
   {
     if(t[head]>k[i])
     {
       head++;
       ans+=200;
     }
     else if(t[head]<k[i])
     {
        tailt--;
        ans-=200;
     }
     else if(t[head]==k[i])
     {
      for(j=tailt,m=tailk;j>=head;j--,m--)
      {
        if(t[j]>k[m])
        {
          ans+=200;
          tailt--;
          tailk--;
        }
        else
        {
          if(t[j]<k[i])ans-=200;
          tailt=j-1;
          tailk=m;
          break;
         }
        }
      }
     if(head>tailt) break;
    }
   printf("%d\n",ans);
   scanf("%d",&n);
 }
   getchar();
   getchar();
}


int cmp(const void *a,const void *b)
{return *(int*)b-*(int*)a;}
main()
{
      int n,i,r;
      int tk,tm,qk,qm;
      int t[1000],q[1000];
      for(;;)
      {
          scanf("%d",&n);
          if(n==0) break;
          for(i=0;i<n;i++)scanf("%d",t+i);
          for(i=0;i<n;i++)scanf("%d",q+i);
          qsort(t,n,sizeof(int),cmp);
          qsort(q,n,sizeof(int),cmp);
          r=0;
          tk=0;
          tm=n-1;
          qk=0;
          qm=n-1;
          while(tk<=tm)
          {
                   if(t[tm]>q[qm]){r++;tm--;qm--;}
              else if(t[tk]>q[qk]){r++;tk++;qk++;}
              else if(t[tm]<q[qk]){r--;tm--,qk++;}
              else break;
          }
          printf("%d\n",200*r);

      }
}


int x[3000], y[3000], n, count, ans;

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

int main() {
	int i, j;
while (1) {
	scanf("%d", &n);
	if (n == 0) break;
	for (i = 1; i <= n; i++) scanf("%d", x + i);
	for (i = 1; i <= n; i++) scanf("%d", y + i);
	sort(x);
	sort(y);
	ans = -n * 200;
	for (i = 0; i < n; i++) {
		count = 0;
		for (j = 1; j <= n; j++)
			if (x[j] > y[i + j]) count += 200;
			else
			if (x[j] < y[i + j]) count -= 200;
		if (count > ans) ans = count;
	}
	printf("%d\n", ans);
}
}


int main()
{
	int n;
	int i,j,k;
	//int ftianji,ltianji;
	//int fqiwang,lqiwang;
	int tianji[1000];
	int qiwang[1000];
	int temptianji,tempqiwang;
	int money;
	int win,tie,lose;
	scanf("%d",&n);
	while(n!=0)
	{
	win = 0,tie = 0,lose = 0;
	for(i = 0;i < n;i++)
		scanf("%d",&tianji[i]);
	for(i = 0;i < n;i++)
		scanf("%d",&qiwang[i]);
	for(j = 0;j < n;j++)
	{
		for(k = 0;k < n - j - 1;k ++)
		{
		if(tianji[k] < tianji[k + 1])
			{
				temptianji = tianji[k];
				tianji[k] = tianji[k + 1];
				tianji[k + 1] = temptianji;
			}
		}
	}
	for(j = 0;j < n;j++)
	{
		for(k = 0;k < n - j - 1;k ++)
		{
		if(qiwang[k] < qiwang[k + 1])
			{
				tempqiwang = qiwang[k];
				qiwang[k] = qiwang[k + 1];
				qiwang[k + 1] = tempqiwang;
			}
		}
	}
	int tstart = 0;
	int tlast = n - 1;
	int kstart = 0;
	int klast = n - 1;
	int cnt = 0;//???
  for(i = 0;i < n;i++)//????????????
  {
   if(tianji[tstart]>qiwang[kstart])//tstart????????????????tianji???????
   {
    cnt++;
    tstart++;
    kstart++;
    continue;
   }
   if(tianji[tstart]<qiwang[kstart])//tianji????tianji???????????
   {
    cnt--;
    kstart++;
    tlast--;
    continue;
   }
   if(tianji[tstart] == qiwang[kstart])//??????
   {
    if(tianji[tlast] < qiwang[klast])//tianji?????????????????????
    {
     tlast--;
     kstart++;
     cnt--;
     continue;
    }
    if(tianji[tlast] > qiwang[klast])//tianji?????????????????
    {
     tlast--;
     klast--;
     cnt++;
     continue;
    }
    if(tianji[tlast] == qiwang[klast])//?????? ???tianji?????????
    {
     if(tianji[tlast] < qiwang[kstart])//??tianji??????????cnt?1
      cnt--;
     kstart++;
     tlast--;
    }
   }
  }
	money = 200 * cnt;
	printf("%d\n",money);
	scanf("%d",&n);
	}
	return 0;
}


void main()
{
	int m,l,qww_fast,tj_fast,qww_slow,tj_slow,n,game,win,turn;
	int qww[2000],tj[2000],out[300];
	for (game=0;;game++)
	{
		scanf("%d",&n);
		if (n==0) break;
		for (m=0;m<n;m++)
			scanf("%d",&tj[m]);
		for (l=0;l<n;l++)
			scanf("%d",&qww[l]);
		for (m=0;m<n;m++)
			for (l=0;l<n-m-1;l++)
			{
				if (tj[l]<tj[l+1])
				{
					turn=tj[l];
					tj[l]=tj[l+1];
					tj[l+1]=turn;
				}
			}
		for (m=0;m<n;m++)
			for (l=0;l<n-m-1;l++)
			{
				if (qww[l]<qww[l+1])
				{
					turn=qww[l];
					qww[l]=qww[l+1];
					qww[l+1]=turn;
				}
			}
		for (win=0,tj_slow=n-1,qww_slow=n-1,tj_fast=0,qww_fast=0;tj_slow>=tj_fast;)
		{
			if(tj[tj_slow]>qww[qww_slow])
			{
				win++;
				tj_slow--;
				qww_slow--;
			}
			else if (tj[tj_slow]<qww[qww_slow])
			{
				win--;
				tj_slow--;
				qww_fast++;
			}
			else
			{
				if (tj[tj_fast]>qww[qww_fast])
				{
					win++;
					tj_fast++;
					qww_fast++;
				}
				else if(tj[tj_fast]<qww[qww_fast])
				{
					win--;
					tj_slow--;
					qww_fast++;
				}
				else
				{
					if (tj[tj_slow]<qww[qww_fast])
					{
						win--;
					}
					qww_fast++;
					tj_slow--;
				}
			}
		}
		out[game]=win*200;
	}
	for(m=0;m<game;m++)
		printf("%d\n",out[m]);
}


const int N = 1001;
int n;
int tj[N],qw[N];
int x,y,a,b,ans;
void fight(int s, int t)
{
	if (tj[s] < qw[t])
		ans--;
	else if (tj[s] > qw[t])
		ans++;
}
int main()
{
	while (cin >> n)
	{
		if (n == 0) break;
		for (int i = 0; i < n; i++)
			cin >> tj[i] ;
		for (int i = 0; i < n; i++)
			cin >> qw[i];
		sort(tj,tj+n);
		sort(qw,qw+n);

		x = a = 0;
		y = b = n-1;
		ans = 0;

		for(int i = 0; i < n ; i++)
		{
			if (qw[y] < tj[b])
				fight(b--,y--);
			else if (qw[y] > tj[b])
				fight(a++,y--);
			else
			{
				if (qw[x] >= tj[a])
					fight(a++,y--);
				else if (qw[x] < tj[a])
					fight(a++,x++);
			}
		}
		cout << ans * 200 << endl;
	}
}


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


int cmp(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}
int main()
{
	int n, i, j, tian[1010], qi[1010];
	while(cin >> n)
	{
		if (n == 0)
			break;
		for (i = 0; i < n; i++)
			cin >> tian[i];
		for (i = 0; i < n; i++)
			cin >> qi[i];
		qsort(tian, n, sizeof(int), cmp);
		qsort(qi, n, sizeof(int), cmp);
		int tmax = n - 1;
		int tmin = 0;
		int qmax = n - 1;
		int qmin = 0;
		int count = 0;
		int money = 0;
		while (count != n)
		{
			if (tian[tmax] > qi[qmax])
			{
				tmax--;
				qmax--;
				count++;
				money += 200;
			}
			else if (tian[tmin] > qi[qmin])
			{
				tmin++;
				qmin++;
				count++;
				money += 200;
			}
			else
			{
				if (tian[tmin] < qi[qmax])
					money -= 200;
				tmin++;
				qmax--;
				count++;
			}
		}
		cout << money << endl;
	}
}


int Q_hs[MAX];
int T_hs[MAX];

int hs_cmp(const void *p, const void *q)
{
        return *(int *)p - *(int *)q;
}

int main(int ac, char **av)
{
        int n;
        while (scanf("%d", &n), n) {
                int i;
                for (i = 0; i < n; i++)
                        scanf("%d", &T_hs[i]);
                for (i = 0; i < n; i++)
                        scanf("%d", &Q_hs[i]);

                qsort(Q_hs, n, sizeof(int), hs_cmp);
                qsort(T_hs, n, sizeof(int), hs_cmp);

                for (i = 0; i < n; i++)
                        printf("(%d %d) ", Q_hs[i], T_hs[i]);
                printf("\n");

                /* greedy strategy */
                int Ql, Qr, Tl, Tr, cost = 0;
                Ql = Tl = 0;
                Qr = Tr = n - 1;

                while (Tl <= Tr) {
                        if (T_hs[Tl] > Q_hs[Ql]) {
                                cost += 200;
                                Tl++;
                                Ql++;
                        } else if (T_hs[Tr] > Q_hs[Qr]) {
                                cost += 200;
                                Tr--;
                                Qr--;
                        } else {
                                if (T_hs[Tl] < Q_hs[Qr]) {
                                        cost -= 200;
                                        Tl++;
                                        Qr--;
                                } else {
                                        Tl++;
                                        Qr--;
                                }
                        }
                }

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

        return 0;
}


int cmp(const void * e1, const void * e2)
{
	return *(int *)e1 - *(int *)e2;
}
int main()
{
	int tian[1000];
	int qi[1000];
	int i,n;
	int tf,tl;
	int qf,ql;
	int count;
	cin>>n;
	while(n >0)
	{
		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), cmp );
		qsort(qi,   n, sizeof(int), cmp );

		tf = 0 ;
		qf = 0 ;
		tl = n-1;
		ql = n-1;
		count = 0;
		while(n--)
		{
			if(tian[tf] > qi[qf] ){  //???
				count++;
				tf++;
				qf++;
			}
			else if(tian[tf] < qi[qf]){
				tf++;
				ql--;
				count --;
			}
			else{//  ????
				if(tian[tl] > qi[ql]){
					tl--;
					ql--;
					count++;
				}
				else if(tian[tl] < qi[ql]){
					count --;
					tf++;
					ql--;
				}
				else{//  ????
					if(tian[tf] < qi[ql])
						count--;
					//else if ==
					tf++;
					ql--;
				}

			}

		}
		printf("%d\n", count * 200);
		// next
		scanf("%d", & n);
	}
	return 0;
}


int mycompare(const void * e1,const void * e2)
{
	int * p1,*p2;
	p1=(int*)e1;
	p2=(int*)e2;
	return (*p2)-(*p1);
};
int main()
{
	int p,count,n,a[1001],b[1001],s1,s2,e1,e2,i;
	cin>>n;
	while(n!=0)
	{

		for(i=0;i<n;i++)
		{
			cin>>a[i];
		}
		for(i=0;i<n;i++)
		{
			cin>>b[i];
		}
		count=0;
		qsort(a,n,sizeof(int),mycompare);
		qsort(b,n,sizeof(int),mycompare);
		s1=s2=0;
		e1=e2=n-1;
		for(p=0;p<n;p++)
		{
			if(a[s1]>b[s2])
			{
				count++;
				s1++;
				s2++;
			}
			else
			{
				if(a[e1]>b[e2])
				{
					e1--;
					e2--;
					count++;
				}
				else
				{
					if(a[e1]<b[s2])
					{
						count--;
					}
					e1--;
					s2++;
				}
			}
		}
		cout<<count*200<<endl;
		cin>>n;
	}
	return 0;
}


int cmp(const void * a, const void * b) {
        return *(int *)a - *(int *)b;
}
int a[MAX], b[MAX], queue[MAX];
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();
                    win ++;
                }
                else {
                                if (a[i] == b[j])
                        enqueue(a[i --]);
                }
            }
                }
        draw = size();
                ans = (2 * win - n + draw) * 200;
                printf("%d\n", ans);
        }
        return 0;
}


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

int main()
{
	int i;
	int n;
	int t[1005];
	int w[1005];
	while(1)
	{
		cin>>n;
		if(n==0)
			break;
		for(i = 0 ; i < n; i++)
			cin>>t[i];
		for(i=0 ; i<n; i++)
			cin>>w[i];
		qsort(t,n,sizeof(t[0]),cmp);
		qsort(w,n,sizeof(w[0]),cmp);
		int count=0;
		int thead=0;
		int khead=0;
		int ttail=n-1;
		int ktail=n-1;
		while(thead<=ttail)
		{
			if(t[thead]>w[khead])//????>????????
			{
				count++;
				thead++;
				khead++;
			}
			else if(t[thead]<w[khead])//????<??????????????
			{
				ttail--;
				count--;
				khead++;
			}
			else//??
			{
				while(ttail>=thead)
				{
					if(t[ttail]>w[ktail])//???????????
					{
						count++;
						ttail--;
						ktail--;
					}
					else
					{
						if(t[ttail]<w[khead])
							count--;
						ttail--;
						khead++;
						break;
					}
				}
			}
		}
		cout<<count*200<<endl;
	}
	return 0;
}


int a[1000],b[1000];
int cmp( const void *a, const void *b )
{
	return ( *( long *)a) - ( *( long *)b);
}
int main()
{
	int n;
	while(1)
	{
		int sum=0,i,j,end1,end2;
		cin>>n;
		if(n==0)
			break;
		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 );
		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 com(const void *ele1,const void *ele2)
{
    int *p1,*p2;
    p1=(int*)ele1;
    p2=(int*)ele2;
    return *p2-*p1;
}

int main(int argc, char *argv[])
{
    int a[1000],b[1000],num,win=0,shu=0,i;
    while(1)
    {

		cin>>num;
		if(num==0)
			break;
		win=0;
		int tt=num-1;
		int tq=num-1;
		int ht=0;
		int hq=0;
		shu=0;
		for(i=0;i<num;i++)
			cin>>a[i];
		for(i=0;i<num;i++)
			cin>>b[i];
		qsort(a,num,sizeof(int),com);
		qsort(b,num,sizeof(int),com);
		while(ht<=tt)
		{
			if(b[tq]>a[tt])
			{
				hq++;
				tt--;
				shu++;
			}
			else if(b[tq]<a[tt])
			{
				win++;
				tt--;
				tq--;
			}
			else
			{
				if(a[ht]>b[hq])
				{
					win++;
					ht++;
					hq++;
				}
				else
				{
					if(a[tt]<b[hq])
						shu++;
					hq++;
					tt--;
			    }

			}
		}
		cout<<200*(win-shu)<<endl;
	}
    return EXIT_SUCCESS;
}


int dp[1010][1010];
int a[1010]={0},b[1010]={0};
int cmp1(const void *a,const void *b){
	return *(int *)a- *(int *)b;
}
int cmp2(const void *a,const void *b){
	return *(int *)b- *(int *)a;
}
int max(int a,int b){
	return a>b?a:b;
}
int mon(int i,int j){
	if(a[i]>b[j])	return 200;
	if(a[i]==b[j])	return 0;
	if(a[i]<b[j])	return -200;
	return 0;
}
int main(){
	int n;
	cin>>n;
	int i,j;
	while(n){
		memset(a,0,sizeof(int));
		memset(b,0,sizeof(int));
		for(i=0;i<n;i++){
			cin>>a[i];
		}
		for(i=0;i<n;i++){
			cin>>b[i];
		}
		qsort(a,n,sizeof(int),cmp1);//????
		qsort(b,n,sizeof(int),cmp2);//????
		memset(dp,0,sizeof(int));
		for(i=1;i<=n;i++){
			dp[i][0]=dp[i-1][0]+mon(n-i,i-1);
			for(j=1;j<i;j++){
				dp[i][j]=max(dp[i-1][j-1]+mon(j-1,i-1),dp[i-1][j]+mon(n-(i-j),i-1));
			}
			dp[i][i]=dp[i-1][i-1]+mon(i-1,i-1);
		}
		int Max=-99999999;
		for(i=0;i<n;i++){
			if(dp[n][i]>Max)Max=dp[n][i];
		}
		cout<<Max<<endl;

		cin>>n;
	}
	return 0;
}


int tianji[1000];
int qiwang[1000];
int comp(const void * a, const void * b)
{
	return *(int *)b - *(int *)a;
}
int main(void)
{
	int comp(const void * a, const void * b);
	int n;
	cin>>n;
	int i,j;
	while(n!=0)
	{
		for(i = 0; i < n; i++)
			cin>>tianji[i];
		for(i = 0; i < n; i++)
			cin>>qiwang[i];
		qsort(tianji,n,sizeof(int),comp);
		qsort(qiwang,n,sizeof(int),comp);
		j = 0;
		int score = 0;
		int index1 = 0;
		int index2 = n-1;
		int index3 = 0;
		int index4 = n-1;

		while(index1 <= index2)
		{
			if( tianji[index1] > qiwang[index3] )
			{
				score = score + 200;
				index1 = index1 + 1;
				index3 = index3 + 1;
			}
			else
			{
				if( tianji[index1] < qiwang[index3] )
				{
					score = score - 200;
					index3 = index3 + 1;
					index2 = index2 - 1;
				}
				else
				{
					if( tianji[index2] > qiwang[index4] )
					{
						score = score + 200;
						index2 = index2 - 1;
						index4 = index4 - 1;
					}
					else
					{
						if( tianji[index2] < qiwang[index3])
						{
							score = score - 200;
							index2 = index2 - 1;
							index3 = index3 + 1;
						}
						else
						{
							break;
						}
					}
				}
			}
		}
		cout<<score<<endl;
		cin>>n;
	}
	return 0;
}


//Hungary Algorithm

int a[1010];
int b[1010];
int n;
int money;

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

int input()
{

	int i;
	scanf("%d",&n);
	if(n==0)
	{
		return 0;
	}

	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++)
	{
		scanf("%d",&b[i]);
	}
	sort(a,n);
	sort(b,n);
	money = 0;
	return 1;
}

void main()
{
	while(input())
	{
		int i=0;
		int j=0;
		int backi = n-1;
		int backj = n-1;
		while(j<n&&i<=backi)
		{
			if(b[j]<a[i])
			{
				money+=200;
				i++;
				j++;
			}
			else if(b[j] == a[i])
			{
				int x;
				int y;
				for(x = backi,y = backj;x>=i;x--,y--)
				{
					if(a[x]>b[y])
					{
						money+=200;
						backi--;
						backj--;
					}
					else
					{
						if(a[x]<b[j])
						{
							money-=200;
						}
						x--;
						backi = x;
						backj = y;
						break;
					}
				}
				j++;
			}
			else
			{
				j++;
				money-=200;
				backi--;
			}
		}
		printf("%d\n",money);
	}
}


int cmp1(const void * p1, const void * p2)
{
	int * p3 = (int *)p1;
	int * p4 = (int *)p2;
	return *p3 - *p4;
}

int cmp2(const void * p1, const void * p2)
{
	int * p3 = (int *)p1;
	int * p4 = (int *)p2;
	return *p4 - *p3;
}

int q[1001], t[1001];

int main()
{
	int n;
	while (cin >> n)
	{
		if (n == 0)
			break;
		for (int i = 0; i < n; i ++)
			cin >> t[i];
		for (int i = 0; i < n; i ++)
			cin >> q[i];

		qsort(t, n, sizeof(int), cmp1);
		qsort(q, n, sizeof(int), cmp2);

		//for (int i = 0; i < n; i ++)
		//	cout << t[i] << ' ' << q[i] << endl;

		int result = 0;

		int tl, tr, ql, qr;
		tl = ql = 0;
		tr = qr = n - 1;

		while (ql <= qr && tl <= tr)
		{
			//cout << ql << ' ' << qr << endl;
			//cout << tl << ' ' << tr << endl;
			if (q[ql] < t[tr])
			{
				result += 200;
				ql ++;
				tr --;
				continue;
			}
			else
			{
				if (t[tl] > q[qr])
				{
					result += 200;
					tl ++;
					qr --;
				}
				else
				{
					if (t[tl] < q[ql])
					{
						result -= 200;
						tl ++;
						ql ++;
					}
					else
					{
						tl ++;
						ql ++;
					}
				}
			}
		}
		cout << result << endl;
	}

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


int cmp(const void* elem1,const void * elem2){
	int * p1,*p2;
	p1 = (int *) elem1;
	p2 = (int *) elem2;
	if(*p1 < *p2) return 1;
	if(*p1 == *p2 ) return 0;
	if(*p1 > *p2) return -1;
}

int main(){
	int n , i ,j ;
	int a[1005],b[1005];
	int p1,p2,end1,end2;
	int win;
	while(1){
		cin>>n;
		if(n == 0) break;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(i = 0;i < n;i++)
			cin>>a[i];
		for(i = 0;i < n;i++)
			cin>>b[i];

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

		win = 0;

		for(p1 = 0, p2 = 0, end1 = n-1,end2 = n-1 ; p1<=end1 && p2<=end2 ;){
			if(a[p1] > b[p2]){
				win ++;
				p1++;
				p2++;
			}
			if(a[p1] < b[p2]){
				win --;
				end1--;
				p2++;
			}
			if(a[p1] == b[p2]){
				if(a[end1] > b[end2]){
					win ++;
					end1 --;
					end2 --;
				}
				else if(a[end1] == b[end2]){
					if(a[end1] == b[p2]){
						end1 --;
						p2++;
					}
					else{
						win--;
						end1--;
						p2++;
					}
				}
				else {
					win--;
					end1--;
					p2++;
				}
			}
		}
		cout<<win * 200 <<endl;

	}
	return 0;
}


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

}


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

main()
{
      int n;
      int t[1000];
      int q[1000];
      int i,j,k,m;
      int r,tk,tm,qk,qm;
      for(;;)
      {
      scanf("%d",&n);
      if(n==0)
      break;
      for(i=0;i<n;i++)

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

      qsort(t,n,sizeof(int),compare);
      qsort(q,n,sizeof(int),compare);
      r=0;
      tk=0;
      tm=n-1;
     qk=0;
     qm=n-1;
     while(tk<=tm)
     {
                  if(t[tm]>q[qm])
                  {r++;tm--;qm--;}
                  else if(t[tk]>q[qk])
                  {r++;tk++;qk++;}
                    else if(t[tm]<q[qk])
                  {r--;tm--;qk++;}
                  else break;
}

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

}


int n;
int q[1001],t[1001];
int qshang,tshang,qxia,txia;

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

int main()
{
	while(cin>>n)
	{
		if(n==0) break;
		int i;
		for(i=1;i<=n;i++)
			cin>>t[i];
		for(i=1;i<=n;i++)
			cin>>q[i];
		qsort(q+1,n,sizeof(q[1]),cmp);
		qsort(t+1,n,sizeof(t[1]),cmp);

		int res=0;
		qxia=txia=n;
		qshang=tshang=1;
		while(qshang<=qxia && tshang<=txia)
		{
			if(t[txia]>q[qxia])
			{
				res++;
				qxia--;
				txia--;
			}
			else if(t[txia]<q[qxia])
			{
				txia--;
				qshang++;
				res--;
			}
			else
			{
				if(q[qshang]>t[tshang])
				{
					qshang++;
					txia--;
					res--;
				}
				else if(q[qshang]<t[tshang])
				{
					tshang++;
					qshang++;
					res++;
				}
				else
				{
					if(t[txia]<q[qshang])
					{
						txia--;
						qshang++;
						res--;
					}
					else
					{
						txia--;
						qshang++;
					}
				}
			}
		}
		cout<<res*200<<endl;
	}
	return 0;
}


int tian[1000], qiw[1000];
int n;
int main()
{
	while(cin>>n && n)
	{
		for(int i = 0;i < n;i ++)
			cin>>tian[i];
		for(int i = 0;i < n;i ++)
			cin>>qiw[i];
		sort(tian,tian + n);
		sort(qiw, qiw + n);
		int ti, tj, qi, qj;
		ti = qi = 0;
		tj = qj = n - 1;
		int sum = 0;
		for(int i = 0;i < n;i ++)
		{
			if(tian[ti] < qiw[qi])
			{
				sum -= 200;
				ti ++;
				qj --;
			}
			else if(tian[ti] > qiw[qi])
			{
				sum += 200;
				ti ++;
				qi ++;
			}
			else if(tian[tj] < qiw[qj])
			{
				sum -= 200;
				ti ++;
				qj --;
			}
			else if(tian[tj] > qiw[qj])
			{
				sum += 200;
				tj --;
				qj --;
			}
			else
			{
				if(tian[ti] > qiw[qj])
					sum += 200;
				else if(tian[ti] < qiw[qj])
					sum -= 200;
				ti ++;
				qj --;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}


int main()
{
	int n,i,tj[1005],qw[1005];
	int win;
	int tl,tr,ql,qr;
	while(cin>>n&&n!=0)
	{
		for(i=0;i<n;i++) cin>>tj[i];
		for(i=0;i<n;i++) cin>>qw[i];
		sort(tj,tj+n);
		sort(qw,qw+n);
		win=0;
		tl=ql=0;
		tr=qr=n-1;
		for(i=0;i<n;i++)
		{
			if(qw[ql]<tj[tl])
			{
				win++;
				ql++;
				tl++;
			}
			else if(qw[ql]>tj[tl])
			{
				win--;
				qr--;
				tl++;
			}
			else
			{
				if(qw[qr]<tj[tr])
				{
					win++;
					qr--;
					tr--;
				}
				else if(qw[qr]>tj[tr])
				{
					win--;
					qr--;
					tl++;
				}
				else
				{
					if(qw[qr]>tj[tl]) {win--;}
					qr--;
					tl++;

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


int cmp(const void *elem1,const void *elem2)
{
	int *p1,*p2;
	p1=(int *)elem1;
	p2=(int *)elem2;
	return *p2 - *p1;
}
int main()
{
	int mon=0;
	int a[1001];
	int b[1001];
	int n;
	while(cin>>n)
	{
		if(n==0)
		{
			break;
		}
		mon=0;
		int i;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
		}
		for(i=0;i<n;i++)
		{
			cin>>b[i];
		}
		int k,l,j;
		qsort(a,n,sizeof(int),cmp);
		qsort(b,n,sizeof(int),cmp);
		k=0;
		l=n-1;
		j=n-1;
		for(i=0;i<=j;i++)
		{
			if(a[k]>b[i])
			{
				mon+=200;
				k++;
				continue;
			}
			else if(a[k]<b[i])
			{
				mon-=200;
				l--;
				continue;
			}
			else
			{
				if(a[l]>b[j])
				{
					l--;
					j--;
					i--;
					mon+=200;
					continue;
				}
				else if(a[l]<b[j])
				{
					l--;
					mon-=200;
					continue;
				}
				else
				{
					if(a[l]==b[i])
					{
						l--;
						continue;
					}
					else
					{
						mon-=200;
						l--;
						continue;
					}
				}
			}

		}
		cout<<mon<<endl;
	}
	return 0;
}


int cmp(const void *a,const void *b)
{
return *(int *)b-*(int *)a;//???????????
}
int main()
{
int n,tian[1005],king[1005],tmax,tmin,kmax,kmin,i,j,s;
while(scanf("%d",&n),n>0)
{
   s=0;
   for(i=1;i<=n;i++)
   scanf("%d",&tian[i]);
   qsort(tian+1,n,sizeof(int),cmp);
   for(j=1;j<=n;j++)
   scanf("%d",&king[j]);
   qsort(king+1,n,sizeof(int),cmp);
   tmax=1;tmin=n;kmax=1;kmin=n;
   for(i=1;i<=n;i++)
   {
   if(tian[tmax]>king[kmax])
   {
           s++;
           tmax++;
           kmax++;
    }
    else
    if(tian[tmax]<king[kmax])
    {
    s--;
    tmin--;
    kmax++;
    }
    else
    if(tian[tmin]>king[kmin])
    {
    s++;
    tmin--;
    kmin--;
    }
    else
    if(tian[tmin]<king[kmin])
    {
    s--;
    tmin--;
      kmax++;
    }
    else
    if(tian[tmin]<king[kmax])
    {
    s--;
    tmin--;
    kmax++;
    }
   }
   printf("%d\n",s*200);
}
return 0;
}


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

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

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

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

		st = sq = 0;
		et = eq = n - 1;
		count = 0;
		while (st <= et)
		{
			if (t[et] > q[eq])
			{
				count ++;
				et --;
				eq --;
			}
			else if (t[et] < q[eq])
			{
				count --;
				et --;
				sq ++;
			}
			else
			{
				if (t[st] > q[sq])
				{
					count ++;
					st ++;
					sq ++;
				}
				else
				{
					if (t[et] < q[sq])
						count --;
					et --;
					sq ++;
				}
			}
		}
		cout << 200 * count << endl;
	}
	return 0;
}


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

int main()
{
   int n=1,i;
   int *t;
   int *q;
   //scanf("%d",&n);
   while(n!=0)
   {
      scanf("%d",&n);
      t=(int *)malloc(sizeof(int)*n);
      q=(int *)malloc(sizeof(int)*n);
      for (i=0;i<n;i++)
        scanf("%d",t+i);
      for (i=0;i<n;i++)
        scanf("%d",q+i);
      if (n!=0)
      printf("%d\n",run(t,q,n));
   }
}


int mycompare(const void *a, const void *b)
{
	return (*(int *)a)-(*(int *)b);
}
int main()
{
	int t[2000];
	int q[2000];
	int ncase;
	int i;
	int h;
	int pbegin;
	int tmax;
	int count;
	while(cin >> ncase)
	{
		if(ncase == 0)
			break;
		for(i = 0; i < ncase; i ++)
		{
			cin >> t[i];
		}
		qsort(t, ncase, sizeof(int), mycompare);
		for(i = 0; i < ncase; i ++)
		{
			cin >> q[i];
		}
		qsort(q, ncase, sizeof(int), mycompare);
		tmax = -99999999;
		pbegin = 0;
		count = 0;
		for(pbegin = 0; pbegin < ncase; pbegin ++)
		{
			count = 0;
			for(i = 0; i < ncase; i ++)
			{
				if(t[(pbegin+i)%ncase] > q[i])
					count += 200;
				if(t[(pbegin+i)%ncase] < q[i])
					count -= 200;
			}
			if(tmax < count)
				tmax = count;

		}
		cout << tmax << endl;
	}

	return 0;
}


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

     tfast=0;tslow=n-1;
     wfast=0;wslow=n-1;

    for(i=0;i<n;i++)
	{
	    if(t[tfast]==w[wfast])
		{
		   if(t[tslow]>w[wslow]){sub++;tslow--;wslow--;}
		   else if(t[tslow]<w[wslow]){sub--;tslow--;wfast++;}
           else if(t[tslow]==w[wslow])
		   {
			   if(t[tslow]<w[wfast]){sub--;tslow--;wfast++;}
               else if(t[tslow]==w[wfast]){break;}
		   }
		}
        else if(t[tfast]>w[wfast])
		{sub++;tfast++;wfast++;}
		else    {sub--;tslow--;wfast++;}
	}
   sum=sub*200;
   printf("%d\n",sum);
   sub=0;sum=0;
  }
}


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

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

int main()
{
    int n, i, j, count;
    int king_h[MAXSIZE];
    int general_h[MAXSIZE];
    char king_f[MAXSIZE];
    char general_f[MAXSIZE];
    while(scanf("%d", &n) != -1)
    {
        if(n == 0)
            break;
        for(i = 0; i < n; ++i)
            scanf("%d", &general_h[i]);
        for(i = 0; i < n; ++i)
            scanf("%d", &king_h[i]);
        qsort(general_h, n, sizeof(int), cmp);
        qsort(king_h, n, sizeof(int), cmpr);
        memset(king_f, 0, sizeof(char) * n);
        memset(general_f, 0, sizeof(char) * n);
        count = 0;
        for(i = 0; i < n; ++i)
        {
            for(j = 0; j < n; ++j)
                if(king_f[j] == 0 && general_h[i] > king_h[j])
                {
                    king_f[j] = 1;
                    general_f[i] = 1;
                    ++count;
                    break;
                }
        }
        for(i = n - 1; i >= 0; --i)
        {
            if(general_f[i] == 1)
                continue;
            for(j = 0; j < n; ++j)
                if(king_f[j] == 0 && king_h[j] == general_h[i])
                {
                    king_f[j] = 1;
                    general_f[i] = 1;
                    break;
                }
        }
        for(i = 0; i < n; ++i)
            if(general_f[i] == 0)
                --count;
        printf("%d\n", count * 200);
    }
    return 0;
}


/*
 * ??-???-1.cpp
 *
 *  Created on: 2011-3-29
 *      Author: user
 */
int compare(const void *element1,const void *element2)
{
	return (*(int *)element2)-(*(int *)element1);
}
int main()
{
	int n;
	int A[1000]={0},B[1000]={0};
	int front1,front2,back1,back2;
	int sum=0;
	while(cin>>n)
	{
		if(n==0)
			return 0;
		for(int i=0;i<n;i++)
			cin>>A[i];
		for(int i=0;i<n;i++)
			cin>>B[i];
		front1=front2=0;
		back1=back2=n-1;
		sum=0;
		qsort(A,n,sizeof(int),compare);
		qsort(B,n,sizeof(int),compare);
		/*for(int i=0;i<n;i++)
			cout<<A[i]<<endl;*/
		while(front1<=back1)
		{
			if(A[back1]>B[back2])
			{
				sum+=200;
				back1-=1;
				back2-=1;
			}
			else if(A[back1]==B[back2])
			{
				if(A[front1]<B[front2])
				{
					back1-=1;
					front2+=1;
					sum-=200;
				}
				else if(A[front1]==B[front2])
				{
					back1-=1;
					front2+=1;
					if(B[front2-1]>A[back1+1])
						sum-=200;
					else
						sum+=0;
				}
				else if(A[front1]>B[front2])
				{
					front1+=1;
					front2+=1;
					sum+=200;
				}
			}
			else if(A[back1]<B[back2])
			{
				sum-=200;
				back1-=1;
				front2+=1;
			}
			//cout<<sum<<endl;
			//cout<<front1<<" "<<back1<<" "<<front2<<" "<<back2<<endl;
		}
		cout<<sum<<endl;
		memset(A,0,sizeof(A));
		memset(B,0,sizeof(B));
	}
}


int MyCmp(const void* x,const void* y)
{
	return *((int*)y) - *((int*)x);
}

int main()
{
	int HorseNum,i,WinMatch,LoseMatch;
	int TianLastHorse,TianFirstHorse,QiFirstHorse,QiLastHorse;
	int TianHorse[1001];
	int QiHorse[1001];
	while(cin>>HorseNum){
		if( 0 == HorseNum )
			break;
		for(i = 1;i <= HorseNum;i ++)
			cin>>TianHorse[i];
		for(i = 1;i <= HorseNum;i ++)
			cin>>QiHorse[i];
		qsort(TianHorse+1,HorseNum,sizeof(int),MyCmp);
		qsort(QiHorse+1,HorseNum,sizeof(int),MyCmp);
		//TianHorse QiHorse ?????
		TianLastHorse = QiLastHorse = HorseNum;
		TianFirstHorse = QiFirstHorse = 1;
		WinMatch = LoseMatch = 0;
		while( TianFirstHorse <= TianLastHorse){
			if( TianHorse[TianFirstHorse] > QiHorse[QiFirstHorse] ){
				WinMatch ++;
				TianFirstHorse ++;
				QiFirstHorse ++;
			}
			else if( TianHorse[TianFirstHorse] < QiHorse[QiFirstHorse] ){
				//tian????????qi????
				LoseMatch ++;
				TianLastHorse --;
				QiFirstHorse ++;
			}
			else{
				//??????
				if( TianHorse[TianLastHorse] > QiHorse[QiLastHorse]){
					//??????
					WinMatch ++;
					TianLastHorse --;
					QiLastHorse --;
				}
				else {
					//????????
					if( TianHorse[TianLastHorse] < QiHorse[QiFirstHorse] )
						LoseMatch ++;
					TianLastHorse --;
					QiFirstHorse ++;
				}
			}
		}
		/*if( QiHorse[QiFirstHorse] < TianHorse[TianFirstHorse] )
			WinMatch ++;
		if( QiHorse[QiFirstHorse] > TianHorse[TianFirstHorse] )
			LoseMatch ++;*/
		cout<<( WinMatch - LoseMatch) * 200 <<endl;
	}
	return 0;
}


int paixu(int *x,int n)
{
	int i,j,temp;
	for(i=0;i<n-1;i++)
		for(j=0;j<n-i-1;j++)
		{
			if(*(x+j)<*(x+j+1))
			{
				temp=*(x+j);
				*(x+j)=*(x+j+1);
				*(x+j+1)=temp;
			}
		}
	return 0;
}

int main()
{
	int n,tj[1000],*p1=tj,qw[1000],*p2=qw,i,sum;
	scanf("%d",&n);
	while(n!=0){
	sum=0;
	for(i=0;i<n;i++) scanf("%d",(p1+i));
	for(i=0;i<n;i++) scanf("%d",(p2+i));
	paixu(p1,n);
	paixu(p2,n);
	int maxtj=0,mintj=n-1,maxqw=0,minqw=n-1;
	while(mintj>=maxtj)
	{
		if(*(p1+mintj)>*(p2+minqw))
		{
			sum++;
			mintj--;
			minqw--;
		}
		else if(*(p1+mintj)<*(p2+minqw))
		{
			sum--;
			mintj--;
			maxqw++;
		}
		else
		{
			if(*(p1+maxtj)>*(p2+maxqw))
			{
				sum++;
				maxtj++;
				maxqw++;
			}
			else if(*(p1+maxtj)<*(p2+maxqw))
			{
				sum--;
				mintj--;
				maxqw++;
			}
			else if(*(p1+mintj)==*(p2+maxqw))
			{
				mintj--;
				maxqw++;
			}
			else
			{
				sum--;
				mintj--;
				maxqw++;
			}
		}
	}
	printf("%d",sum*200);
	printf("\n");
	scanf("%d",&n);
	}
	return 0;
}


int a[1001];	//???????
int b[1001];	//???????

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

int main()
{
	int n,i;
	int win=0,lose=0;
	int maxa,maxb,mina,minb;
	int money;
	scanf("%d",&n);
	while(n!=0)
	{
		win=lose=0;
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		sort(a,n);
		for(i=0;i<n;i++)
			scanf("%d",&b[i]);
		sort(b,n);
		maxa=maxb=n-1;
		mina=minb=0;
		money=0;
		for(i=0;i<n;i++)
		{
			if(a[mina]>b[minb])
			{
				win++;
				mina++;
				minb++;
			}
			else if(a[maxa]>b[maxb])
			{
				win++;
				maxa--;
				maxb--;
			}
			else if(a[mina]==b[maxb])
			{
				mina++;
				maxb--;
			}
			else if(a[mina]<=b[minb])
			{
				lose++;
				mina++;
				maxb--;
			}
		}
		money=200*(win-lose);
		printf("%d\n",money);
		scanf("%d",&n);
	}
	return 0;
}


main()
{
int n;
while (1)
{
int a[1005],b[1005],i,j,ua[1005]={0},ub[1005]={0};
scanf("%d",&n);
if (n==0) break;//loop condition
//"a" stores the king's horses' data;"b" stores Tianji's hores' data
//ua[i] means whether horse[i] has raced

//begin{readdata}
for (i=1;i<=n;i++)
scanf("%d",&b[i]);

for (i=1;i<=n;i++)
scanf("%d",&a[i]);
//end{readdata}

//begin{sort(a)}[small->large]
for (i=1;i<n;i++)
for (j=i+1;j<=n;j++)
if (a[i]>a[j]) {int t=a[i]; a[i]=a[j]; a[j]=t;}
//end{sort(a)}

//begin{sort(b)}[small->large]
for (i=1;i<n;i++)
for (j=i+1;j<=n;j++)
if (b[i]>b[j]) {int t=b[i]; b[i]=b[j]; b[j]=t;}
//end{sort(b)}

int win=0,draw=0;
//begin{calculate(win)}
for (i=1;i<=n;i++)
for (j=n;j>=1;j--)//use Tianji's worst to win the king's best
if (b[i]>a[j]&&!ub[i]&&!ua[j])
{win+=1; ub[i]=1; ua[j]=1;}
//end{calculate(win)}

//begin{calculate(draw)}
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
if (a[i]==b[j]&&!ua[i]&&!ub[j])
{draw+=1; ua[i]=1; ub[j]=1;}
//end{calculate(draw)}
int ans=(win-(n-win-draw))*200;
printf("%d\n",ans);//printanswer
}
}


int main()
{
	int n, Speed1[ 1001 ], Speed2[ 1001 ];
	while( cin >> n && n )
	{
		int Answer = 0;
		for( int i = 0; i < n; i ++ )
			cin >> Speed1[ i ];
		for( int i = 0; i < n; i ++ )
			cin >> Speed2[ i ];
		sort( Speed1, Speed1 + n );
		sort( Speed2, Speed2 + n );
		int left1 = 0, right1 = n - 1, left2 = 0, right2 = n - 1;
		while( left1 <= right1 && left2 <= right2 )
		{
			if( Speed1[ left1 ] == Speed2[ left2 ] )
			{
				if( Speed1[ right1 ] > Speed2[ right2 ] )
				{
					Answer ++;
					right1 --;
					right2 --;
				}
				else if( Speed1[ right1 ] < Speed2[ right2 ] )
				{
					Answer --;
					left1 ++;
					right2 --;
				}
				else
				{
					if( Speed1[ left1 ] < Speed2[ right2 ] )
					{
						Answer --;
						left1 ++;
						right2 --;
					}
					else break;
				}
			}
			else if( Speed1[ left1 ] > Speed2[ left2 ] )
			{
				Answer ++;
				left1 ++;
				left2 ++;
			}
			else
			{
				Answer --;
				left1 ++;
				right2 --;
			}
		}
		cout << Answer * 200 << endl;
	}
}


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


int n;
int tian[1001],king[1001];
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;
                 }
         }
    }
}

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 sum=0;
        while(begin_tian<=end_tian)
        {
            while((tian[begin_tian]>king[begin_king])&&(begin_tian<=end_tian))
            {
                      sum=sum+200;
                      begin_tian++;
                      begin_king++;
            }
            while((tian[end_tian]>king[end_king])&&(begin_tian<=end_tian))
            {
                     sum=sum+200;
                     end_tian--;
                     end_king--;
            }
            if(begin_tian<=end_tian)
            {
                   if(tian[begin_tian]<king[end_king])
                    sum=sum-200;
                    begin_tian++;
                    end_king--;
            }
         }
    printf("%d\n",sum);
  }
  getchar();
  getchar();
}


int n;
int num1[1001];
int num2[1001];

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

int main()
{
while(1)
{
   cin>>n;
   if(!n)
    break;
   memset(num1,0,sizeof(num1));
   memset(num2,0,sizeof(num2));
   for(int i = 0 ; i < n; i++)
    cin>>num1[i];
   for(int i = 0 ; i < n; i++)
    cin>>num2[i];
   qsort(num1,n,sizeof(num1[0]),cmp);
   qsort(num2,n,sizeof(num2[0]),cmp);
   int res = 0;
   int m;
   int head = 0;
   int ttail = n-1;
   int ktail = n-1;
   for(int i = 0; i < n; i++)
   {
    if(num1[head] > num2[i])
    {
     res++;
     head++;
    }
    else if(num1[head] < num2[i])
    {
     ttail--;
     res--;
    }
    else      //??????????????????????
    {
     for(int j = ttail,m = ktail ; j>=head;j--,m--)
     {
      if(num1[j] > num2[m])
      {
       res++;
       ttail--;
       ktail--;
      }
      else
      {
       if(num1[j] < num2[i])
        res--;
       ttail = --j;
       ktail = m;
       break;
      }
     }
    }
    if(head > ttail)
      break;
   }
   cout<<res*200<<endl;
}

return 0;
}


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

int main()
{
	int n;
	while(cin>>n)
	{
		if(n == 0)
			return 0;
		int a[1005];
		int b[1005];
		int i;
		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);

		int pi,pj,qi,qj;
		pi = qi =0;
		pj = qj = n-1;

		int sum = 0;
		while(n--)
		{
			if(a[pi] > b[qi])
			{
				sum += 200;
				pi++;
				qi++;
			}
			else if(a[pj] > b[qj])
			{
				sum += 200;
				pj--;
				qj--;
			}
			else
			{
				if(a[pi] < b[qj])
					sum -= 200;
				pi++;
				qj--;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}


int comp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		int a[n];
		int b[n];
		int i,j;
		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);
        int first1=0,first2=0,last1=n-1,last2=n-1;
        int sum=0;
        while(first2<=last2){
        		if(a[last1]>b[last2]){
        			sum=sum+200;
        			last1--;
        			last2--;
        			continue;
        		}
        		if(a[last1]<b[last2]){
        			sum=sum-200;
        			first1++;
        			last2--;
        			continue;
        		}
        		if(a[last1]==b[last2]){
                	if(a[first1]<b[first2]) {sum=sum-200;last2--;first1++;continue;}
                	if(a[first1]>b[first2]) {sum=sum+200;first2++;first1++;continue;}
                	if(a[first1]==b[first2]){
        			if(a[first1]<b[last2]) sum=sum-200;
        			if(a[first1]==b[last2]) sum=sum;
        			if(a[first1]>b[last2]) sum=sum+200;
        			first1++;
        			last2--;
        			continue;
        		}
        	}
        }
        cout<<sum<<endl;
	}
	return 0;
}


int qi[1000],tian[1000];
int state[1001][1001];

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

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

int main()
{
	int i,j,n,tmp1,tmp2,maxi;
	while(cin>>n){
		if(n==0)
			break;

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

		for(i = 0; i <=n ; i ++)
			state[0][i]=0;

		for(i = 1; i <= n; i ++)
			for(j = 0; j <= i; j ++){
				if(j == 0)
					state[i][j]=state[i-1][j]+match(qi[i-1],tian[n-i+j]);
				else if(i == j){
					state[i][j]=state[i-1][j-1]+match(qi[i-1],tian[j-1]);
				}
				else
				{
					tmp1=state[i-1][j-1] + match(qi[i-1],tian[j-1]);
					tmp2=state[i-1][j] + match(qi[i-1],tian[n-i+j]);
					if(tmp1 > tmp2)
						state[i][j]=tmp1;
					else state[i][j]=tmp2;

				}
			}

		maxi=state[n][0];

		for(i = 1; i <= n; i ++){
			if(state[n][i] > maxi)
				maxi=state[n][i];
		}

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

	}
	return 0;
}


void list(int x[],int n)
{
    int i,j,temp;
    for(i=0;i<n-1;i++)
    {
          for(j=i+1;j<n;j++)
          {
                   if(x[j]>x[i])
                      {temp=x[i];x[i]=x[j];x[j]=temp;}
          }
    }
}
int main()
{
    void list(int x[],int n);
    int n,i,tian[1010],qi[1010],win=0,lose=0,*ptianlow,*pqilow,*ptianfast,*pqifast,money;
  for(;;money=win=lose=0)
  {
    scanf("%d",&n);
    if(n==0)
    break;
    else
    {

    for(i=0;i<n;i++)
          scanf("%d",&tian[i]);
    for(i=0;i<n;i++)
          scanf("%d",&qi[i]);
    list(tian,n);
    list(qi,n);

    ptianlow=&tian[n-1];
    ptianfast=&tian[0];
    pqilow=&qi[n-1];
    pqifast=&qi[0];

    for(;ptianfast<ptianlow+1;)
    {

    if(*ptianlow<*pqilow)
    {
          lose++;
          ptianlow--;
          pqifast++;
          continue;
    }

    else if(*ptianlow>*pqilow)
    {
          win++;
          ptianlow--;
          pqilow--;
          continue;
    }

    else
    {
          if(*ptianfast<*pqifast)
          {
                lose++;
                ptianlow--;
                pqifast++;
                continue;
          }
          else if(*ptianfast>*pqifast)
          {
                win++;
                ptianfast++;
                pqifast++;
                continue;
          }
          else
          {
                if(*ptianlow<*pqifast)
                {
                   lose++;
                   ptianlow--;
                   pqifast++;
                }
                else
                {
                    ptianlow--;
                    pqifast++;
                }
          }

    }
	}

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

return 0;
}


int n;
int King[1005];
int Tian[1005];
int Ans[1005];

int mCmp(const void *v1, const void *v2)
{
	int *i1=(int *)v1;
	int *i2=(int *)v2;
	return *i1-*i2;
}

int main()
{
	int i,j,k;
	int max;
	while(1)
	{
		cin>>n;
		if (n==0) return 0;
		memset(King,0,sizeof(King));
		memset(Tian,0,sizeof(Tian));
		memset(Ans,0,sizeof(Ans));
		max=-1000000;
		for(i=0;i<n;i++)
			cin>>Tian[i];
		for(i=0;i<n;i++)
			cin>>King[i];
		qsort(Tian,n,sizeof(int),mCmp);
		qsort(King,n,sizeof(int),mCmp);
		for(i=0;i<=n;i++)
		{
			Ans[i]=0;
			for(j=0;j<i;j++)
			{
				if(King[n-1-j]>Tian[j])
					Ans[i]-=200;
				else if (King[n-1-j]<Tian[j])
					Ans[i]+=200;
			}
			for(j=i;j<n;j++)
			{
				if(King[j-i]>Tian[j])
					Ans[i]-=200;
				else if (King[j-i]<Tian[j])
					Ans[i]+=200;
			}
			if(Ans[i]>=max) max=Ans[i];
		}
		cout<<max<<endl;
	}
}


int Tj[1001]={0};
int Qw[1001]={0};
int cmp( const void *a, const void *b )
{
	return (*( int *)a - *( int *)b );
}
int main()
{
	int N,i,j;
	int temp=200,count=0;
	while( cin>> N && N!=0 )
	{
			count=N;
			int start1=0,start2=0,end1=N-1,end2=N-1;
			int win=0,lose=0;
		for( i=0; i< N; i++ )
		{
			cin>> Tj[i];
		}
		qsort(Tj,N,sizeof( int ),cmp );

		for( i=0; i< N; i++ )
			cin>> Qw[i];
		qsort(Qw,N,sizeof( int ),cmp );
		while( count--)
		{
			if( Tj[start1] > Qw[start2] )
			{
				start1++;
				start2++;
				win++;
			}
			else if( Tj[end1] > Qw[end2] )
			{
				end1--;
				end2--;
				win++;
			}
			else if( Tj[start1] < Qw[start2] )
			{
				start1++;
				end2--;
				lose++;
			}
			else if( Tj[end1] < Qw[end2] )
			{
				start1++;
				end2--;
				lose++;
			}
			else if( Tj[end1] == Qw[end2] )
			{
				if( Tj[start1] < Qw[end2] )
				{
					start1++;
					end2--;
					lose++;
				}
			}
		}

      int sum= temp* ( win-lose );
	  cout<<sum<<endl;
	}
	return 0;
}


const int MAX = 1005;
int tian[MAX],qi[MAX];
int n;

int func(int t0,int q0,int t1,int q1){
	if(t0>t1 || q0>q1) return 0;

	while(tian[t1]>qi[q1]){
		t1--;q1--;
		return 1+func(t0,q0,t1,q1);
	}
	while(tian[t0]>qi[q0]){
		t0++;q0++;
		return 1+func(t0,q0,t1,q1);
	}

	if(tian[t0]<qi[q1])
		return func(t0+1,q0,t1,q1-1)-1;
	else if(tian[t0] == qi[q1])
		return func(t0+1,q0,t1,q1-1);
}

int main(){
	while(cin>>n){
		if(n==0) break;
		for(int i=0;i<n;i++)
			cin>>tian[i];
		for(int i=0;i<n;i++)
			cin>>qi[i];

		sort(tian,tian + n);
		sort(qi,qi+n);

		cout<<200*func(0,0,n-1,n-1)<<endl;
	}

	return 0;
}


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

void main()
{
	int n,i,win=0,lose=0,btj,bqw,etj,eqw;
	int *tj,*qw;
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
			break;
		else
		{
			tj=(int*)malloc(n*sizeof(int));
			qw=(int*)malloc(n*sizeof(int));
			for(i=0;i<n;i++)
				scanf("%d",tj+i);
			for(i=0;i<n;i++)
				scanf("%d",qw+i);
			sort(tj,n);
			sort(qw,n);
			btj=bqw=0;
			etj=eqw=n-1;
			while(btj<=etj)
			{
				if(*(tj+btj)>*(qw+bqw))
				{
					win=win+1;
					btj++;
					bqw++;
					continue;
				}
				if(*(tj+etj)>*(qw+eqw))
				{
					win=win+1;
					etj--;
					eqw--;
					continue;
				}
				if(*(tj+btj)<=*(qw+bqw))
				{
					if(*(tj+etj)<*(qw+bqw))
						lose=lose+1;
					bqw++;
					etj--;
					continue;
				}
			}
			printf("%d\n",win*200-lose*200);
			win=lose=0;
		}
	}
}


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

int main()
{
	int n;
	int TJ[2001];
	int QW[2001];

	while(cin >> n && n != 0)
	{
		for (int i = 0; i < n; i ++)
			cin >> TJ[i];
		for (int i = 0; i < n; i ++)
			cin >> QW[i];

		qsort(TJ, n, sizeof(int), compare);
		qsort(QW, n, sizeof(int), compare);

		int Tslow, Tfast, Qslow, Qfast;
		Tslow = Qslow = 0;
		Tfast = Qfast = n - 1;

		int bonus = 0;

		while(Tslow <= Tfast && Qslow <= Qfast)
		{
			if (TJ[Tfast] > QW[Qfast])
			{
				Tfast --;
				Qfast --;
				bonus ++;
			}
			else if (TJ[Tfast] < QW[Qfast])
			{
				Tslow ++;
				Qfast --;
				if (TJ[Tslow - 1] < QW[Qfast + 1])
					bonus --;
			}
			else
			{
				while(Tslow <= Tfast && Qslow <= Qfast)
				{
					if (TJ[Tslow] > QW[Qslow])
					{
						Tslow ++;
						Qslow ++;
						bonus ++;
					}
					else
					{
						Tslow ++;
						Qfast --;
						if (TJ[Tslow - 1] < QW[Qfast + 1])
							bonus --;
						break;
					}
				}
			}
		}
		cout << bonus * 200 << endl;
	}
	return 0;
}


int cmp(const void*p1,const void*p2)
{
	int *e1,*e2;
	e1=(int*)p1;
	e2=(int*)p2;
	return *e1 > *e2?1:-1;
}
int main()
{
	int n;
	int T[1001],E[1001];
	while(1)
	{
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		cin >> T[i];
		for(int i=0;i<n;i++)
		cin >> E[i];
		qsort(T,n,sizeof(int),cmp);
		qsort(E,n,sizeof(int),cmp);
		int ans=0;
		int lT=0,lE=0,rT=n-1,rE=n-1;
		while(lT<=rT)
		{
			if(T[lT]>E[lE]){ans+=200;lT++;lE++;}
			else if(T[lT]<E[lE])
			{
				ans-=200;
				lT++;rE--;
			}
			else
			{
				if(T[rT]<E[rE]){ans-=200;lT++;rE--;}
				else if(T[rT]>E[rE]){ans+=200;rE--;rT--;}
				else
				{
					if(T[lT]<E[rE]){ans-=200;lT++;rE--;}
					else {lT++;rE--;}
				}
			}
		}
		cout <<ans<<endl;
	}

	return 0;
}


void main()
{

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

		int i,j;

		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(i=0;i<n;i++)
		{
			scanf("%d",&b[i]);
			choose[i]=n;
			bchoose[i]=0;
		}

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

		int win=0,deuce=0,lose=0;

		int heada=0,headb=0,taila=n-1,tailb=n-1;
		while(heada<=taila&&headb<=tailb)
		{
			if(choose[heada]!=n)
			{
				heada++;
				continue;
			}
			else if(choose[taila]!=n)
			{
				taila--;
				continue;
			}
			else if(bchoose[headb]==1)
			{
				headb++;
				continue;
			}
			else if(bchoose[tailb]==1)
			{
				tailb--;
				continue;
			}
			else
			{
				if(a[heada]>b[headb])
				{
					choose[heada]=headb;
					bchoose[headb]=1;
					win++;
					heada++;
					headb++;
				}
				else if(a[taila]>b[tailb])
				{
					choose[taila]=tailb;
					bchoose[tailb]=1;
					win++;
					taila--;
					tailb--;
				}
				else
				{
					choose[taila]=headb;
					bchoose[headb]=1;
					if(a[taila]<b[headb])
						lose++;
					else
						deuce++;
					headb++;
					taila--;
				}
			}
		}

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

	}
}


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

int main() {
	int tj[1002], qw[2002], *q, n, ans;
	while(cin >> n) {
		if (n == 0)
			break;
		ans = -99999;
		for (int i = 0; i < n; i++)
			cin >> tj[i];
		for (int i = 0; i < n; i++)
			cin >> qw[i];
		qsort(tj, n, sizeof(int), mycmp);
		qsort(qw, n, sizeof(int), mycmp);
		for (int i = 0; i < n; i++)
			qw[i + n] = qw[i];
		for (q = qw; q < qw + n; q++) {
			int tmp = 0;
			for (int i = 0; i < n; i++) {
				if(tj[i] > q[i])
					tmp ++;
				else if (tj[i] < q[i])
					tmp --;
			}
//			cout << qw[0] << "|" << qw[1] << endl;
//			cout << tmp << endl;
			if (tmp > ans) ans = tmp;
		}
		cout << 200 * ans << endl;
	}
	return 0;
}


int main()
{
	int array_1[1005],array_2[1005];
	int num;
	int count;
	int first;
	int last;
	while(cin>>num)
	{
		if(num==0)
			break;
		count=0;
		first=0;
		last=num;
		for(int i=0;i<num;i++)
		{
			cin>>array_1[i];
		}
		for(int i=0;i<num;i++)
		{
			cin>>array_2[i];
		}
		sort(array_1,array_1+num);
		sort(array_2,array_2+num);
		for(int i=0;i<num;i++)
		{
			if(array_1[i]>array_2[first])
			{
				count=count+200;
				first++;
			}
			else
			{
				while(array_1[num-1]>array_2[last-1]&&num-1>i)
				{
					count=count+200;
					num--;
					last--;
				}
				if(array_1[i]<array_2[last-1])
				{
					count=count-200;
					last--;
				}
				else
				last--;
			}

		}
		cout<<count<<endl;
	}
	return 0;
}


int main()
{
	int king_horse[1010], tian_horse[1010], king_head, tian_head, king_tail, tian_tail, n = 0, i = 0, sum = 0, flag = 0;
	while (cin >> n && n != 0)
	{
		sum = 0;
		flag = 0;
		for (i = 0; i < n; i ++)
			cin >> tian_horse[i];
		for (i = 0; i < n; i ++)
			cin >> king_horse[i];
		sort(tian_horse, tian_horse + n);
		sort(king_horse, king_horse + n);
		king_head = tian_head = 0;
		king_tail = tian_tail = n - 1;
		while (king_head <= king_tail && tian_head <= tian_tail)
		{
			if (tian_horse[tian_tail] > king_horse[king_tail])
			{
				sum = sum + 200;
				tian_tail --;
				king_tail --;
			}
			else
			{
				while (king_head <= king_tail && tian_head <= tian_tail)
				{
					if (tian_horse[tian_head] > king_horse[king_head])
					{
						sum = sum + 200;
						tian_head ++;
						king_head ++;
					}
					else
					{
						if (tian_horse[tian_head] < king_horse[king_tail])
							sum = sum - 200;
						tian_head ++;
						king_tail --;
						break;
					}
				}
			}
			if (tian_horse[tian_head] > king_horse[king_tail])
			{
				flag = 1;
				break;
			}
		}
		if (flag == 1)
			sum = sum + (tian_tail - tian_head + 1) * 200;
		cout << sum << endl;
	}
	return 0;
}


int tj[1000],qw[1000];

int main(){
	//freopen("data.txt","r",stdin);
	int n,i,j,w,win,c,m;
	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);
		m=-n;
		for(i=0;i<n;i++)
		{
			c=-i;
			for(j=i,w=0;j<n&&tj[j]>=qw[w];j++,w++)
				if(tj[j]>qw[w])
					c++;
			if(j==n&&c>m)
				m=c;
		}
		printf("%d\n",m*200);
	}
	return 0;
}


int qi[1001];
int tian[1001];

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

int main()
{
	int n;
	int count;
	while(cin>>n)
	{
		if(n==0) break;
		count=0;
		int i,j;
		for(i=0;i<n;i++)
			cin>>tian[i];
		for(i=0;i<n;i++)
			cin>>qi[i];

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

		int l=0,m=0;
		for(i=n-1,j=n-1;i>=l&&j>=m;)
		{
			if(tian[i]<qi[j])
			{
				count--;
				i--;
				m++;
			}
			else if(tian[i]>qi[j])
			{
				count++;
				i--;
				j--;
			}
			else
			{
				if(tian[l]>qi[m])
				{
					count++;
					l++;
					m++;
				}
				else
				{
					if(qi[m]!=tian[i])count--;
					m++;
					i--;
				}
			}
		}
		cout<<count*200<<endl;
	}
	return 0;
}


static int cmp(const void *a, const void *b)
{
	return *(int *)b - *(int *)a;
}
int main()
{
	int n,a[1000]={0},b[1000]={0},t,s,j,p,t1,p1,c,tk,tm,qk,qm;
	for(;;)
	{
		scanf("%d",&n);
		if (n==0) break;
		t1=0;
		p1=0;
		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 if(a[tm]>b[qk])
			{
				t++;
				tm--;
				qk++;
			}
			else
			{
				tm--;
				qk++;
			}
		}
		printf("%d\n",t*200-s*200);
	}
	return 0;
}


void saima(int a,int b[1500],int d[1500]);
void paixu(int e[1500],int c);
int main(){
	int tianji[1500],kingma[1500];
	int n,i,num=0;
	do{
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&tianji[i]);
		}
		for(i=0;i<n;i++){
			scanf("%d",&kingma[i]);
		}
		if(n==0){
			break;
		}
		paixu(tianji,n);
		paixu(kingma,n);
		saima(n,tianji,kingma);
	}while(n!=0);
	return 0;

}
void paixu(int e[1500],int c){
	int temp,k,l;
	for(k=0;k<c-1;k++){
		for(l=0;l<c-1;l++){
			if(e[l]<e[l+1]){
				temp=e[l];
				e[l]=e[l+1];
				e[l+1]=temp;
			}
		}
	}
}
void saima(int a,int b[1500],int d[1500]){
	int qian=0,head=0,twei=a-1,kwei=a-1;
	int j,x,y;
	for(j=0;j<a;j++){
		if(b[head]>d[j]){
			head++;
			qian+=200;
		}else{
			for(x=twei,y=kwei;x>=head;x--,y--){
				if(b[x]>d[y]){
					qian+=200;
					twei--;
					kwei--;
				}
				else{
					if(b[x]<d[j]){
					qian-=200;
					}
					twei--;
					break;
				}

			}

		}
		if(twei<head){break;}
	}
	printf("%d\n",qian);
}


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

int main()
{
    int w[1500], t[1500];
    int wsymb[1500], tsymb[1500];
    int n, i, j, tot;

    while( scanf("%d",&n), n )
    {
        for( i = 0; i < n; i++ )
            scanf( "%d", &t[i] );
        for( i = 0; i < n; i++ )
            scanf( "%d", &w[i] );

        qsort( w, n, sizeof(int), comp );
        qsort( t, n, sizeof(int), comp );

        memset( wsymb, 0, n * sizeof(int) );
        memset( tsymb, 0, n * sizeof(int) );
        tot = 0;

        for( i = 0; i < n; i++ )
        {
            for( j = n - 1; j >= 0 && (wsymb[j] || w[j] >= t[i]); j-- );
            if( j < 0 ) continue;
            wsymb[j] = tsymb[i] = 1;
            tot++;
        }

        for( i = j = 0; i < n; i++ )
        {
            if( wsymb[i] ) continue;
            while( j < n && (tsymb[j] || w[i] > t[j]) ) j++;
            if( j == n ) break;
            if( w[i] == t[j] )
                wsymb[i] = tsymb[j++] = 1;
        }
        for( i = 0; i < n; i++ )
            if( !wsymb[i] ) tot--;

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

    return 0;
}


//C++ program by Ruby;
//to judge whether n could be divided by 3,5,7.
int main()
{
	int n,s;//n for testing number;s for a sumer
	cin>>n;
	s=0;
	if (n%3==0)
	{
		s=s+1;
		cout<<"3";
	}
	if (n%5==0)
	{
		if (s>=1) cout<<" ";
		s=s+1;
		cout<<"5";
	}
	if (n%7==0)
	{
		if (s>=1) cout<<" ";
		s=s+1;
		cout<<"7";
	}
	if (s==0)
		cout<<"n"<<endl;
	return 0;
}


int main()
{
	int x, front_number_exist;
	front_number_exist = false;
	cin >> x;
	if (x % 3 == 0)
	{
		front_number_exist = 1;
		cout << 3;
	}
	if (x % 5 == 0)
	{
		if (front_number_exist)
		{
			cout << " 5";
		}
		else
		{
			front_number_exist = 1;
			cout << "5";
		}
	}
	if (x % 7 == 0)
	{
		if (front_number_exist)
		{
			cout << " 7";
		}
		else
		{
			front_number_exist = 1;
			cout << "7";
		}
	}
	else
	{
		if (front_number_exist == 0)
		{
			cout << "n";
		}
	}
	return 0;
}


//*****???????????*****
//*****?????            *****
//*****???2013.9.27        ****

int main()
{
	int n;
	cin >> n;
	int sum = 0;
	if (n % 3 == 0)
		sum = sum +3;
	if (n % 5 == 0)
		sum = sum +5;
	if (n % 7 == 0)
		sum = sum +7;
	switch (sum)
	{
	    case 0: cout << "n" << endl; break;
		case 3: cout << 3 << endl; break;
		case 5: cout << 5 << endl; break;
		case 7: cout << 7 << endl; break;
		case 8: cout << "3 5" << endl; break;
		case 10: cout << "3 7" << endl; break;
		case 12: cout << "5 7" << endl; break;
		case 15: cout << "3 5 7" << endl; break;
		default: cout << "error" << endl; break;
	}
	return 0;
}


void main()
{
	int n,num;
	scanf("%d",&num);
	if(num%3==0)
	{if(num%5==0)
	{if(num%7==0)
	printf("%d %d %d",3,5,7);
	else
		printf("%d %d",3,5);
	}
	else if(num%7==0)
		printf("%d %d",3,7);
	else printf("%d",3);
	}
	else
		if(num%5==0)
		{if(num%7==0)
		printf("%d %d",5,7);
		else printf("%d",5);
		}
		else if(num%7==0)
			printf("%d",7);
		else
			printf("n");
}


main()
{
      int n, is3, is5, is7;
      int is;
      scanf("%d", &n);

      is3 = (n % 3 == 0);
      is5 = (n % 5 == 0);
      is7 = (n % 7 == 0);

      is = is3 + is5 + is7;
      switch(is)
      {
                case 0:
                     {
                           printf("n");
                           break;
                     }
                case 3:
                     {
                           printf("3 5 7");
                           break;
                     }
                case 2:
                     {
                           if(is3 && is5) printf("3 5");
                           if(is5 && is7) printf("5 7");
                           if(is7 && is3) printf("3 7");
                           break;
                     }
                case 1:
                     {
                           if(is3) printf("3");
                           if(is5) printf("5");
                           if(is7) printf("7");
                     }
      }
}


int main()
{
	int a,b=3,c=5,d=7;//??a?????
    cin>>a;
	if(a%b==0)
		if(a%c==0)
			if(a%d==0)
			cout<<b<<" "<<c<<" "<<d;
			else cout<<b<<" "<<c;
        else if(a%d==0)cout<<b<<" "<<d;
             else cout<<b;
	else
 		if(a%c==0)
			if(a%d==0)
			cout<<c<<" "<<d;
			else cout<<c;
        else if(a%d==0)cout<<d;
             else cout<<"n";
    return 0;
}


int main()
{
    int n,a,b,c,sum;
    scanf("%d",&n);
    if(n%3==0)
    a=3;
    else
    a=0;
    if(n%5==0)
    b=5;
    else
    b=0;
    if(n%7==0)
    c=7;
    else
    c=0;
    sum=a+b+c;
    switch(sum)
    {
    case 0:printf("n");break;
    case 7:printf("7");break;
    case 5:printf("5");break;
    case 3:printf("3");break;
    case 12:printf("5 7");break;
    case 8:printf("3 5");break;
    case 10:printf("3 7");break;
    case 15:printf("3 5 7");break;
    return 0;
    }
}


int main()
{
	int num;
	scanf("%d",&num);
	if(num%3==0)
	{
		printf("3");
		if(num%5==0)
		{
			printf(" %d",5);
			if(num%7==0)
				printf(" %d",7);
		}
		else if(num%7==0)
			printf(" %d",7);
	}
	else if(num%5==0)
		{
			printf("%d",5);
			if(num%7==0)
				printf(" %d",7);
		}
	else if(num%7==0)
			printf("%d",7);
	else
		printf("n");
	return 0;
}


int main()
{
	int a,b,c;
	scanf("%d",&a);
	b=0;
	c=a%3;
	if(c==0) b++;
	c=a%5;
	if(c==0) b=b+2;
	c=a%7;
	if(c==0) b=b+4;
	switch(b)
	{
	case 7:printf("3 5 7");break;
	case 6:printf("5 7");break;
	case 5:printf("3 7");break;
	case 4:printf("7");break;
	case 3:printf("3 5");break;
	case 2:printf("5");break;
	case 1:printf("3");break;
	case 0:printf("n");break;
	}

}


int main()
{
    int n;
    scanf("%d",&n);
    int r3 = 0, r5 = 0, r7 = 0;
    if (n%3!=0) r3 = 1;
    if (n%5!=0) r5 = 1;
    if (n%7!=0) r7 = 1;
    int temp = r3*4 + r5*2 +r7;
    switch (temp)
    {
        case 7 :
             printf("n\n");
             break;
        case 1 :
             printf("3 5\n");
             break;
        case 2 :
             printf("3 7\n");
             break;
        case 4 :
             printf("5 7\n");
             break;
        case 6 :
             printf("7\n");
             break;
        case 5 :
             printf("5\n");
             break;
        case 3 :
             printf("3\n");
             break;
        case 0 :
             printf("3 5 7\n");
             break;
    }
    return 0;
}


const int a[3] = {3, 5, 7};

int sum, b[10];

int main() {
    int N;
    cin >> N;
    int sum = 0;
    for (int i = 0; i < 3; i++) {
        if (N % a[i] == 0) {
            sum ++;
            b[sum] = a[i];
        }
    }
    if (sum == 0) cout << "n" << endl; else {
        cout << b[1];
        for (int i = 2; i <= sum; i++) cout << " " << b[i];
        cout << endl;
    }
    return 0;
}


void main()
{
	int m, a,b,c,d,sum=0;

	scanf("%d",&m);
	if (m%3==0)
		a=1;
	else a=0;
	if (m%5==0)
		b=1;
	else b=0;
	if (m%7==0)
		c=1;
	else c=0;

	sum=a+b+c;

	if (sum==3)
		printf("3 5 7\n");
	else
		if (sum==2)
		{
			if (a==b)
				printf("3 5");
			else
				if (a==c)
					printf("3 7");
				else printf("5 7");
		}
		else
			if (sum==1)
			{
				d=a*3+b*5+c*7;
				printf("%d\n",d);
			}
			else printf("n\n");

}


int main()
{
	int Number;
	cin>>Number;
	if(Number%3==0&&Number%5==0&&Number%7==0)
	cout<<3<<" "<<5<<" "<<7<<endl;
	if(Number%3==0&&Number%5==0&&Number%7!=0)
	cout<<3<<" "<<5<<endl;
	if(Number%3==0&&Number%5!=0&&Number%7==0)
	cout<<3<<" "<<7<<endl;
	if(Number%3!=0&&Number%5==0&&Number%7==0)
	cout<<5<<" "<<7<<endl;
    if(Number%3!=0&&Number%5!=0&&Number%7==0)
    cout<<7<<endl;
     if(Number%3!=0&&Number%5==0&&Number%7!=0)
    cout<<5<<endl;
     if(Number%3==0&&Number%5!=0&&Number%7!=0)
    cout<<3<<endl;
    if(Number%3!=0&&Number%5!=0&&Number%7!=0)
    cout<<"n"<<endl;
	cin.get();	cin.get();	cin.get();	cin.get();
	return 0;
}


int main(void)
{
    int n, a, b, c;
    scanf("%d", &n);
    if(n%7==0)
    {
        if(n%5==0)
        {
            if(n%3==0)
                printf("3 5 7");
            else
                printf("5 7");

        }
        else if(n%3==0)
            printf("3 7");
        else
            printf("7");
    }
    else if(n%5==0)
    {
        if(n%3==0)
            printf("3 5");
        else
            printf("5");
    }
    else if (n%3==0)
        printf("3");
    else
    printf("n");
    return 0;
}


int main()
{
int a;
int i=0;
scanf("%d",&a);
if(a%3==0)
 i=i+3;
if(a%5==0)
i=i+5;
if(a%7==0)
 i=i+7;
switch(i)  {
case 0:
printf("n");break;
case 3:
printf("3");break;
case 5:
printf("5");break;
case 7:
printf("7");break;
case 8:
printf("3 5");break;
case 10:
printf("3 7");break;
case 12:
printf("5 7");break;
case 15:
printf("3 5 7");break;
}
return 0;
}