semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int a[1001];
int b[1001];
int f[1001][1001];

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

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

	while(scanf("%d",&n) && n){

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

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

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

		printf("%d\n",f[0][n-1]);
	}
	return 0;
}
int paixu(int s[],int n)
{
    int i,j,t;
    for (i=0;i<n-1;i++)
    {
        for (j=0;j<n-i-1;j++)
        {
            if (s[j]>s[j+1])
            {
                t=s[j];s[j]=s[j+1];s[j+1]=t;
            }
        }
    }
    return 0;
}
int main ()
{
    while (1)
    {
    int a=0,b=0,m,n=0,i,j,k,s[1001],t[1001],x;
    scanf("%d",&n);
    if (n==0) break;
    for (i=0;i<n;i++)
    scanf("%d",&s[i]);
    for (i=0;i<n;i++)
    scanf("%d",&t[i]);
    paixu(s,n);
    paixu(t,n);
    for (i=0,j=0;i<n;i++)
    {
        if (s[i]>t[j])
        {
            j++;a++;
        }
        else if (s[i]==t[j])
        {
            for (k=i+1,x=0;k<n;k++)
            {
                if (s[k]<=t[k-i+j]&&s[k]>s[i])
                {x=1;break;}
            }
            if (x==0)
            {
                j++;b++;
            }
            else
            {
                j++;a++;
                s[k]=0;
            }
        }
    }
    m=200*(a-(n-a-b));
    printf("%d\n",m);
    }
    getchar();getchar();getchar();getchar();
}
int sort(int x[], int m){
  int i, j, k;
  for (i=0;i<m;i++)
        for (j=i+1;j<m;j++)
            if (x[i]<x[j])
            {
               k = x[i];
               x[i] = x[j];
               x[j] = k;
                          }
}

int main(){
    while (1)
    {
          
    int num;
    int a[1000];
    int b[1000];
    int i,j,shadow,k;
    int temp_gain=0, temp_tie=0, temp_lose=0;
    int gain=0, lose=0, tie=0;
    int total_gain=0;
    scanf("%d",&num);
    
    if (num==0)
       break;
       
    for (i=0;i<num;i++)
        scanf("%d",&a[i]);
    for (i=0;i<num;i++)
        scanf("%d",&b[i]);
    sort(a,num);
    sort(b,num);
    
    for (i=0;i<num;i++)
    {
        shadow = i;
        i=0;
        for (j=shadow;j<num;j++,i++)
        {
            if (a[i]>b[j])
               temp_gain++;
            else if (a[i]<b[j])
               temp_lose++;
            else
               temp_tie++;
            }
        temp_lose += shadow;
        if ((temp_gain - temp_lose)>(gain - lose) || shadow==0)
           {
                       gain = temp_gain;
                       lose = temp_lose;
                       tie = temp_tie;
                       }
        i = shadow;
        temp_gain = 0;
        temp_lose = 0;
        temp_tie = 0;
        }

    total_gain = (gain-lose)*200;
    printf("%d\n",total_gain);    
}
getchar();
getchar();
    }
