semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int mycompare(const void *elem1, const void *elem2)
{
	return *((int *)elem2) - *((int *)elem1);
}
int main()
{
	int n;
	while (cin >> n, n != 0)
	{
		int a[1000] = {0};
		int b[1000] = {0};
		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), mycompare);
		qsort(b, n, sizeof(int), mycompare);
		int index1_head = 0, index1_tail = n-1;
		int index2_head = 0, index2_tail = n-1;
		int money = 0;
		while (index1_head <= index1_tail)
		{
			if (a[index1_head] > b[index2_head])
			{
				index1_head++;
				index2_head++;
				money += 200;
			}
			else if (a[index1_tail] > b[index2_tail])
			{
				index1_tail--;
				index2_tail--;
				money += 200;
			}
			else 
			{
				if (b[index2_head] > a[index1_tail]) money -= 200;
				index1_tail--;
				index2_head++;
			}
		}
		cout << money << endl;
	}
return 0;
}
int main()
{
    int num;
    int store[100];
    for(num=0;;num++)
{
	int i,n,j;
	int a[100000],b[100000];
	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]);
	}
	a[n]=2147483647;
	b[n]=2147483647;
	for(i=0;i<n;i++)
	{
		int t;
		for(j=0;j<n-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;i++)
	{
		int t;
		for(j=0;j<n-i;j++)
		{
			if(b[j]>b[j+1])
			{t=b[j];b[j]=b[j+1];b[j+1]=t;}
		}
	}
	int money=0,x,q=0;
	int m[100000];
	for(x=0;x<n;x++)
	{
		int t;
		t=a[0];
		for(i=0;i<n;i++)
		{
			a[i]=a[i+1];
		}
		a[n-1]=t;
	for(i=0;i<n;i++)
	{
		if(a[i]>b[i])
		{money=money+200;}
		else
		{
			if(a[i]<b[i])
			{money=money-200;}
		}
	}
	m[q]=money;
	money=0;
	q++;
	}
	int max=m[0];
	for(i=1;i<n;i++)
	{
		if(m[i]>=max)
			max=m[i];
	}
	store[num]=max;
	
}
int w;
for(w=0;w<num;w++)
{
printf("%d\n",store[w]);
}
}
main()
{
      int wang[1000],tian[1000];
      int head,tailw,tailt,i,j,m,n,t,sum;
      for(;;)
      {
             sum=0;
             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]);
             for(i=0;i<n-1;i++)
             for(j=i+1;j<n;j++)
             {
                               if(tian[j]>tian[i])
                               {
                                                  t=tian[j];
                                                  tian[j]=tian[i];
                                                  tian[i]=t;
                               }
                               if(wang[j]>wang[i])
                               {
                                                  t=wang[j];
                                                  wang[j]=wang[i];
                                                  wang[i]=t;
                               }
             }
             head=0;
             tailw=n-1;
             tailt=n-1;
             for(i=0;i<n;i++)
             {
                             if(tian[head]>wang[i])
                             {
                                                   sum++;
                                                   head++;
                             }
                             else if(tian[head]<wang[i])
                             {
                                  tailt--;
                                  sum--;
                             }
                             else if(tian[head]==wang[i])
                             {
                                  for(j=tailt,m=tailw;j>=head;j--,m--)
                                  {
                                                                      if(tian[j]>wang[m])
                                                                      {
                                                                                         tailt--;
                                                                                         tailw--;
                                                                                         sum++;
                                                                      }
                                                                      else 
                                                                      {
                                                                           if(tian[j]<wang[i]) sum--;
                                                                           tailt--;
                                                                           tailw=m;
                                                                           break;
                                                                      }
                                  }
                             }
                             if(head>tailt) break;
             }
             printf("%d\n",sum*200);
      }
    }
