semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
main()
{int i;
for(i=0;i<1000;i++)
{int n,j,k,p;
scanf("%d",&n);
if(0==n)
break;
else
{int a[n],b[n];
 for(j=0;j<n;j++)
 scanf("%d",&a[j]);
 for(j=0;j<n;j++)
 scanf("%d",&b[j]); 
 for(j=0;j<(n-1);j++)
 {for(k=0;k<(n-1-j);k++)
 {if(a[k]<a[k+1])
 {p=a[k];a[k]=a[k+1];a[k+1]=p;}
  if(b[k]<b[k+1])
 {p=b[k];b[k]=b[k+1];b[k+1]=p;}
 }
 } //???????????????????? 
//for(j=0;j<n;j++)
//printf("%d %d\n",a[j],b[j]);
int a1=0,a2=n-1,b1=0,b2=n-1,q,r,s,t;//???? 
r=0;s=0;                                                                                                                                                                
for(q=0;q<n;q++)         
{if(a[a1]==b[b1])    //????????????? 
{if(a[a2]>b[b2]){r++;a2--;b2--;}
 else if(a[a2]<b[b2]){r--;a2--;b1++;}
 else if(a[a2]==b[b2])
{if(a[a2]<b[b1]){r--;a2--;b1++;}
 else if(a[a2]==b[b1]){break;}
}
}
else if(a[a1]>b[b1])     //?????????? 
{r++;a1++;b1++;}
else    {r--;a2--;b1++;} //????????? 
}
   s=r*200;
   printf("%d\n",s);
   r=0;s=0;
}}
} //?????C++???????????????????????????C??????
void sort(int a[1005],int n)
{
   int i,j,k,temp;
   for(i=0;i<n-1;i++)
   {
     k=i;
	 for(j=i+1;j<n;j++)
		 if(a[j]>a[k])k=j;
		 if(k!=i)
		 {
		 temp=a[i];a[i]=a[k];a[k]=temp;
		 }
   
   }

}

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

            if(head>tailt) break;
        }

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


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

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

int main()
{
	int i,j;
	int end1,end2;
	int sum=0;
	scanf("%d",&n);
	while(n!=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);
	  
	   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])//?????????????????????
            {
             sum++;end1++;end2++; j++; 
            }
           else if(a[end1]<b[end2]) //?????????????????????
           {
             sum--;end1++;
           }
           else
           {
             if(a[end1]==b[j])
                {
                  end1++;
                }
             else
                {
                  sum--;end1++;
                }
           }
      } 
   }
   printf("%d\n",200*sum);
   sum=0;
   scanf("%d",&n);
	}
   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);

        for(i=0;i<100;i++)
        {  T[i]=0;  Q[i]=0;     }
        scanf("%d",&n);
    }
    return 0;
}
int c[1010][1010];

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

int cmp(const void * x, const void * y)
{
	int * a = (int *)x;
	int * b = (int *)y;
	if (*a > *b)
		return 1;
	else return -1;
}

int main()
{
	int n;
	int a[1010];
	int b[1010];
	int i, j, k;
	int max;
	int val;

	for (i = 0; i < 1010; i++)
		for (j = 0; j < 1010; j++)
			c[i][j] = -100000;
	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]);
		qsort(a, n, sizeof(int), cmp);
		qsort(b, n, sizeof(int), cmp);
		j = 0;
		for (i = 0; i < n; i++)
			for (j = 0; j <= i; j++)
			{
				c[i][j] = -10000;
				if (j == 0)
				{
					if (a[i] > b[j])
						c[i][j] = 1;
					else if (a[i] == b[j])
						c[i][j] = 0;
				}
				else {
					if (a[i] < b[j])
						c[i][j] = c[i-1][j];
					if (a[i] == b[j])
						c[i][j] = maximum(c[i-1][j-1], c[i-1][j]);
					if (a[i] > b[j])
						c[i][j] = c[i-1][j-1] + 1;
				}
			}
		max = -100000;
		for (i = 0; i< n; i++)
			for (j = 0; j < n; j++)
				if (max < c[i][j] - (n - j - 1))
					max = c[i][j] - (n - j - 1);
		if (max <= -5000)
			max = -n;
		printf("%d\n", max * 200);
	}
}
int T[1001],K[1001];   
  
