semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
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 main()
{
	int n,i,j,x,y,vTian[1000],vQi[1000],cnt,t;
	while(scanf("%d",&n),n)
	{
		cnt=0;
		for(i=0;i<n;i++)
		{
			scanf("%d",&vTian[i]);
		}
		for(i=0;i<n;i++)
		{
			scanf("%d",&vQi[i]);
		}

		for(i=n-1;i>=0;i--)
		{
			for(j=0;j<i;j++)
			{
				if(vTian[j]>vTian[j+1])
				{
					t=vTian[j];
					vTian[j]=vTian[j+1];
					vTian[j+1]=t;
				}
				if(vQi[j]>vQi[j+1])
				{
					t=vQi[j];
					vQi[j]=vQi[j+1];
					vQi[j+1]=t;
				}
			}
		}

		x=y=n-1;
		i=j=0;
        while(i<=x)      
        {  
            if(vTian[x]>vQi[y])  
            {
                x--;  
                y--;  
                cnt+=200;  
            }  
            else if(vTian[i]>vQi[j])  
            {
                i++;  
                j++;  
                cnt+= 200;  
            }  
            else  
            {
                if(vTian[i]<vQi[y])  
                    cnt-= 200;  
                i++;  
                y--;  
            }  
        } 
		printf("%d\n",cnt);
	}
	return 0;
}
void sort(int a[],int n)              /*???????? */
{
	int i,j,k,t;
	for (i=0;i<n;i++)
	{	k=i;
		for (j=i;j<n;j++)
			if (a[j]>a[k])
				k=j;
		if (i!=k)
			{t=a[i];	
			a[i]=a[k];
			a[k]=t;}
	}
}