main()
{
      int n,i,j,a[1001],b[1001],t,f=0; 
      while(1)
      {f++;
      scanf("%d",&n);
      if(n==0)
      break;
      for(i=1;i<=n;i++)
      scanf("%d",&a[i]);
      for(i=1;i<=n;i++)
      scanf("%d",&b[i]);
      for(i=1;i<n;i++)
      {
           for(j=i+1;j<=n;j++)
           {
                 if(a[i]<a[j])
                 {
                       t=a[i];
                       a[i]=a[j];
                       a[j]=t;
                 }
           }
      }
      for(i=1;i<n;i++)
      {
           for(j=i+1;j<=n;j++)
           {
                 if(b[i]<b[j])
                 {
                       t=b[i];
                       b[i]=b[j];
                       b[j]=t;
                 }
           }
      }
      int x1,x2=0,y1,s1,s,k;
      for(k=n;k>=1;k--)
      {
      x1=0,y1=0,x2=0;
      for(i=n-k+1;i<=n;i++)
      {
           if(b[i]<a[i-n+k])
           x1++;
           else if(b[i]==a[i-n+k])
           y1++;
      }
      s1=400*x1+200*y1-200*n;
      if(k==n)
      s=s1;
      else if(s1>s)
      s=s1;
      }
      printf("%d\n",s);
      }
}
int tj[1000],qw[1000],n,money=0;
void games(int n)
{
if(n>1)
{
	int i,j,mid;
	if(tj[n-1]<qw[n-1])
	{
	    tj[n-1]=0;qw[0]=0;money=money-200;
        for(i=0;i<n-1;i++)
		qw[i]=qw[i+1];
	}
	else if(tj[n-1]>qw[n-1])
	{
		tj[n-1]=0;qw[n-1]=0;money=money+200;
	}
	else if(tj[0]>qw[0])
	{
		tj[0]=0;qw[0]=0;money=money+200;
		for(i=0;i<n-1;i++)
		{tj[i]=tj[i+1];qw[i]=qw[i+1];}
	}
	else if(tj[0]<=qw[0])
	{
		if(tj[n-1]<qw[0])money=money-200;
		tj[n-1]=0;qw[0]=0;
        for(i=0;i<n-1;i++)
		qw[i]=qw[i+1];
	}
	games(n-1);
}
	if(n==1)
	{
		if(tj[0]>qw[0])money=money+200;
		if(tj[0]<qw[0])money=money-200;
	}
}
void main()
{
	int i,j,mid;
	while(1)
	{
		scanf("%d",&n);
		if(n==0) break;
		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;i++)
		for(j=i;j<n;j++)
		{
		if(tj[j]>tj[i])
		{
			mid=tj[j];tj[j]=tj[i];tj[i]=mid;
		}
		if(qw[j]>qw[i])
		{
			mid=qw[j];qw[j]=qw[i];qw[i]=mid;
		}
		}
		games(n);
		printf("%d\n",money);
		money=0;
	}
}
int myfunc(const void *a, const void *b)
{
	return *(int *)a-*(int *)b;
}
int max(int a, int b)
{
	return a>b?a:b;
}
int main()
{
	int t[2000];
	int q[1000];
	int n;
	int i, start;
	int sum, tmp;
	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);
		qsort(t, n, sizeof(int), myfunc);
		qsort(q, n, sizeof(int), myfunc);
		memcpy(t+n, t, n);
		sum = -0xFFFFFFF;
		for (start = 0; start < n; start ++) {
			tmp = 0;
			for (i = 0; i < n; i ++) {
				if (t[start+i] < q[i])
					tmp -= 200;
				if (t[start+i] > q[i])
					tmp += 200;
			}
			sum = max(sum, tmp);
		}
		printf("%d\n", sum);
	}
	return 0;
}
void paixu(int *a,int n)              //n?????,?????? 
{
     int i,j,t;
     for(i=0;i<n;i++)
     {
                     for(j=0;j<n-i-1;j++)
                        {
                                            if(a[j]>a[j+1])
                                            {
                                                           t=a[j];
                                                           a[j]=a[j+1];
                                                           a[j+1]=t;
                                                           }
                                                           }
                                                           }
}
main()
{
      int i,j,k,a[1000],b[1000],m,n,p,q;                     //a????????b????? 
      loop:;
      k=0;                    //k??????? 
      scanf("%d",&n);
      if(n==0)
      return 0;
      for(j=0;j<n;j++)
      scanf("%d",&a[j]);
      for(j=0;j<n;j++)
      scanf("%d",&b[j]);
      paixu(a,n);
      paixu(b,n);
      p=n;               //j???????? 
      q=0;                //q???????????? 
      for(i=0;i<n;i++)
      {
                      if(a[i]>b[q])
                      {
                                   k++;
                                   q++;
                                   continue;
                                   }
                      else if(a[i]<b[q])
                      {
                          p--;
                          k--;
                          continue;
                          }
                      else
                      {
                          if(a[n-1]>b[p-1])
                          {
                                           k++;
                                           n--;
                                           i--;
                                           p--;
                                           continue;
                                           }
                          else if(a[n-1]<b[p-1])
                          {
                               k--;
                               p--;
                               continue;
                               }
                          else
                          {
                              if(a[i]<b[p-1])
                              {
                              k--;
                              p--;
                              continue;
                              }
                              else if(a[i]==b[p-1])
                              break;
                              }
                              }
                              }
      printf("%d\n",200*k);                 
      goto loop;
      }
