semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
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 mycompare(const void * elem1, const void * elem2)
{
	int *p1, *p2;
	p1 = (int *)elem1;
	p2 = (int *)elem2;
	return *p2 - *p1;
}

int main()
{
	int n, i, money, khead, thead, ktail, ttail;
	int horse[2][1005];
	while (cin >> n)
	{
		if (n == 0)
			break;
		money = 0;
		for (i = 0; i < n; i ++)
			cin >> horse[0][i];
		for (i = 0; i < n; i ++)
			cin >> horse[1][i];
		qsort(horse[0], n, sizeof(int), mycompare);
		qsort(horse[1], n, sizeof(int), mycompare);
		khead = thead = 0;
		ktail = ttail = n - 1;
		while (khead <= ktail && thead <= ttail)
		{
			if (horse[0][thead] > horse[1][khead])//??????????????????? ??????????
			{
				thead ++;
				khead ++;
				money += 200;
			}
			else if (horse[0][thead] < horse[1][khead])//??????????????????? ???????????????
			{
				khead ++;
				ttail --;
				money -= 200;
			}
			else//???????????????????????,????????????????,??????
			{
				while (thead <= ttail && khead <= ktail)
				{
					if (horse[0][ttail] > horse[1][ktail])
					{
						ttail --;
						ktail --;
						money += 200;
					}
					else
					{
						if (horse[0][ttail] < horse[1][khead])
							money -= 200;
						ttail --;
						khead ++;
						break;
					}
				}
			}
		}
		cout << money << endl;
	}
	return 0;
}