int cmp(const void* a,const void *b)   
{   
    return *(int *)b-*(int *)a;   
}   
  
  
int main()   
{   
    int n,i,sum;   
    int flag;   
    int t_tail,t_head,k_tail,k_head;   
    while (scanf("%d",&n)!=EOF && n)   
    {   
        for(i=0;i<n;i++)   
            scanf("%d",&T[i]);   
        for(i=0;i<n;i++)   
            scanf("%d",&K[i]);   
           
        qsort(T,n,sizeof(T[0]),cmp);   
        qsort(K,n,sizeof(K[0]),cmp);   
        sum=0;   
        flag=1;   
        k_head=t_head=0;   
        k_tail=t_tail=n-1;   
           
        while(t_head<=t_tail && k_head<=k_tail)   
        {   
            if(T[t_head]>K[k_head])   
            {      
                sum+=200;   
                t_head++;   
                k_head++;   
            }   
//?????else?   
            else if(T[t_head]<K[k_head])   
            {   
                sum-=200;   
                t_tail--;   
                k_head++;   
            }   
            else    
            {   
                while(t_head<=t_tail && k_head<=k_tail)   
                {      
                    if(T[t_tail]>K[k_tail])   
                    {   
                        sum+=200;   
                        t_tail--;   
                        k_tail--;   
                    }   
                    else  
                    {   
                        if(T[t_tail] <K[k_head])   
                            sum-=200;   
                        t_tail--;   
                        k_head++;   
                        break;   
                    }   
                }   
            }   
            if(T[t_tail]>K[k_head])   
            {   
                flag=1;   
                break;   
            }              
        }   
        if(flag==1)   
            sum+=(t_tail-t_head+1)*200;   
        printf("%d\n",sum);   
    }   
    return 0;   
}
// ???????
int n;
int self[1000], enemy[1000];

// ??
int result;

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

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

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

int main(void)
{
	int i;
	while (scanf("%d", &n) != -1 && n != 0)
	{
		for (i = 0; i < n; i++)
			scanf("%d", &self[i]);
		qsort(self, n, sizeof(int), compare);
		for (i = 0; i < n; i++)
			scanf("%d", &enemy[i]);
		qsort(enemy, n, sizeof(int), compare);
		printf("%d\n", calcMax());
	}
	return 0;
}
const int maxn=1010,minl=-999999999;
inline int Max(int a,int b){return a>b?a:b;}
int f[maxn][maxn];
int a[maxn],b[maxn];
int n;
int cmp(const void *a,const void *b)
{
	return *((int*)b)-*((int*)a);
}
void dp()
{
	int i,j,k;
	for (i=0;i<=n;i++) for (j=0;j<=n;j++) f[i][j]=minl;
	f[0][0]=0;
	for (i=0;i<n;i++)
		for (j=0;j<=i;j++) if (f[i][j]>=-n)
		{
			if (b[i+1]<a[j+1]) f[i+1][j+1]=Max(f[i+1][j+1],f[i][j]+1);
			if (b[i+1]>a[j+1]) f[i+1][j]=Max(f[i+1][j],f[i][j]-1);
			if (b[i+1]==a[j+1])
			{
				f[i+1][j+1]=Max(f[i+1][j+1],f[i][j]);
				if (b[i+1]>a[n-(i-j)]) f[i+1][j]=Max(f[i+1][j],f[i][j]-1);
				else if (b[i+1]==a[n-(i-j)]) f[i+1][j]=Max(f[i+1][j],f[i][j]);
			}
		}
	k=-n;
	for (i=0;i<=n;i++) k=Max(k,f[n][i]);
	printf("%d\n",k*200);
}
int main()
{
	//freopen("in.in","r",stdin);
	while (scanf("%d",&n),n)
	{
		int i;
		for (i=1;i<=n;i++) scanf("%d",a+i);
		for (i=1;i<=n;i++) scanf("%d",b+i);
		qsort(a+1,n,sizeof(int),cmp);
		qsort(b+1,n,sizeof(int),cmp);
		dp();
	}
	return 0;
}
int money(int n){
	int i,j,m,ans=0,mid,head=0,tailt=n-1,tailk=n-1;
	int *k=(int*)malloc(sizeof(int)*n);
	int *t=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
		scanf("%d",&t[i]);
	for(i=0;i<n;i++)
		scanf("%d",&k[i]);
	for(i=0;i<n;i++)
		for(j=0;j<n-1;j++)
			if(k[j]<k[j+1]){
				mid=k[j];
				k[j]=k[j+1];
				k[j+1]=mid;
			}
	for(i=0;i<n;i++)
		for(j=0;j<n-1;j++)
			if(t[j]<t[j+1]){
				mid=t[j];
				t[j]=t[j+1];
				t[j+1]=mid;
			}
    for(i=0;i<n;i++)
        {
            if(t[head]>k[i])
            {
                head++;
                ans+=200;
            }
            else if(t[head]<k[i])
            {
                tailt--;
                ans-=200;
            }
            else if(t[head]==k[i])
            {
                for(j=tailt,m=tailk;j>=head;j--,m--)
                {
                    if(t[j]>k[m])
                    {
                        ans+=200;
                        tailt--;
                        tailk--;
                    }
                    else
                     {
                        if(t[j]<k[i]) ans-=200;
                        tailt=--j;
                        tailk=m;
                        break;               
                     }
                }
            }

            if(head>tailt) break;
        }
	free(k);
	free(t);
	return ans;
}
void main(){
	int n;
	while(scanf("%d",&n)==1&&n!=0)
		printf("%d\n",money(n));
}
int n;
int a[1001], b[1001];	//a,b??????????????
int win, lose;		//?????????

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

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

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

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

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

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

	int i,j;

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