main()
{	int n,i,j,k,l,s;                  //i???????????????????????
                                      //j??????????????????????
                                      //l?????????????????????? 
                                      //????????????????????????????l-j+i 
                                      //k??????????n???
									  //s??????????1,0?-1? 
	int t[MAX],q[MAX];
	while (1)
		{scanf("%d",&n);
		if (n==0)
			break;
		for (i=0;i<n;i++)
			scanf("%d",&t[i]);
		for (i=0;i<n;i++)
			scanf("%d",&q[i]);
		sort(t,n);
		sort(q,n);
		s=0;	 
		for (k=0,i=0,j=0,l=n-1;k<n;k++)
			{	if (t[i]>q[j])                //??????????????????????? 
					{i++;
					j++;
					s++;}
				else if (t[l-j+i]>q[l])       //???????????????????????
					{l--;
					s++;}
					else if (t[l-j+i]<q[j])   //??????????????????????????????
					                          //?????????????????? 
						{j++;
						s--;}
						else                  //???????????????????
						j++;
												
			}
		printf("%d\n",s*MONEY);			
					
					
					
				
				
			}		
		}
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;
}
main()
{
      int a[1001],b[1001],i,n,t,u,j,k,s,v,f1,f2,s1,s2;
      do
      {
      scanf("%d",&n);
      if (n!=0)
      {
      for(i=0;i<n;i++)
      {
                      scanf("%d",&a[i]);
      }      
      for(i=0;i<n;i++)
      {
                      scanf("%d",&b[i]);
      }
      t=0;u=0; 
      for(j=n;j>1;j--)
      {
                      for(k=0;k<j-1;k++)
                      {
                        if(a[k+1]>a[k])
                        {
                                       t=a[k];
                                       a[k]=a[k+1];
                                       a[k+1]=t;
                        }
                        if(b[k+1]>b[k])
                        {
                                       u=b[k];
                                       b[k]=b[k+1];
                                       b[k+1]=u;
                        }
                      }
      }
      v=0;
      int f1=0;
      int f2=0;
      int s1=n-1;
      int s2=n-1;
      while(f1!=s1&&f2!=s2)
      {
      if(a[f1]>b[f2])
      {
          v +=200;
          f1++;
          f2++;
      }
      if(a[f1]<b[f2])
      {
          v -=200;
          f2++;
          s1--;     
      }
      if(a[f1]==b[f2])
      {
           if(a[s1]>b[s2])
           {
                v += 200;
                s1--;
                s2--;
           }      
           else 
           {if(a[s1]<=b[s2])
                if(a[s1]<b[f2])
                {v -=200;
                s1--;
                f2++;
                }
                else if(a[s1]==b[f2])
                {
                s1--;
                f2++;
                }
           }
      }
      }
      if(a[f1]>b[f2])
      v += 200;
      else if(a[f1]<b[f2])
      v -= 200;
      printf("%d\n",v);
      }
     }while(n!=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;  
}
main()
{
	int n,t,input[2][1000],i,j,k,win,money;
	for(;;)
	{
		win=0;
		scanf("%d",&n);
		if(0==n) break;
		for(i=0;i<2;i++)
		{
			for(j=0;j<n;j++)
			{
				scanf("%d",&input[i][j]);
			}
		}
		for(i=0;i<n;i++)
		{
			for(j=i+1;j<n;j++)
			{
				if(input[1][i]<input[1][j])
				{
					t=input[1][i];
					input[1][i]=input[1][j];
					input[1][j]=t;
				}
				if(input[0][i]<input[0][j])
				{
					t=input[0][i];
					input[0][i]=input[0][j];
					input[0][j]=t;
				}
			}
		}
		while(n>0)
		{
			if(input[0][n-1]>input[1][n-1])
			{
				win++;
				n--;
			}
			else if(input[0][n-1]<input[1][n-1])
			{
				win--;
				for(i=0;i<n-1;i++)
					input[1][i]=input[1][i+1];
				n--;
			}
			else
			{
				if(input[0][0]<input[1][0])
				{
					win--;
					for(i=0;i<n-1;i++)
						input[1][i]=input[1][i+1];
					n--;
				}
				else if(input[0][0]>input[1][0])
				{
					win++;
					for(i=0;i<n-1;i++)
					{
						input[0][i]=input[0][i+1];
						input[1][i]=input[1][i+1];
					}
					n--;
				}
				else
				{
					if(input[0][n-1]<input[1][0])
					{
						win--;
						for(i=0;i<n-1;i++)
							input[1][i]=input[1][i+1];
						n--;
					}
					else
					{
						n--;
					}
				}
			}
		}
	money=win*200;
	printf("%d\n",money);
	}
}
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;
}
int cmp(const void *a,const void *b)
{
  if(*((int*)a)>*((int*)b))return -1;
  else if(*((int*)a)<*((int*)b))return 1;
  else return 0;
}
int main()
{
  int n,a[1000],b[1000],i,sum,s1,s2,i1,i2;
  scanf("%d",&n);
  while(n)
  {
    sum=0;
    for(i=0;i<n;i++)scanf("%d",&a[i]);
    for(i=0;i<n;i++)scanf("%d",&b[i]);
    qsort(a,n,sizeof(a[0]),cmp);
    qsort(b,n,sizeof(b[0]),cmp);
    i1=i2=n-1;
    s1=s2=0;
    while(s1<=i1)
    {
      while(a[i1]!=b[i2]&&s1<=i1)
      {
        if(a[i1]>b[i2]){sum++;i1--;i2--;}
        else{sum--;i1--;s2++;}
      }
      if(s1>i1)break;
      while(a[s1]!=b[s2]&&s1<=i1)
      {
        if(a[s1]>b[s2]){sum++;s1++;s2++;}
        else{sum--;i1--;s2++;}
      }
      if(s1>i1)break;
      if(a[s1]==b[s2]&&a[i1]==b[i2])
      {
        if(a[i1]>b[s2])sum++;
        else if(a[i1]<b[s2])sum--;
        i1--;
        s2++;
      }
      if(s1>i1)break;
    }
    printf("%d\n",sum*200);
    scanf("%d",&n);
 }
 return 0;
}
long sum[1001][1001],s[1001],s1[1001];

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