/*
?????
?????????????????????????????
????????????????????????????
?????????????????????????????????->???????????
???????????????????O(n)?

  
??????? 

(1)??????????????????? ??????????

     ??????? ?????????????? ????????????? ???????????????????? ????

     ???????????(????? ???????)  ?????????? ???????????

(2)??????????????????????? 

     ???????????????????????????? ??????????? ???????????????????  

     ??????? ????????????????? ????? ???????????????

(2)??????????????????? ??????????????? ???????(???)

     ????????????????????????? ????????????? ??????????? ?????????

     ????????? ?

  */
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 a[1000],b[1000],ans[1000],a1[1000],n,p;
void change()
{    
     int i;
     for (i=0;i<n-p;i++)
       a[i+p]=a1[i];
     for (i=0;i<p;i++)
       a[i]=a1[n-i-1];
}
int calc()
{ int s,i,j;
  s=0;
  for (i=0;i<n;i++)
  if (a[i]>b[i]) s=s+200;
  else if (a[i]<b[i]) s=s-200;
  return(s);
}
void make(int a[1000])
{
     int i,j,k,p;
     for (i=0;i<n-1;i++)
     { p=i;
       for (j=i+1;j<n;j++)
       if (a[j]>a[p]) p=j;
       k=a[i]; a[i]=a[p]; a[p]=k;
     }
}
main()
{
      
      int i,j,k,max;
      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]);
            make(a); make(b);
            for (i=0;i<n;i++)
            a1[i]=a[i];
            p=1;
            while (p<n)
            {ans[p]=calc();
             change();
             p++;
             }
            max=-200000;
            for (i=1;i<n;i++)
            if (ans[i]>max) max=ans[i];
            printf("%d\n",max);
            scanf("%d",&n);
      }
}
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);
	}
}
main(){
	int n,i,j,flag,max,maxnum,money,t[1001],q[1001],temp;
	while(1){
		scanf("%d",&n);
		if(!n)break;
		for(i=0;i<n;i++)scanf("%d",&t[i]);
		for(i=0;i<n;i++)scanf("%d",&q[i]);

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

		for(i=0;i<n;i++){
			flag=0;
			max=-100;maxnum=-1;
			for(j=0;j<n;j++){
				if(q[j]<t[i]&&q[j]>max){
					max=q[j];maxnum=j;flag=1;
				}
			}
			if(flag){
				t[i]=-100;q[maxnum]=-100;money+=200;
			}
		}

		for(i=0;i<n;i++){
			if(t[i]==-100)continue;
			for(j=0;j<n;j++){
				if(q[j]==-100)continue;
				if(t[i]==q[j]){
					t[i]=-100;q[j]=-100;break;
				}
			}
		} 

		for(i=0;i<n;i++){
			if(q[i]!=-100){
				money-=200;
			}
		}

		printf("%d\n",money);
	}
	return 0;
}
int main()
{
	int n;
	int a[1000],b[1000];                    //a????b???
	int circle,i,j;
	int i1,i2,j1,j2;
	int count,win;
	int t;
	for(circle=0;;circle++)
	{
		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-1;i++)
		{
			for(j=0;j<n-1-i;j++)
				if(a[j]<a[j+1])
				{
					t=a[j];
					a[j]=a[j+1];
					a[j+1]=t;
				}
		}
		for(i=0;i<n-1;i++)
		{
			for(j=0;j<n-1-i;j++)
				if(b[j]<b[j+1])
				{
					t=b[j];
					b[j]=b[j+1];
					b[j+1]=t;
				}
		}
		win=0;
		count=0;
		i1=0;
		i2=n-1;
		j1=0;
		j2=n-1;
		while(count<n)
		{
			for(;i1<=n-1-(n-1-i2);i1++,j1++)
			{
				if(a[i1]>b[j1])
				{
					win++;
					count++;
				}
				else
				{
					j1++;
					break;
				}
			}              //??
			if(count==n)
				break;
			for(;j2>=0;i2--,j2--)
			{
				if(a[i2]>b[j2])
				{
					win++;
					count++;
				}
				else
				{
					i2--;
					break;
				}
			}                       //??
			if(count==n)
				break;
			if(a[i2+1]<b[j1-1])
				win--;                 //?a[t2]?b[t1]?
			count++;
		}
		printf("%d\n",win*200);
	}
	return 0;
}
int main()
{
 int n,t[1000],q[1000],i,j,win=0,ping=0,x=0,num=0;
 n=1;
 while(n!=0)
 {
 int tian[1000]={0};
 int qi[1000]={0};
  win=0;
  ping=0;
  scanf("%d\n",&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]); 
  for(j=0;j<n;j++)
  {
      for(i=1+j;i<n;i++)
      {
       if(t[j]>=t[i])
      {
        num=t[i];
         t[i]=t[j];
        t[j]=num;
      }
      }
  }                           
  for(j=0;j<n;j++)
  {
      for(i=1+j;i<n;i++)
      {
       if(q[j]>=q[i])
      {
          num=q[i];
          q[i]=q[j];
          q[j]=num;
      }
      }
  }                           
  for(i=0;i<n;i++)
  {
   for(j=n-1;j>=0;j--)
   {
    if(tian[i]==0 && qi[j]==0)
    if(t[i]>q[j])
    {
     tian[i]=1;
     qi[j]=1;
     win++;
     break;
    }
   }
  }
  for(i=0;i<n;i++)
  {
   if(tian[i]==0)
   for(j=0;j<n;j++)
   {
    if(qi[j]==0)
     if(t[i]==q[j])
     {
      ping++;
      break;
     }
   }
  }
  printf("%d\n",400*win+200*ping-200*n);
 } 
 return 0;
}
int Compare(const void *elem1,const void *elem2)
      {
       return *((int *)(elem2)) - *((int *)(elem1));
       }
      