int thorse[1002];
int qhorse[1002];
int match[1002];
int compare(const void *p1,const void *p2)
{
	int *p=(int *) p1;
	int *q = (int *)p2;
	return (*q)-(*p);
}
int main()
{
	int n;
	while(cin>>n)
	{
		if(n==0){break;}
		memset(thorse,0,sizeof(thorse));
		memset(qhorse,0,sizeof(qhorse));
		memset(match,0,sizeof(match));
		for(int i=0;i<n;i++)
		{
			cin>>thorse[i];
		}
		for(int i=0;i<n;i++)
		{
			cin>>qhorse[i];
		}
		qsort(thorse,n,sizeof(int),compare);
		qsort(qhorse,n,sizeof(int),compare);
		int fast=0, slow=n-1, head=0, tail=n-1;
		int win=0, lose=0;
		while(fast<=slow)
		{
			if(thorse[tail]>qhorse[slow])
			{
				match[slow]=tail;
				slow--;tail--;
			}
			else if(thorse[tail]<qhorse[slow])
			{
				match[fast]=tail;
				fast++;tail--;
			}
			else 
			{
				if(thorse[head]>qhorse[fast])
				{
					match[fast]=head;
					fast++;head++;
				}
				else
				{
					match[fast]=tail;
					tail--;fast++;
				}
			}
		}
		for(int i=0;i<n;i++)
		{
			if(qhorse[i]>thorse[match[i]]){lose++;}
			else if(qhorse[i]<thorse[match[i]]){win++;}
		}
		int money=win*200-200*lose;
		cout<<money<<endl;
	}
	return 0;
}
int count1;
int a[1010] ;
int b[1010];
int n;
int cmp(const void *a,const void *b)
{
    return *(int *)b - *(int *)a;
}
int dfs(int *a,int *b)
{
    int x,y,i,j;
    x=y=0;
    i=j=n-1;
    while(true)
    {
    if(x>i)
    break;
    if(a[x]>b[y])
    {
    count1+=1;
    x++;
    y++;
    }
    else
    if(a[i]>b[j])
    {
    count1+=1;
    i--;
    j--;
    }
    else
    {
    if(a[i]<b[y])
    count1-=1;
    i--;
    y++;
    }
    }
}
int main()
{
    while(true)
    {
    cin>>n;
    if(n==0)
    break;
    for(int i=0;i<n;i++)
    cin>>a[i];
    qsort(a,n,sizeof(int),cmp);
  //  for(int i=0;i<n;i++)
  //  cout<<a[i]<<' ';
  //  cout<<endl;
    for(int i=0;i<n;i++)
    cin>>b[i];
    qsort(b,n,sizeof(int),cmp);
    count1=0;
  //  i_count=0;
    dfs(a,b);
    cout<<200*(count1)<<endl;
    }
    return 0;
}
//???? 
int main()
{
    int n=1,i,j,k,r;
    int t[1000],q[1000];
    while(n!=0)
    {
        scanf("%d",&n);
        if(n==0)
           break;
        for(i=0;i<n;i++)
           scanf("%d",&t[i]);//???? 
        for(i=0;i<n;i++)
        { 
           for(j=n-1;j>i;j--)
           {
              if(t[j]>=t[j-1])//?? 
              {
                 k=t[j-1];
                 t[j-1]=t[j];
                 t[j]=k;
              }
           }
        }
        for(i=0;i<n;i++)
           scanf("%d",&q[i]);//???? 
        for(i=0;i<n;i++)
        { 
           for(j=n-1;j>i;j--)
           {
              if(q[j]>=q[j-1])//?? 
              {
                 k=q[j-1];
                 q[j-1]=q[j];
                 q[j]=k;
              }
           }
        }
        int sum=0,fail=0,qfail=0; //fail???????????qfail????
        for(j=0;j<n;j++)
        {
           i=j-fail;
           k=j-qfail;
           if(t[i]>q[k])//??? 
              sum++;
           else if(t[i]<q[k])//??? 
           {
              sum--;
              fail++;
           }
           else if(t[i]==q[k])//???????? 
           {
              if(t[n-fail-1]>q[n-qfail-1])
              {
                 sum++;
                 fail++;
                 qfail++;
              }
              else if(t[n-fail-1]<q[n-qfail-1])
              {
                 sum--;
                 fail++;
              }
              else if(t[n-fail-1]==q[n-qfail-1]&&t[n-fail-1]<q[k])
              {
                 sum--;
                 fail++;
              }
           }
        }
        r=200*sum;
        printf("%d\n",r);
    }
}
void main()
{
  int n,a[1000],b[1000],m[1000],c=0,i,j,t,x,y;
  for(;;)
  {scanf("%d",&n);
  if(n==0)
  break;
  x=0;
  y=0;
  m[c]=-n;
  for(i=0;i<=n-1;i++)
  scanf("%d",&a[i]);
  for(i=0;i<=n-1;i++)
  scanf("%d",&b[i]);
  for(j=0;j<n-1;j++)
  for(i=0;i<n-j-1;i++)
 {	 if(a[i]<a[i+1])
 {  t=a[i];
    a[i]=a[i+1];
	a[i+1]=t;
 }
     if(b[i]<b[i+1])
	 { t=b[i];
	   b[i]=b[i+1];
	   b[i+1]=t;
      }
}
for(j=0;j<=n-1;j++)
{ for(i=0;i<=n-1;i++)
  {  if(i+j<=n-1)
  {if(a[i]>b[i+j])
		 x++;
   if(a[i]<b[i+j])
	     y++;
  }
     if(i+j>=n)
	 { if(a[i]>b[i+j-n])
	     x++;
	   if(a[i]<b[i+j-n])
		 y++;
	 }
  }	 
   if(x-y>m[c])
	m[c]=x-y;
     x=0;
	 y=0;
   }
  c++;
  }
   for(i=0;i<=c-1;i++)
   printf("%d\n",200*m[i]);
}
const int maxn = 1200;

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