void pai(int i,int j)
{
	long i1=i,j1=j,tmp=s[i];
	while(i<j)
	{
		while(i<j && s[j]<tmp)	j--;
		if(i<j)	s[i++]=s[j];
		while(i<j && s[i]>tmp)	i++;
		if(i<j)	s[j--]=s[i];
	}
	s[i]=tmp;
	if(i1<i-1)	pai(i1,i-1);
	if(j+1<j1)	pai(j+1,j1);
}

void pai1(int i,int j)
{
	long i1=i,j1=j,tmp=s1[i];
	while(i<j)
	{
		while(i<j && s1[j]<tmp)	j--;
		if(i<j)	s1[i++]=s1[j];
		while(i<j && s1[i]>tmp)	i++;
		if(i<j)	s1[j--]=s1[i];
	}
	s1[i]=tmp;
	if(i1<i-1)	pai1(i1,i-1);
	if(j+1<j1)	pai1(j+1,j1);
}





void main()
{
  long zong,i=0,j,n,temp,temp1,temp2;
  scanf("%ld",&n);
  while (n!=0)
  {
     for (i=0;i<n;i++)
		 scanf("%ld",&s[i]);
	 for (i=0;i<n;i++)
		 scanf("%ld",&s1[i]);

	 pai(0,n-1);
	 pai1(0,n-1);
	 j=0;

	 if (s[0]>s1[0]) sum[1][n]=1; else if (s[0]==s1[0]) sum[1][n]=0; else sum[1][n]=-1;
	 if (s[n-1]>s1[0]) sum[0][n-1]=1; else if (s[n-1]==s1[0]) sum[0][n-1]=0; else sum[0][n-1]=-1;
	 for (i=1;i<n;i++)
	 {
        for (j=0;j<=i;j++)
		{
          
			if (s[n+j-i-1]>s1[i]) temp=sum[j][n+j-i]+1;
				 else if (s[n+j-i-1]==s1[i]) temp=sum[j][n+j-i];
				  else  temp=sum[j][n+j-i]-1;

	        if (j>0) sum[j][n+j-i-1]=max(temp,sum[j][n+j-i-1]);
			 else sum[j][n+j-i-1]=temp;

			if (s[j]>s1[i]) sum[j+1][n+j-i]=sum[j][n+j-i]+1;
			     else if (s[j]==s1[i]) sum[j+1][n+j-i]=sum[j][n+j-i];
				  else {sum[j+1][n+j-i]=sum[j][n+j-i]-1;}	
		}
	 }
	 zong=sum[1][1];
	 for (i=1;i<=n;i++)
		 if (sum[i][i]>zong) zong=sum[i][i];
	 printf("%ld\n",zong*200);
	 scanf("%ld",&n);
  }
}
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 data[2][1000];
int cmp(const void * e1,const void * e2)
{
	int * p1 = (int *)e1;
	int * p2 = (int *)e2;
	return *p2 - *p1;
}
int main()
{
	int n;int ans;
	while(cin >> n && n != 0)
	{
		ans = 0;
		for(int i = 0;i < n;i ++)
			cin >> data[0][i];
		for(int i = 0;i < n;i ++)
			cin >> data[1][i];
		qsort(data[0],n,sizeof(int),cmp);
		qsort(data[1],n,sizeof(int),cmp);
		int b[2],e[2];
		b[0] = b[1] = 0;e[0] = e[1] = n-1;
		while(b[0]<=e[0])
		{
			if(data[0][b[0]] > data[1][b[1]])
			{
				b[0]++;b[1]++;
				ans += 200;
			}
			else
			{
				for(;data[0][e[0]] > data[1][e[1]];e[0]--,e[1]--,ans += 200);
				if(data[0][e[0]] < data[1][b[1]])	ans -= 200;
				b[1]++;e[0]--;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
int T[1000],Q[1000],n;
int search()
{
    int i,j,temp;
    int Inco[1000][1000]={0};
                          
    for(i=0;i<=n-2;i++) 
        for(j=i+1;j<=n-1;j++)
        {
            if(T[i]<T[j])
            {    temp=T[i];    T[i]=T[j];    T[j]=temp;    }
            if(Q[i]<Q[j])
            {    temp=Q[i];    Q[i]=Q[j];    Q[j]=temp;  }
        }
    
    for(i=0;i<n;i++)
    {    if(Q[i]<T[0])    Inco[i][0]=1;
        else if(Q[i]==T[0])    Inco[i][0]=0;
        else    Inco[i][0]=-1;
    }
    for(i=n-2;i>=0;i--)
    {
        for(j=1;i+j<n;j++)
        {
            if(Q[i+j]<T[0+j])
                Inco[i][j]=Inco[i][j-1]+1;
            else if(Q[i+j]>T[0+j])
                Inco[i][j]=Inco[i+1][j-1]-1;
            else 
            {    if(Inco[i+1][j-1]-1>Inco[i][j-1]+0)
                   Inco[i][j]=Inco[i+1][j-1]-1;    
                else                       
                    Inco[i][j]=Inco[i][j-1]+0;
            }
        }
    }
    return Inco[0][n-1];
}
    
int main()
{
    int i;
    scanf("%d",&n);
    while(n!=0)
    {
        for(i=0;i<n;i++)
            scanf("%d",&T[i]);
        for(i=0;i<n;i++)
            scanf("%d",&Q[i]);
        printf("%d\n",search()*200);  
        scanf("%d",&n);
    }
    return 0;
}
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 ans, n, a[1000], b[1000];
int cmp(int x, int y){
	return (x > y);
}
int main(){
	int i, j, an, bn;
	while(cin >> n && n){
		ans = 0;
		an = n;
		bn = n;
		for(i = 0; i < n; i++)
			cin >> a[i];
		for(i = 0; i < n; i++)
			cin >> b[i];
		sort(a,a+n,cmp);
		sort(b,b+n,cmp);
		for(i = 0, j = 0; i < an && j < bn;){
			if(a[i] > b[j]){
				ans++;
				i++;
				j++;
			}
			else if(a[i] < b[j]){
				if(a[an-1] < b[j]){
					ans--;
					an--;
					j++;
				}
			}
			else{
				if(a[an-1] > b[bn-1]){
					ans++;
					an--;
					bn--;
				}
				else{
					if(a[an-1] < b[j]){
						ans--;
						an--;
						j++;
					}
					else if(a[an-1] == b[j]){
						an--;
						j++;
					}
				}
			}
		}
		cout << ans*200 << endl;
	}
	return 0;
}
int tianji[1010];
int qiwang[1010];

void Input( int n )
{
	int i;
	for( i = 0 ; i < n ; i ++ )
	{
		scanf("%d",&tianji[i]);
	}
	for( i = 0 ; i < n ; i ++ )
	{
		scanf("%d",&qiwang[i]);
	}
}
int comp( const void *a , const void * b )
{
	return *(int *)a - *(int *)b;
}


int calc( int n )
{
	int t1,t2,q1,q2;
	t1 = 0;
	t2 = n-1;
	q1 = 0;
	q2 = n-1;

	int win, lose;
	win = 0;
	lose = 0;
	while( t1 <= t2 )
	{
		if( tianji[t2] > qiwang[q2] ) //??????????????
		{
			win++;
			t2--;
			q2--;
		}
		else
		{
			if( tianji[t2] < qiwang[q2] )//??????????????????????
			{
				lose++;
				t1++;
				q2--;
			}
			else//?????????????
			{
				if( tianji[t1] > qiwang[q1] )//??????????????
				{
					win++;
					t1++;
					q1++;
				}
				else//???????????????
				{
					if( tianji[t1] < qiwang[q2] )//??????????
					{
						lose++;
						t1++;
						q2--;
					}
					else//???
					{
						t1++;
						q2--;
					}
				}
			}
		}
	}
	return (win - lose) * 200;
}
main()
{
	int n;
	while( scanf("%d",&n) && n )
	{
		Input(n);
		qsort(tianji,n,sizeof(tianji[0]),comp);
		qsort(qiwang,n,sizeof(qiwang[0]),comp);
		printf("%d\n",calc(n));
	}
	return 0;
}
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;
	}
}