int compare(const void *p,const void *q)
{
	return *((int *)p)-*((int *)q);
}
int main()
{
	int n,i,t[1000],q[1000];
	while(cin>>n)
	{
		if(n==0)
			break;
		int count=0;
		for(i=0;i<n;i++)
			cin>>t[i];
		for(i=0;i<n;i++)
			cin>>q[i];
		qsort(t,n,sizeof(int),compare);
		qsort(q,n,sizeof(int),compare);
		int tmin=0,tmax=n-1,qmin=0,qmax=n-1;
		while(tmin<=tmax)
		{
			if(t[tmax]<q[qmax])
			{
				qmax--;
				tmin++;
				count--;
			}
			else if(t[tmax]>q[qmax])
			{
				qmax--;
				tmax--;
				count++;
			}
			else
			{
				if(t[tmin]>q[qmin])
				{
					count++;
					tmin++;
					qmin++;
				}
				else if(t[tmin]<q[qmin])
				{
					count--;
					tmin++;
					qmax--;
				}
				else
				{
					if(t[tmax]>t[tmin])
					{
						count--;
						tmin++;
						qmax--;
					}
					else
					{
						break;
					}
				}
			}
		}
		cout<<count*200<<endl;
	}
	return 0;
}
int main()
{
	int n,a[1000],b[1000],i,j,i0,j0,sum = 0;
	while(cin>>n)
	{
		sum = 0;
		if(n == 0)
			break;
		for(i = 0;i<n;i++)
			cin>>a[i];
		for(i = 0;i<n;i++)
			cin>>b[i];
		sort(a,a+n);
		sort(b,b+n);
		for(i=j=n-1,i0=j0=0;j>=j0&&i>=i0;j--)
		{
			if(a[i]>b[j])
			{
				sum++;
				i--;
			}
			else if(a[i]<b[j])
			{
				sum--;i0++;
			}
			else 
			{
				if(a[i0]>b[j0])
				{
					sum++;i0++;j0++; j++;
				}
				else if(a[i0]<b[j0])
				{
					sum--;i0++;
				}
				else
				{
					if(a[i0]==b[j])
					{
						i0++;
					}
					else
					{
						sum--;i0++;
					}
				}
			}
		}
		cout<<200*sum<<endl;
	}
	return 0;
}
int main()
{
    int n[100];
    int tianji[100][1000];
    int qiwang[100][1000];
    int i;
    for(i=0;;i++)
    {
        scanf("%d",&n[i]);
        if(n[i]==0)
        {
            break;       
        }
        else
        {
            for(int j=0;j<=n[i]-1;j++)
            {
                scanf("%d",&tianji[i][j]);    
            }
            for(int k=0;k<=n[i]-1;k++)
            {
                scanf("%d",&qiwang[i][k]);    
            }
        }            
    }
    for(int l=0;l<=i-1;l++)
    {  
        for(int j=n[l]-1;j>0;j--)
        {
            for(int k=0;k<j;k++)
            {
                if(tianji[l][k]>tianji[l][k+1])
                {
                    int temp;
                    temp=tianji[l][k+1];
                    tianji[l][k+1]=tianji[l][k];
                    tianji[l][k]=temp;                         
                }
                if(qiwang[l][k]>qiwang[l][k+1])
                {
                    int temp;
                    temp=qiwang[l][k+1];
                    qiwang[l][k+1]=qiwang[l][k];
                    qiwang[l][k]=temp;                         
                }                    
            }    
        }    
    }
    for(int l=0;l<=i-1;l++)
    {
        int t1=0,t2=n[l]-1;
        int q1=0,q2=n[l]-1;
        int count=0;
        for(;t1<=t2;)
        {
            if(tianji[l][t2]>qiwang[l][q2])
            {
                count++;
                t2--;
                q2--;                       
            }        
            else if(tianji[l][t1]>qiwang[l][q1])
            {
                count++;
                t1++;
                q1++; 
            } 
            else if(tianji[l][t1]<qiwang[l][q2])
            {
                count--;
                t1++;
                q2--;
            }
            else
            {
                t1++;
                q2--;
            } 
        } 
        printf("%d\n",200*count);   
    }
    return 0;    
}
int vs[MaxN][MaxN];
int f[MaxN][MaxN];
int qiwang[MaxN] , tianji[MaxN];

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