main()
{
      int n,i=0,j=0,counter=0,c=0,lose=0,k=0,l=0,m=0;
      int money[1000]={0};
      for(k=0;;k++)
      {
          scanf("%d",&n);
       if(n==0)
          {break;}
       else
       {
          
          int q[1000]={0};
          int t[1000]={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);
           m=0;
           for(j=0;n>0;j++)
           {
                   counter=0,c=0,lose=0;
                   for(i=0;(q[i]<t[i])&&(i<n);i++)
                   {
                       counter=counter+1;         /*??????counter????*/ 
                       
                   }
                   
                   for(i=0;i<=n-counter-1;i++)
                   {
                       q[i]=q[i+counter];       
                       t[i]=t[i+counter];
                   }
                   n=n-counter;
                   m=m+counter;
                   if(n==0)
                   break;
                   
                   for(i=n-1;q[i]<t[i];i--)
                   {
                       c++;                    /*??????c????*/ 
                   }
                   n=n-c;
                   m=m+c;
                   if(n==0)
                   break;
                   
                   if(q[0]>t[n-1])
                   {lose++;}                         /*?????*/ 
                   m=m-lose;
                   for(i=0;i<=n-1;i++)        
                   {
                       q[i]=q[i+1];                /*???????pass*/
                   }
                   
                                            
                   n=n-1;
            
            }
       
          money[k]=200*(m);               
          
          l++;
          
         }
          
       }
             
               for(k=0;k<l;k++)
                {
                printf("%d\n",money[k]);              /*??????????????*/
                }


}
int main()
{
    int a[1010], b[1010], fa[1010], fb[1010], f[1010];
    int i, j, p1, p2, q1, q2, n, ans, t, cot;
    scanf("%d", &n);
    while(n!=0)
    {
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        memset(fa, 0, sizeof(fa));
        memset(fb, 0, sizeof(fb));
        for(i=1; i<=n; i++)
            scanf("%d", &b[i]);
        for(i=1; i<=n; i++)
            scanf("%d", &a[i]);
        for(i=n-1; i>=1; i--)
            for(j=1; j<=i; j++)
            {
                if(a[j]<a[j+1])
                {
                    t = a[j]; a[j] = a[j+1]; a[j+1] = t;
                }
                if(b[j]<b[j+1])
                {
                    t = b[j]; b[j] = b[j+1]; b[j+1] = t;
                }
            }
        if(b[1]<a[n])
        {
            printf("%d\n", -200*n);
            scanf("%d", &n);
            continue;
        }
        ans = 0;
        p1 = 1;
        p2 = 1;
        q1 = n;
        q2 = n;
        cot = 0;
        while((++cot)<=n)
        {
            if(a[p1]<b[p2])
            {
                ans++;
                p1++;
                p2++;
            }
            else if(a[p1]>b[p2])
            {
                ans--;
                p1++;
                q2--;
            }
            else
            {
                if(a[q1]<b[q2])
                {
                    ans++;
                    q1--;
                    q2--;
                }
                else
                {
                    if(a[p1]>b[q2])
                    {
                        ans--;
                        p1++;
                        q2--;
                    }
                }
            }
        }
        printf("%d\n", ans*200);
        scanf("%d", &n);
    }
    return 0;
}
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 TianJi[M], King[M];

int dp[M][M];          //dp[i][j]????????????????????i?????,

                       //?"?"??j?????,?"?"??i-j?????,??????????.

 
int cmp(const void *a, const void *b)

{

       return *(int *)b - *(int *)a;

}

 
int profit(int x, int y)

{

       if (TianJi[x] > King[y])

       {

              return 200;

       }

       else if (TianJi[x] < King[y])

       {

              return -200;

       }

       else

       {

              return 0;

       }

}

 
void main()

{



 
       int i, j, n;

       while(scanf("%d", &n)&&n!=0)

       {

              memset(dp, 0, sizeof(dp));

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

              {

                     scanf("%d", &TianJi[i]);

              }

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

              {

                     scanf("%d", &King[i]);

              }

              //?????????????????

              qsort(TianJi + 1, n, sizeof(TianJi[0]), cmp);

              qsort(King + 1, n, sizeof(King[0]), cmp);

              //??dp

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

              {

                     //????????????????????????,????????????????????

                     dp[i][0] = dp[i - 1][0] + profit(n - i + 1, i);  
                     //????????????????????????,????????????????

                     dp[i][i] = dp[i - 1][i - 1] + profit(i, i);

                     //?????????????????????????,?????????????????,????i?????????

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

                     {

                            dp[i][j] = max( ( dp[i - 1][j] + profit(n - (i - j) + 1, i) ), ( dp[i - 1][j - 1] + profit(j, i) ) );

                     }

              }

              //????????

              int ans = -99999999;

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

              {

                     if (ans < dp[n][i])

                     {

                            ans = dp[n][i];

                     }

              }

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

       }

}