int main()
{
	while(true){
		cin>>n;
		if (n==0)
			break;
		for (int i=1; i<=n; i++)
			cin>>a[i];
		for (int i=1; i<=n; i++)
			cin>>b[i];
		a[0] = b[0] = 0;
		qsort(a, n+1, sizeof(int), cmp);
		qsort(b, n+1, sizeof(int), cmp);
		win=0;
		lose=0;
		cal(n);
		cout<<200*(win-lose)<<endl;
	}
	return 0;
}
int cmp(const void*e1,const void *e2)
{
	return *((int*)e2)-*((int*)e1);
}
int main()
{
	int n,a[1000],b[1000],i,j,k,s,t,result;
	while(scanf("%d",&n) && n )
	{
		for(i=0;i<n;++i)
			scanf("%d",&b[i]);
		qsort(b,n,sizeof(int),cmp);
		for(i=0;i<n;++i)
			scanf("%d",&a[i]);
		qsort(a,n,sizeof(int),cmp);
		i=k=0;
		j=s=n-1;
		result=0;
		for(t=0;t<n;++t)
		{
			if(b[i]>a[k]) 
			{
				result+=200;
				++i;
				++k;
			}
			else if(b[j]>a[s])
			{
				result+=200;
				--j;
				--s;
			}
			else 
			{
				if(b[j]>a[k])
					result+=200;
				else if(b[j]<a[k])
					result-=200;
				--j;
				++k;
			}
		}
		printf("%d\n",result);
	}
	return 0;
}
int num1[1001];
int num2[1001];
int num;
int compare(const void * p1,const void * p2)
{
	int * q1,* q2;
	q1=(int *) p1;
	q2=(int *) p2;
	return *q1-*q2;
}
int main()
{
	while(true)
	{
		
		cin>>num;
		if(num==0)
			break;
		for(int i=1;i<=num;i++)
		{
			cin>>num1[i];
		}
		for(int i=1;i<=num;i++)
		{
			cin>>num2[i];
		}
		qsort(&(num1[1]),num,sizeof(int),compare);
		qsort(&(num2[1]),num,sizeof(int),compare);
		int p1,p2,p3,p4;
		p1=1;
		p2=num;
		p3=1;
		p4=num;
		int money=0;
		while(true)
		{
			if(p1==p2)
			{
				if(num1[p1]>num2[p3])
					money++;
				if(num1[p1]<num2[p3])
					money--;
				break;
			}
			else
			{
				if(num1[p1]>num2[p3])
				{
					money++;
					p1++;
					p3++;
					continue;
				}
				if(num1[p2]>num2[p4])
				{
					money++;
					p2--;
					p4--;
					continue;
				}
				if(num1[p1]<num2[p4])
					money--;
				if(num1[p1]>num2[p4])
					money++;
				p1++;
				p4--;
			}
		}
		cout<<money*200<<endl;
	}
	return 0;
}
int bonus[1002],index=0;
int main()
{
	void f(int x[2][1002],int y);
	int n,flag=1,a[2][1002];
	while(flag==1)
	{
		scanf("%d",&n);
		if(n!=0) { f(a,n);index++;}//?????????????
		else flag=0;
	}
	for(int i=0;i<index;i++)
		printf("%d\n",bonus[i]);
}
void f(int x[2][1002],int y)
{
	int i,j,k,win,draw,flag,b[1002]={0},max,num=0;
	for(i=0;i<2;i++)
		for(j=0;j<y;j++)
			scanf("%d",&x[i][j]);
	for(i=0;i<y-1;i++)//?????????????
		for(j=1;i+j<y;j++)
		if(x[0][i]<x[0][i+j])       
			{k=x[0][i];
	         x[0][i]=x[0][i+j];
			 x[0][i+j]=k;}
	for(i=0;i<y-1;i++)//??????
		for(j=1;i+j<y;j++)
		if(x[1][i]<x[1][i+j])       
			{k=x[1][i];
	         x[1][i]=x[1][i+j];
			 x[1][i+j]=k;}
	flag=1;
	for(i=0;i<y&&flag==1;i++)  //????????????????????????????????????
	{if(x[0][0]>x[1][i]||x[0][0]==x[1][i]) {k=i;flag=0;}}
	if(flag==1) max=y*(-200);
	else 
	{
		while (k<=y-1)
		{
				win=0;
				draw=0;
				for(i=0,j=k;i<y&&j<y;i++,j++)
				{	
					if(x[0][i]>x[1][j]) win++;
					else if (x[0][i]==x[1][j]) draw++;
				}
				b[num++]=win*200-(y-draw-win)*200;//??????????????
				k++;
		}
	max=b[0];
	for(i=0;i<num;i++)
	if(max<b[i]) max=b[i];
	}
     bonus[index]=max;//??????????????????????????
}
int cmp(const void *e1,const void *e2)
{
	return *(int *)e2-*(int *)e1;
}

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

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

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

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