int
main(void)	{
	int n;
	int a[maxn], b[maxn];
	
	while (cin >> n)	{
		if (n == 0)	break;

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

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

		int la, lb, ra, rb;

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

		int ans = 0;

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

		cout << ans * 200 << endl;

	}

	return 0;
}
main()
{
    int n,h,i=0,j=0,temp,re,iLAST,jLAST;
    int t[1000],q[1000];
    for (h=1;;h++)
    {
        scanf("%d",&n);
        if (n==0)
        break;
        else
        {
            for (i=0;i<n;i++)
            {
                scanf("%d",t+i);
            }
            for (j=0;j<n;j++)
            {
                scanf("%d",q+j);
            }
            for (i=0;i<n;i++)//&#197;&#197;Dòì&#239;&#188;é
            {
                for (j=i;j<n;j++)
                {
                    if (t[j]<t[i])
                    {
                        temp=t[j];
                        t[j]=t[i];
                        t[i]=temp;
                    }
                }
            }
            for (i=0;i<n;i++)//&#197;&#197;Dò&#198;&#235;í&#245;
            {
                for (j=i;j<n;j++)
                {
                    if (q[j]<q[i])
                    {
                        temp=q[j];
                        q[j]=q[i];
                        q[i]=temp;
                    }
                }
            }

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

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

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

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

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

		cout << sum << endl;
	}	

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

  int tian_fast = n-1, king_fast = n-1, result = 0;
  int tian_slow = 0, king_slow = 0;
  while(tian_slow <= tian_fast && king_slow <= king_fast)
  {
   if(tian[tian_slow] < king[king_slow])
   {
    king_fast--;
    tian_slow++;
    result--;
   }
   else if(tian[tian_slow] > king[king_slow])
   {
    tian_slow++;
    king_slow++;
    result++;
   }
   else
   {
    if(tian[tian_fast] > king[king_fast])
    {
     result++;
     tian_fast--; king_fast--;
    }
    else if(tian[tian_fast] < king[king_fast])
    {
     result--;
     tian_slow++;
     king_fast--;
    }
    else
    {
     if(tian[tian_slow] < king[king_fast])
     {
      result--;
      tian_slow++;
      king_fast--;
     }
     else
     {
      break;//??????
     }
    }
   }
  }
  printf("%d\n", result*200);
 }
 return 0;
}
void main()
{
	while(1)
	{
		int n,i,j,k,p,temp,win,tie,money;
		int tj[2000],qw[2000];
		scanf("%d",&n);
		if(n==0) break;
		else
		{
		   /*????*/
			for(i=0;i<n;i++)
				scanf("%d",&tj[i]);
			for(i=0;i<n;i++)
				scanf("%d",&qw[i]);
			for(i=0;i<n-1;i++)
				for(j=0;j<n-1-i;j++)
					if(tj[j]<tj[j+1])
					{
						temp=tj[j];
						tj[j]=tj[j+1];
						tj[j+1]=temp;
					}
			for(i=0;i<n-1;i++)
				for(j=0;j<n-1-i;j++)
					if(qw[j]<qw[j+1])
					{
						temp=qw[j];
						qw[j]=qw[j+1];
						qw[j+1]=temp;
					}
			
			/*??*/		
					
			win=tie=0;
			for(i=0,j=0,k=p=n-1;j<=k&&i<=p;)
			{
				if(tj[j]>qw[i])
				{
					win++;
					j++;
					i++;
				}
				else if(tj[k]>qw[p])
				{
					win++;
					p--;
					k--;
				}
				else
				{
					if(tj[k]==qw[i])
						tie++;
					k--;
					i++;
				}
			}
			money=200*(win-(n-win-tie));
			printf("%d\n",money);
		}
	}
}
int tian[1000],wang[1000],temp[1000];

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