int vs1(int x, int y)
{

    if (tianji[x] > qiwang[y]) return 200;
    else if (tianji[x] < qiwang[y]) return -200;
        else return 0;
}

int sort(int a[MaxN],int l, int r)
{

    int i = l, j = r, k = a[(i+j)/2];

    while (i <= j)
    {
        while (a[i] > k) ++i;
        while (k > a[j]) --j;
        if (i <= j)
        {

            int x = a[i];
            a[i] = a[j];
            a[j] = x;
            ++i;
            --j;
        }
    }
    if (l < j) sort(a,l,j);
    if (i < r) sort(a,i,r);
}
int main()
{
  //  freopen("1.in","r",stdin);
   // printf("2\n");


    int k, L, n , i , j , a ;
	scanf("%d" , &n );
	while (n)
	{



		//qiwang = (int*)malloc(n*sizeof(int));
	//	tianji = (int*)malloc(n*sizeof(int));
		for ( i = 0 ; i < n ; i ++ )  scanf("%d" , &tianji[i] );
		for ( i = 0 ; i < n ; i ++ ) { scanf("%d" , &qiwang[i] );}//printf(" %d ",i);}

        sort(tianji,0,n-1);
        sort(qiwang,0,n-1);

    for (i = 0; i < n; ++i) f[i][i] = vs1(i,n-1);
       for (L = 1; L < n; ++L)
            for (i = 0; i < n-L; ++i)
            {
                j = i + L;
                f[i][j] = max ( f[i+1][j] + vs1(i,n-1-L) , f[i][j-1] + vs1(j,n-1-L) );
            }
		printf("%d\n",f[0][n-1]);
	scanf("%d" , &n );
	}
	return 0;
}
int cmp(const void * a, const void * b) {
        return *(int *)a - *(int *)b;
}
int a[1000], b[1000], queue[1001];
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();
            //        printf("dequeue: %d\n", dequeue());
                    win ++;
                }
                else {
                                if (a[i] == b[j])
                        enqueue(a[i --]);
                }
            }
                }
        draw = size();
                ans = (2 * win - n + draw) * 200;
                printf("%d\n", ans);