void sort(int a[], int n)
{
    int k,i,b,e;
    if (n <= 1)
	return;
    k = n/2;
    sort(a, k);
    sort(a+k, n-k);
    for (i=0; i<k; i++)
	tmp[i] = a[i];
    for (i=k; i<n; i++)
	tmp[i] = a[n+k-i-1];
    b=0, e=n-1;
    for (i=0; i<n; i++) {
	if (tmp[b] <= tmp[e])
	    a[i] = tmp[b++];
	else a[i] = tmp[e--];
    }
}

int main()
{
    int n, i, res;
    int b1,e1, b2,e2;
    while (scanf("%d", &n)!=EOF && n!=0) {
	for (i=0; i<n; i++)
	    scanf("%d", &tj[i]);
	for (i=0; i<n; i++)
	    scanf("%d", &qw[i]);
	res = 0;
	sort(tj, n);
	sort(qw, n);
	b1=b2=0, e1=e2=n-1;
	while (b1 <= e1) {
	    if (qw[b1] < tj[b2]) {
		b1++, b2++, res++;
	    }
	    else if (qw[b1] > tj[b2]) {
		e1--, b2++, res--;
	    }
	    else {
		if (qw[e1] < tj[e2]) {
		    e1--, e2--, res++;
		}
		else if (qw[e1] > tj[e2]) {
		    e1--, b2++, res--;
		}
		else {
		    if (qw[e1] > tj[b2])
			res--;
		    else if (qw[e1] < tj[b2])
			res++;
		    e1--, b2++;
		}
	    }
	}
	printf("%d\n", res*200);
    }
    return 0;
}
int wis[MAX];
int king[MAX];

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


int main()
{
	int n, count;
	int i, imax, imin, jmax, jmin;
	
	while (1)
	{
		scanf("%d", &n);
		if (n == 0)
			break;
		
		for (i=0 ; i<n ; i++)
			scanf("%d", wis+i);
		for (i=0 ; i<n ; i++)
			scanf("%d", king+i);
		
		qsort(wis, n, sizeof(int), comp);
		qsort(king, n, sizeof(int), comp);
		
		imin = 0;
		imax = n-1;
		jmin = 0;
		jmax = n-1;
		count = 0;
		while (jmin < jmax)
		{
			if (wis[imin] > king[jmin])
			{
				count++;
				imin++;
				jmin++;
			}
			else if (wis[imin] < king[jmin])
			{
				count--;
				imin++;
				jmax--;
			}
			else	//wis[imin] == king[jmin]
			{
				while (jmin < jmax)
				{
					if (wis[imax] > king[jmax])
					{
						count++;
						imax--;
						jmax--;
					}
					else if (wis[imax] < king[jmax])
					{
						count--;
						imin++;
						jmax--;
					}
					else	//wis[imax] == king[jmax]
					{
						if (wis[imin] < king[jmax])
							count--;
						imin++;
						jmax--;
						break;
					}
				}
			}
		}
		if (wis[imax] > king[jmax])
			count++;
		else if (wis[imax] < king[jmax])
			count--;
		count *= 200;
		
		printf("%d\n", count);
	}
	
	return 0;
}
void _qsort ( int a[] , int start , int end )
{
   int i , j , temp;
   i = start , j = end;
   temp = a[i];
   while ( i < j )
    {
     for ( ; temp >= a[j] && i < j ; j -- );
     i < j ? a[i++] = a[j] : 0;
     for ( ; a[i] >= temp && i < j ; i ++ );
     i < j ? a[j--] = a[i] : 0;
    }
   a[i] = temp;
   if ( start < i-1 ) _qsort ( a , start , i-1 );
   if ( j + 1 < end ) _qsort ( a , j + 1 , end );
}

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