int main()
{
	int n;
	while(1)
	{
		int i,num = 0,t_first,q_first,t_last,q_last;
		scanf("%d",&n);
		if( n == 0 )
			break;

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

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

		t_first = q_first = 0;
		t_last = q_last = n-1;
		while( t_last >= t_first )
		{
			if( tian[t_first] > wang[q_first] )
			{
				num++;
				t_first++;
				q_first++;
			}
			else if( tian[t_first] < wang[q_first] )
			{
				num--;
				t_first++;
				q_last--;
			}
			else
			{
				if( tian[t_last] > wang[q_last] )
				{
					num++;
					t_last--;
					q_last--;
				}
				else if( tian[t_last] < wang[q_last] )
				{
					num--;
					t_first++;
					q_last--;
				}
				else
				{
					if( tian[t_first] < wang[q_last] )
						num--;
					t_first++;
					q_last--;
				}
			}
		}
		
		printf("%d\n",num*200);
	}
	return 0;
}
int n;
void paixu (int* p)
{
    int k;
    for (int i=n-1;i>=0;i--)
    {
        for (int j=0;j<i;j++)
        {
            if (*(p+j)<*(p+j+1))
            {
                k=*(p+j);
                *(p+j)=*(p+j+1);
                *(p+j+1)=k;
            }
        }
    }
}
void huan(int* p)
{
    int x;
    x=*p;
    for (int i=0;i<n-1;i++) *(p+i)=*(p+i+1);
    *(p+n-1)=x;
}
int main ()
{
    int a[1000],b[1000];
    int w,m;
    for (;;)
    {
        scanf("%d",&n);
        if (n==0) break;
        for (int i=0;i<n;i++) scanf("%d",&a[i]);
        for (int i=0;i<n;i++) scanf("%d",&b[i]);
        paixu (a);
        paixu (b);
        m=-n;
        for (int i=0;i<n;i++)
        {
            w=0;
            for (int j=0;j<n;j++)
            {
                if (a[j]>b[j]) w++;
                else if (a[j]<b[j]) w--;
            }
            m=(m>w)?m:w;
            huan(a);
        }
        printf("%d\n",200*m);
    }
    return 0;
}
int main()
{

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

for(k=0;;k++){
 
   sum=0;
    
win=0;
    
draw=0;
    
scanf("%d",&n);

    if(n==0)break;

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

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

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

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

                t=a[j];

                a[j]=a[i];

                a[i]=t;
           
 }
            
if(b[i]<b[j])
            
{
               
 t=b[j];
              
  b[j]=b[i];

                b[i]=t;

           
 }
        
}
   
 }
   
 //cong da dao xiao
 
   //test sort
    //for(i=0;i<n;i++)
    //    printf("a:%d,b:%d\n",a[i],b[i]);
    //test end
    as=0;//amax
    ae=n-1;//amin
    bs=0;//bmax
    be=n-1;//bmin
    while(as<=ae)
    {
        if(a[as]>b[bs])
        {
            as++;
            bs++;
            win++;
        }
        else if(a[ae]>b[be])
        {
            ae--;
            be--;
            win++;
        }
        else
        {
            if(a[ae]==b[bs])
            {
                ae--;
                bs++;
                draw++;
            }
            else
            {
                ae--;
                bs++;
            }
        }
        
    }
    sum=win*200-(n-win-draw)*200;
    //printf("win:%d;draw:%d;\n",win,draw);
    printf("%d\n",sum);
}
return 0;
}
int main()
{
	int a[1000]={0},b[1000]={0};
	void move(int x[],int y);
	void list(int x[],int y);
	while(true)
	{
		int t,j,i,max;
		cin>>t;
		if(t!=0)
		{
			for(i=0;i<=t-1;i++)
				cin>>a[i];
			for(i=0;i<=t-1;i++)
				cin>>b[i];
			list(a,t);
			list(b,t);
			for(j=0;j<=(t-1)/2;j++)
			{
				int money=0;
				for(i=0;i<=t-1;i++)
				{
					if(a[i]<b[i])
						money--;
					if(a[i]>b[i])
						money++;
				}
				if(j==0)
					max=money;
				if(max<money)
					max=money;
				move(a,t-1);
			}
			cout<<max*200<<endl;
		}
		else
			return 0;
	}
}