//              printf("ans : %d\n", ans);
//              printf("win : %d\n", win);
//              printf("draw: %d\n", draw);
        }
        return 0;
}
int main()
{   
	int n,s,m,i,j,t=0,sum=0;
	int fast1,slow1,fast2,slow2; 
	int a[1000],b[1000];
	for(m=0;;m++){
  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]);
		for(i=0;i<n-1;i++){
			for(j=0;j<n-1-i;j++){
            if(a[j]<a[j+1])
			{s=a[j];a[j]=a[j+1];a[j+1]=s;}}}
        for(i=0;i<n-1;i++){
			for(j=0;j<n-1-i;j++){
			if(b[j]<b[j+1])
			{s=b[j];b[j]=b[j+1];b[j+1]=s;}}}   
 
     fast1=0;slow1=n-1;
     fast2=0;slow2=n-1;    
     
    for(i=0;i<n;i++)         
	{
	    if(a[fast1]==b[fast2])    
		{
		   if(a[slow1]>b[slow2]){t++;slow1--;slow2--;}
		   else if(a[slow1]<b[slow2]){t--;slow1--;fast2++;}
           else if(a[slow1]==b[slow2])
		   {
			   if(a[slow1]<b[fast2]){t--;slow1--;fast2++;}
               else if(a[slow1]==b[fast2]){break;}
		   }
		}
        else if(a[fast1]>b[fast2])     
		{t++;fast1++;fast2++;}
		else    {t--;slow1--;fast2++;} 
	}
   sum=t*200;
   printf("%d\n",sum);
   t=0;sum=0;
  }
  if(n==0) break;}
  
}
void main()
{
int m,n,tq[2][1000],j,k,w,K,money,g,a,c[100],d,e,i;
for(m=0,d=0;;m++,d++)
{
scanf("%d",&n);
if(n==0)break;
for(j=0;j<2;j++)
for(k=0;k<n;k++)scanf("%d",&tq[j][k]);
for(j=0,k=0;k<n-1;k++)
         for(K=0;K<n-1-k;K++)
         if(tq[0][K]<tq[0][K+1])
         {
                 w=tq[0][K];
                 tq[0][K]=tq[0][K+1];
                 tq[0][K+1]=w;
         }
for(j=1,k=0;k<n-1;k++)
         for(K=0;K<n-1-k;K++)
         if(tq[1][K]<tq[1][K+1])
         {
                 w=tq[1][K];
                 tq[1][K]=tq[1][K+1];
                 tq[1][K+1]=w;
         }
for(g=n-1,money=0;g>0;g--)
{
         if(tq[0][g]>tq[1][g])i=0;
         if(tq[0][g]<tq[1][g])i=1;
         if(tq[0][g]==tq[1][g])
         {
                 if(tq[0][0]>tq[1][0])i=2;
                 if(tq[0][0]<tq[1][0])i=3;
                 if(tq[0][0]==tq[1][0])i=4;
         }
            switch(i)
         {
         case 0:money=money+200;break;
         case 1:money=money-200;for(a=0;a<g;a++)tq[1][a]=tq[1][a+1];break;
         case 2:money=money+200;for(a=0;a<g;a++)tq[1][a]=tq[1][a+1];for(e=0;e<g;e++)tq[0][e]=tq[0][e+1];break;
         case 3:money=money-200;for(a=0;a<g;a++)tq[1][a]=tq[1][a+1];break;
         case 4:
                 {
                 if(tq[0][g]>tq[1][0])money=money+200;
                 if(tq[0][g]==tq[1][0])money=money+0;
                 if(tq[0][g]<tq[1][0])money=money-200;
                 for(a=0;a<g;a++)tq[1][a]=tq[1][a+1];
                 break;
                 }
         }
}
if(tq[0][0]>tq[1][0])money=money+200;
if(tq[0][0]==tq[1][0])money=money+0;
if(tq[0][0]<tq[1][0])money=money-200;
c[m]=money;
}
for(m=0;m<d;m++)printf("%d\n",c[m]);//?????????????
}
int main()
{
    int n,m,i,j,s,M,k1,l1,l2;
    for(i=0;;i++)
    {
       scanf("%d",&n);
       if(n==0)   break;
       else
       {
         int * t=(int*)malloc((n+1)*sizeof(int));
         int * q=(int*)malloc((n+1)*sizeof(int));
         for(j=0;j<n;j++)
         {scanf("%d",t+j);}
         for(j=0;j<n;j++)
         {scanf("%d",q+j);}
        for(j=0;j<n-1;j++)
         {
             for(m=j+1;m<n;m++)
             {
                if(*(t+j)<*(t+m))
                {s=*(t+j);*(t+j)=*(t+m);*(t+m)=s;}
             }
         }
         for(j=0;j<n-1;j++)
         {
             for(m=j+1;m<n;m++)
             {
                if(*(q+j)<*(q+m))
                {s=*(q+j);*(q+j)=*(q+m);*(q+m)=s;}
             }
         }
                 k1=0;M=0;l2=n-1;l1=n-1;
             for(j=0;j<n;j++)
             {
                   if(q[j]<0)
                     break;
                     else
                  {
                    if(q[j]<t[k1])
                    {M=M+200;k1+=1;q[j]=-9;}
                    if(q[j]==t[k1])
                    {
                          for(m=0;;m++)
                          {
                              if(q[l2]<0)
                              break;
                             if(q[l2]>=t[l1])
                             {
                                 if(t[l1]<q[j])
                                 {M=M-200;l1=l1-1;q[j]=-9;break;}
                                 else
                                 { l1=l1-1;q[j]=-9;break; }
                             }
                             if(q[l2]<t[l1])
                             {M=M+200;q[l2]=-9;l1=l1-1;l2=l2-1;}
                          }
                       }
                    if(q[j]>t[k1])
                    {M=M-200;l1=l1-1;q[j]=-9;}
                 }
             }
              printf("%d\n",M);
              free(t);
             free(q);
         }
       }
          return 0;
}
void pailie(int*a,int n);
int f(int*a,int*b,int n);
int maxa(int x,int y);
main()
{
      int n,a[1000],b[1000],i;
      for(;;)
      {
          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]);
          pailie(a,n);
          pailie(b,n);
          printf("%d\n",f(a,b,n));
      }
      return 0;    
}
void pailie(int *a,int n)
{
     int i,j;
     for(i=0;i<n;i++)
     {
         int max=i;
         for(j=i+1;j<n;j++)
                 if (a[j]>a[max])
                     max=j;
         int temp=a[i];
         a[i]=a[max];
         a[max]=temp;
     }
}
int f(int *a,int *b,int n)
{
    int max;
    int i,j;
    int g[1001][1001];
    for(i=0;i<=n;i++)
       for(j=0;j<=n;j++)
          g[i][j]=-300000;
    g[0][0]=0;
 
    for(i=0;i<n;i++)
        for(j=0;j<=i;j++)
        {
           if(g[i][j]>-200000)
           {
                          
               if (a[j]>b[i]) 
                    {g[i+1][j+1]=maxa(g[i][j]+200,g[i+1][j+1]);}
               else if(a[j]<b[i])
                    {g[i+1][j]=maxa(g[i][j]-200,g[i+1][j]);}
               else if(a[j]==b[i]&&b[i]==a[n-1-i+j])
                    {g[i+1][j]=maxa(g[i][j],g[i+1][j]);}
               else
                    {g[i+1][j+1]=maxa(g[i][j],g[i+1][j+1]);g[i+1][j]=maxa(g[i][j]-200,g[i+1][j]);}
           }
        }
    max=g[n][0];
    for(j=1;j<=n;j++)
        max=g[n][j]>max?g[n][j]:max;
    return (max);
}     
int maxa(int x,int y)
{
    return(x>y?x:y);
}
int N, a[1001], b[1001], f[1001][1001];
 
int main()
{
    scanf ("%d", &N);
    while (N != 0)
    {
	 for (int i = 1; i <= N; i ++)
   	     scanf ("%d", &a[i]);
   	 for (int i = 1; i <= N; i ++)
       scanf ("%d", &b[i]);
    sort(a + 1, a + N + 1);
    sort(b + 1, b + N + 1);
    for (int i = 1; i <= N; i ++)
        for (int j = 1; j <= N; j ++)
            if (a[i] > b[j])
                f[i][j] = f[i - 1][j - 1] + 1;
            else if (a[i] < b[j])
                f[i][j] = f[i][j - 1] - 1;
            else
                f[i][j] = max(f[i - 1][j - 1], f[i][j - 1] - 1);
    printf ("%d\n", f[N][N] * 200);
    scanf ("%d", &N);
}
    return 0;
}