void move(int x[],int y)
{
	int temp,i;
	temp=x[y];
	for(i=y-1;i>=0;i--)
		x[i+1]=x[i];
	x[0]=temp;
}
void list(int x[],int y)
{
	int i,j,temp;
	for(i=0;i<=y-1;i++)
		for(j=i;j<=y-1;j++)
		{
			if(x[i]<x[j])
			{
				temp=x[j];
				x[j]=x[i];
				x[i]=temp;
			}
		}
}
int main()
{
	int rn;
	int a[1001], b[1001],t,i,j,as,ae,bs,be,c;
	while(1){
		cin >> rn;
		if(rn == 0)
			break;
		for(i = 0;i<rn; i ++)
			cin>>a[i];
		for(i = 0;i<rn; i ++)
			cin>>b[i];
		for(i = 0; i < rn - 1; i ++)
			for(j = i + 1; j < rn; j ++)
				if(a[i]<a[j])
				{
					t=a[i];a[i]=a[j];a[j]=t;
				}
		for(i = 0; i < rn - 1; i ++)
			for(j = i + 1; j < rn; j ++)
				if(b[i]<b[j])
				{
					t=b[i];b[i]=b[j];b[j]=t;
				}
		as=0;
		ae=rn-1;
		bs=0;
		be=rn-1;
		c=0;
		while(as<=ae&&bs<=be)
		{
			if(a[ae]>b[be])
			{
				c++;
				ae--;
				be--;
				continue;
			}
			if(a[ae]<b[be])
			{
				c--;
				ae--;
				bs++;
				continue;
			}
			if(a[as]>b[bs])
			{
				c++;
				as++;
				bs++;
				continue;
			}
			if(a[as]<b[bs])
			{
				c--;
				ae--;
				bs++;
				continue;
			}
			if(a[as]==b[bs])
			{
				if(a[ae]<b[bs])
					c--;
				ae--;
				bs++;
				continue;
			}		
		}
		cout<<c*200<<endl;
	}
	return 0;
}
int n;
int fun(int a[],int b[])
{
	int min1=0;
	int min2=0;
	int max1=n-1;
	int max2=n-1;
	int count=0;
	int sum=0;
	while(count<n)
	{
		count++;
		if(a[max1]>b[max2])
		{
			max1--;
			max2--;
			sum+=200;
		}
		else if(a[max1]<b[max2])
		{
			sum-=200;
			min1++;
			max2--;
		}
		else
		{
			if(a[min1]>b[min2])
			{
				sum+=200;
				min1++;
				min2++;
			}
			else if(a[min1]<b[max2])
			{
				sum-=200;
				min1++;
				max2--;
			}
			else if(a[min1]==b[max2])
			{
				sum+=0;
				min1++;
				max2--;
			}
		}

	}
	return sum;
}

int main()
{
	int i;
	int a[1005],b[1005];
	while(scanf("%d",&n)&&n)
	{
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(i=0;i<n;i++)
			scanf("%d",&b[i]);
		sort(a,a+n);
		sort(b,b+n);
		printf("%d\n",fun(a,b));
	}
	return 0;
}
int  Greedy(int Tj[],int Kg[],int n)
{
	int count=0;//???????
	int Tj_fa=n-1, Tj_lo=0; // ??????????
	int Kg_fa=n-1, Kg_lo=0;
	while(Tj_lo<=Tj_fa)
	{
		if( Tj[Tj_fa]>Kg[Kg_fa] )         // ?????????????? 
                  {     count++;   Tj_fa--;    Kg_fa--;   }
		else if(Tj[Tj_lo]>Kg[Kg_lo])   // ??????????????
                  {      count++;   Tj_lo++;   Kg_lo++; }
		else                                      //???????????????
                  {        if(Tj[Tj_lo]<Kg[Kg_fa])  count--;
	                     Tj_lo++;
		        Kg_fa--;
		}
	}
	return count;
}
int main()
{
   int T[1002],K[1002];
   int n;
  while( cin>>n&&n)
  {
       int i;
       for (i=0;i<n;i++)
       {
           cin>>T[i];
       }
       for (i=0;i<n;i++)
       {
           cin>>K[i];
       }
       sort(T,T+n);
       sort(K,K+n);
       cout<<Greedy(T,K,n)*200<<endl;
 }
   return 0;

}
void sort(int *p,int n)
{
    int i,j,k;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(p[i]<p[j])
            {
                k=p[i];
                p[i]=p[j];
                p[j]=k;
            }
        }
    }
}
main()
{   int a[1000],b[1000];
    int n,i,j,k,s,t,sum;
    for(;;)
    {
        scanf("%d",&n);
        if(n==0) break;
        else{
        for(i=0;i<n;i++)
        {scanf("%d",&a[i]);}
        for(i=0;i<n;i++)
        {scanf("%d",&b[i]);}
        s=n-1;
        t=n-1;
        sum=0;
        sort(a,n);
        sort(b,n);
        for(i=0,j=0,k=0;k<n;k++)
        {
            if(a[i]>b[j])
            {
                sum=sum+200;
                i++;
                j++;
            }
            else
            {
                if(a[s]>b[t])
                {
                    sum=sum+200;
                    s--;
                    t--;
                }
                else
                {
                    if(a[s]!=b[j])
                    {
                        sum=sum-200;
                        j++;
                        s--;
                    }
                }
            }
        }
        printf("%d\n",sum);
    }
    }   
}
int n;
int a[1002],b[1002];
int solve(int start);
int main(){
	int i;
	while(scanf("%d",&n) &&n){
		for(i=0;i<n;i++)
			scanf("%d",b+i);
		for(i=0;i<n;i++)
			scanf("%d",a+i);
		sort(a,a+n);
		sort(b,b+n);
		int maxp=-99999999;
		for(i=0;i<n;i++){
			int temp=solve(i);
			if(maxp<temp)maxp=temp;
		}
		printf("%d\n",maxp);
	}
	return 0;
}

int solve(int start){
	int i;
	int sum=0;
	for(i=start;i<n;i++){
		if(b[i]>a[i-start])sum+=200;
		else if(b[i]<a[i-start])sum-=200;
		else;
	}
	for(i=0;i<start;i++){
		if(b[i]>a[n-start+i])sum+=200;
		else if(b[i]<a[n-start+i])sum-=200;
		else;
	}
	return sum;
}
int a[1002],b[1002],n,sum,cas;
int cmp1( const void *a ,const void *b) 
{ 
 int i;
	 i=(*(int *)a)-(*(int *)b);
 return i;
}
int cmp2( const void *a ,const void *b) 
{ 
 int i;
	 i=(*(int *)b)-(*(int *)a);
 return i;
}
void solve()
{
	int i,j,k;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			if ((b[j]<a[i])&&(b[j]!=-1)&&(a[i]!=-1))
			{
				sum++;
				b[j]=-1;
				a[i]=-1;
				break;
			}
			/*if ((b[j]==a[i])&&(b[j]!=-1)&&(a[i]!=-1))
			{
				cas--;
				b[j]=-1;
				a[i]=-1;
				break;
			}*/
		}
	}
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			if ((b[j]==a[i])&&(b[j]!=-1)&&(a[i]!=-1))
			{
				cas++;
				b[j]=-1;
				a[i]=-1;
				break;
			}
		}
	}
//	cout<<"cas="<<cas<<endl;
//	cout<<"sum="<<sum<<endl;

	cout<<200*(sum-(n-cas-sum))<<endl;
}

int main()
{
	int i;
	while (scanf("%d",&n))
	{
		if (n==0)
			break;
		sum=0;
		cas=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		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(a[1]),cmp1);
		qsort(&b[1],n,sizeof(b[1]),cmp2);
		/*for (i=1;i<=n;i++)
			cout<<a[i]<<" ";
		cout<<endl;
		for (i=1;i<=n;i++)
			cout<<b[i]<<" ";
		cout<<endl;*/
		solve();
	}
}