int main()
{
int year,month,day,d=0;

scanf("%d%d%d\n",&year,&month,&day);

switch(month)
{case 1:d=0;break;
case 2:d=31;break;

case 3:d=59;break;

case 4:d=90;break;

case 5:d=120;break;

case 6:d=151;break;

case 7:d=181;break;

case 8:d=212;break;

case 9:d=243;break;

case 10:d =273;break;

case 11:d=304;break;

case 12:d=334;break;

}if ((month>2)&&(year%400==0)){d=d+1+day;}
else if ((month>2)&&(year%100!=0)&&(year%4==0)){ d=d+1+day;}

else {d=d+day;}

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

return 0;
}


main()
{
      int year,month,day;
      scanf("%d %d %d",&year,&month,&day);
      if ((year%4==0&&year%100!=0)||year%400==0)
      {
           switch (month)
           {
                  case 1: day=day;break;
                  case 2: day=day+31;break;
                  case 3: day=day+60;break;
                  case 4: day=day+91; break;
                  case 5: day=day+121;break;
                  case 6: day=day+152;break;
                  case 7: day=day+182;break;
                  case 8: day=day+213;break;
                  case 9: day=day+244;break;
                  case 10: day=day+274;break;
                  case 11: day=day+305;break;
                  case 12: day=day+335;break;
           }
      }
      else
      {
          switch (month)
           {
                  case 1: day=day;break;
                  case 2: day=day+31;break;
                  case 3: day=day+59;break;
                  case 4: day=day+90; break;
                  case 5: day=day+120;break;
                  case 6: day=day+151;break;
                  case 7: day=day+181;break;
                  case 8: day=day+212;break;
                  case 9: day=day+243;break;
                  case 10: day=day+273;break;
                  case 11: day=day+304;break;
                  case 12: day=day+334;break;
           }
      }
      printf("%d",day);
      getchar();
      getchar();
}


int main(int argc, char* argv[])
{
    int year,month,day,total,i;
	scanf("%d%d%d",&year,&month,&day);
	int monday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
	total=0;
	for(i=1;i<month;i++)
	{
        total=total+monday[i-1];
	}
	if(year%4==0&&year%100!=0||year%400==0)
		total=total+1;
	total=total+day;
	printf("%d",total);
	return 0;
}


int main ()
{
	int y,m,d,dd=0,i;
	scanf("%d%d%d",&y,&m,&d);
	if((y%4 == 0) && (y%100 !=0) ||(y%400 ==0))
	{
		for(i=1;i<m;i++)
		{
			switch(i)
			{
				case 1:
				case 3:
				case 5:
				case 7:
				case 8:
				case 10:
					dd += 31;
					break;
				case 2:
					dd += 29;
					break;
				case 4:
				case 6:
				case 9:
				case 11:
					dd += 30;
					break;
			}
		}
		dd = dd + d;
		printf("%d",dd);
	}
	else
	{
		for(i=1;i<m;i++)
		{
			switch(i)
			{
				case 1:
				case 3:
				case 5:
				case 7:
				case 8:
				case 10:
					dd += 31;
					break;
				case 2:
					dd += 28;
					break;
				case 4:
				case 6:
				case 9:
				case 11:
					dd += 30;
					break;
			}
		}
		dd = dd + d;
		printf("%d",dd);
	}
	return 0;
}


void main(){
	int isrunnian(int);
	int year,month,day,result=0;
	int i;
	scanf("%d",&year);
	scanf("%d",&month);
	scanf("%d",&day);
	for(i=1;i<month;i++){
		switch(i){
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			result=result+31;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			result=result+30;
			break;
		case 2:
			if(isrunnian(year)){
				result=result+29;
			}else{
				result=result+28;
			}
			break;
		}
	}
	result=result+day;
	printf("%d\n",result);
}

int isrunnian(int year){
	if(year%400==0){
		return 1;
	}else if(year%4==0&&year%100!=0){
		return 1;
	}else{
		return 0;
	}
}


int main()
{
	char c;
	int num[1000]={0},n,m=0,index=0,i,j;
	while(num[0]!=-1)
	{
		while(true)
		{
			scanf("%d",&num[index]);
			index++;
			scanf("%c",&c);
			if(c!=' ')
				break;
		}
		for(i=0;i<index;i++)
		{
			for(j=0;j<index;j++)
			{
				if(num[i]==2*num[j]||num[i]*2==num[j])
					m++;
			}
		}
		if(num[0]==-1)
		{
			return 0;
		}
		printf("%d\n",m/2);
		m=0;index=0;
	}
}


int main()
{
    int i,j;
    while(1)
    {
           int array[16]={0};
            int n=0,sum=0;
            while(1)
            {
                    cin>>array[n];
                    if(array[n]==0 || array[n]==-1)
                    {
                      n--;
                      break;
                    }
                   n++;
            }
            if(array[0]==-1)
             break;
            for(i=0;i<=n;++i)
            {
             for(j=i;j<=n;++j)
              {
                      if((array[i]==array[j]*2) || (array[j]==array[i]*2))
                            {
                             sum++;
                            }
                    }
            }
            cout<<sum<<endl;
    }

    return 0;
}


int main()
{
	int i, a[16];
	while(1)
	{
		for( i = 0;;i++)
		{
			cin >> a[i];
			if(a[i] == 0)
				break;
			if(a[i] == -1)
				goto end;
		}
		int count = 0;
		for(int m = 0; m < i; m++)
		{
			for(int n = 0; n < i; n++)
			{
				if(a[m] == a[n] * 2)
					count++;
			}
		}
		cout << count << endl;
	}
	end:
	return 0;
}


int main()
{
    int i,j,k,l,geshu,get,n=0;
    int shuzu[15];
    for(j=0;;j++){
        n=0;
        for(i=0;;i++){
	scanf("%d",&get);
	    if(get==-1){
                goto end;
	    }
	    shuzu[i]=get;
	    if(get==0){
	        geshu=i;
		break;
	    }
	}
	for(k=0;k<geshu;k++){
	    for(l=0;l<geshu;l++){
	        if(shuzu[k]==2*shuzu[l]){
	            n=n+1;
	        }
	    }
	}
	printf("%d\n",n);
    }
    end:return 0;
}


int main(){
    int c,a[20],t,sum;
    while(1){
        t=sum=0;
        while(1){
           scanf("%d",&c);
           if(!c || c==-1)break;
           a[t++]=c;
        }
        if(c==-1)break;
        for(int i=0;i<t;i++)
        for(int j=0;j<t;j++)
            if(a[j]==a[i]*2)sum++;
        printf("%d\n",sum);
    }
    return 0;
}


int main()
{
	int n=100,nfa[n];
    int a[n][16];
	memset(a,-100,sizeof(a));
	memset(nfa,0,sizeof(nfa));
	for(int i=0;i<n;i++)
		for(int j=0;j<16;j++){
			cin>>a[i][j];
			if(a[i][0]==-1){n=i;
			break;}
			if(a[i][j]==0)break;
		}
	for(int i=0;i<n;i++)
		for(int k=0;k<16;k++)
			for(int j=0;j<16;j++)
			   if(a[i][j]==2*a[i][k])nfa[i]++;
    for(int i=0;i<n;i++)cout<<nfa[i]-1<<endl;
    return 0;
}


int main(int argc, char* argv[])
{
   int shuzu[16];
   int i,j,k,number;
   for(k=1;1;k++){

	   scanf("%d",&shuzu[0]);
	   if(shuzu[0]==-1){
		   break;
	   }
        number=1;
	   for(i=1;i<16;i++){//????

		   scanf("%d",&shuzu[i]);
		   if(shuzu[i]==0){
			   break;
		   }
		   else number++;
	   }

       int zu=0;
	   double a,b;
	   for(i=0;i<number-1;i++){
		   for (j=number-1;j>i;j--){
			   a=(double)shuzu[i]/shuzu[j];
			   b=(double)shuzu[j]/shuzu[i];
			   if(a==2||b==2){
				   zu++;
			   }
		   }
	   }
	   printf("%d\n",zu);

   }

	return 0;
}


int main()
{
	int i=0,j=0,num[16]={0},count=0,key=0;
	cin>>num[0];
	while(num[0]!=-1)
	{
		for(i=0;num[i]!=0;i++)
		{
			cin>>num[i+1];
		}
		count=i;
		key=0;
		for(i=0;i<count;i++)
			for(j=i;j<count;j++)
				if(num[i]==2*num[j]||num[j]==2*num[i])
					key++;
		cout<<key<<endl;
		for(i=0;i<16;i++)
			num[i]=0;
		cin>>num[0];
	}
	return 0;
}


int main()
{
	int num[101],ori[15];
	int n,i,count,tot;

	scanf("%d",&n);
	while(n!=-1)
	{

		for(i=0;i<101;i++) num[i]=0;
		count=0;
		while(n!=0)
		{

			ori[count]=n;
			count++;
			num[n]=1;
			scanf("%d",&n);

		}
		tot=0;
		for(i=0;i<count;i++)
			if (ori[i]<=50&&num[ori[i]*2]) tot++;
			printf("%d\n",tot);
			scanf("%d",&n);

	}
	return 0;
}


/* Author: Yahoo */
/* Date: 2011-10-12 */
/* Function: random access to files */
/*#include<stdio.h>
int main()
{
	if(4==5,5)
		printf("good\n");
	return 0;
}*/
int main()
{
	int n, sum = 0, mat[100];
	memset(mat, 0, sizeof(mat));
	while(scanf("%d",&n),n != -1)
	{
		if(n == 0)
		{
			printf("%d\n", sum);
			sum = 0;
			memset(mat, 0, sizeof(mat));
		}
		else if(n > 49)
		{
			mat[n] = 1;
			if(mat[n>>1])
				sum++;
		}
		else
		{
			mat[n] = 1;
			if(mat[n<<1])
				sum++;
			if(!(n&1) && mat[n>>1])
				sum++;
		}
	}
	return 0;
}


int main()
{
	int m,i,j,k,key,num;
	key=0;
	int count[100];
	int a[100][156];
	int result[100];
	for(i=0;i<100;i++)
	{
		for(j=0;j<16;j++)
		{
			scanf("%d",&m);
			if(m==0)
			{
				break;
			}
			else if(m==-1)
			{
				key=1;
				break;
			}
			else
			{
				a[i][j]=m;
				count[i]=j;
			}
		}
		if(key==1)
		{
			break;
		}
		num=i;
	}
	for(i=0;i<=num;i++)
		result[i]=0;
	for(i=0;i<=num;i++)
	{
		for(j=0;j<=count[i];j++)
		{
			for(k=0;k<=count[i];k++)
			{
				if(a[i][j]==a[i][k]*2)
				    result[i]=result[i]+1;
			}
		}
	}
	for(i=0;i<=num;i++)
	{
		printf("%d\n",result[i]);
	}
	return 0;
}


//this program helps you to find how many pairs of numbers satisfy the standard that the one is double of the other
int main()
{
	int a[20],bn[100]={0,0,0},i,j,k,t=1,l;//bn is the number of double

	for(t=1;;t++)
	{
		i=1;
		do
		{                            //this loop is aimed at inputting the t group of numbers
			scanf("%d",&a[i-1]);
			if(a[i-1]==-1)break;
			i++;
		}while(a[i-2]!=0);
		if(a[i-1]==-1)break;
		for(j=1;j<=i-2;j++)        //this loop is aimed at check the sequence one by one
		{
			for(k=1;k<=i-2;k++)  //realize the checking
				if(a[j-1]==2*a[k-1])bn[t-1]++;
		}
	}
	for(l=1;l<=t-1;l++)
		printf("%d\n",bn[l-1]);
	return 0;
}


int main()
{
	int sz[16],i,a,num=0,no=0,j;
	while(1)
	{
		scanf("%d",&a);
			if(a==-1)
				return 0;
			else if(a>0)
			{
				sz[no]=a;
				no++;
			}
			else if(a==0)
			{
				for(i=0;i<no;i++)
				{

					for(j=0;j<no;j++)
					if(sz[i]==2*sz[j])
					num++;
				}

			printf("%d\n",num);
			no=0;
			num=0;

			}
	}

	return 0;

}


int iFind(int *p, int findnum)
{
	int k, sum = 0;
	for (k = 0; k < 15; k++)
	{
		if (*(p + k) == findnum)
			sum ++;
	}
	return sum;
}

int main()
{
	int a[15], temp, i = 0, j, k, *p, sum = 0;
	p = a;
	for (j = 0; j < 15; j++)
		a[j] = -1;
	while (cin >> temp, temp != -1)
	{
		if (temp != 0)
		{
			a[i] = temp;
			i++;
		}
		else
		{
			for (k = 0; k < 15; k++)
			{
				sum += iFind(p, a[k] * 2);
			}
			cout << sum << endl;
			sum = 0;
			i = 0;
			for (j = 0; j < 15; j++)
				a[j] = -1;
		}
	}
	return 0;
}


int main ()
{
	int array[15];
	int i,j,temp,min,flag,twice;
	for(;;)
	{

	for(i=0;i<15;i++)
		array[i]=0;
	for(i=0;;i++)
	{
		scanf("%d", &temp);
		if(temp==-1)
			return 0;
		if(temp==0)
			break;
		array[i]=temp;
	}
    // ??
    for(i=0;i<15;i++)
	{
			min=array[i];
			for(j=i+1;j<15;j++)
			{
				if(array[j]<min)
				{
					temp=min;
					min=array[j];
					array[j]=temp;
				}
			}
			array[i]=min;
	}
	//?????????
	for(flag=0,i=0;i<15;i++)
	{
        if(array[i]==0)
			continue;
		twice=array[i]*2;
		for(j=i+1;j<15;j++)
		{
			if(array[j]>twice)
				break;
			if(array[j]==twice)
				flag++;
		}
	}
	printf("%d\n\n",flag);
	}

	return 0;
}


int main()
{
    int data[16];
    int i, j;
    int len;
    int count;

    while(1)
    {
                  count = 0;
                  scanf("%d", &data[0]);
                  if(data[0] == -1)
                             break;

                  for(i = 1; i <= 15; i++)
                  {
                        scanf("%d", &data[i]);
                        if(data[i] == 0)
                        {
                                   len = i;
                                   break;
                        }
                  }

                  for(i = 0; i <= len - 1; i++)
                        for(j = 0 ; j <= len - 1; j++)
                              count = count + (data[i] == 2 * data[j]);

                  printf("%d\n", count);
    }

    return 0;
}


int main(void)
{
	int i,j,m,n;
	int num[100], result[100], temp;

	i=0;
	j=0;
	while(1)
	{
		cin >> num[i];
		if(num[i] == -1)
		{
			break;
		}

		while(1)
		{
			if(num[i] == 0)
			{
				temp = 0;
				for(m=0; m<i; m++)
				{
					for(n=0; n<i; n++)
					{
						if(num[m] == 2*num[n])
						{
							temp++;
						}
					}
				}
				result[j] = temp;

				i=0;
				j++;
				break;
			}
			else
			{
				i++;
				cin >> num[i];
			}
		}
	}

	for(m=0; m<j; m++)
	{
		cout << result[m] << endl;
	}
	return 0;
}


int a[16]={0};
int main()
{
  while(cin>>a[0])
  {
	  if(a[0]==(-1)) break;
     int i,j,k,countnumber=0,countpair=0;
	  for(i=1;i<=15;i++)
	 { cin>>a[i];
	 if(a[i]==0) break;}
	 countnumber=i+1;
	 for(i=0;i<countnumber-1;i++)
		 for(j=i+1;j<countnumber;j++)
		 { if((a[i]==2*a[j])||(a[j]==2*a[i])) countpair++;
	 }
	 cout<<countpair<<endl;
  }
	 return 0;

}


/*
 * ??.cpp
 *
 *  Created on: 2011-11-2
 *      Author:Administrator
 */

int main(){
    int a[16],i,n,j,total;
    while(cin>>a[0]&&a[0]!=-1){
    	i=1;
    	while(cin>>a[i]&&a[i]!=0){
    		i++;
    	}
    	n=i;
    	total=0;
    	for(i=0;i<n;i++)
    		for(j=0;j<n;j++){
    			if(a[j]==2*a[i])total++;
    		}
    	cout<<total<<endl;
    	}
    return 0;
}


int main()
{
	int a[20],i,j,k,count;
	while(cin>>a[0])
	{
		if(a[ 0 ]==-1)
			break;
		count=0;
		for(i=1;;i++)
		{
			cin>>a[i];
			if(a[i]==0) break;
		}
		for(j=0;j<i;j++)
		{
			for(k=0;k<i;k++)
			{
				if(a[k]==2*a[j])
				{
					count+=1;
				}
			}
		}
		cout<<count<<endl;
	}
	return 0;
}


void main(){
	int i,j,l,t,m,count[50],lie[20];
	char p;
	for(i=0;i<50;i++){
for(j=0;j<20;j++){
scanf("%d",&lie[j]);
if(lie[0]==-1) goto lalala;
scanf("%c",&p);
if (p=='\n') break;
}
count[i]=0;
for(l=0;l<j;l++)
for(t=0;t<j;t++)
if((lie[l]-2*lie[t])==0)
count[i]=count[i]+1;
}
lalala:for(m=0;m<i;m++){
printf("%d",count[m]);
if(m!=i-1)
printf("\n");
}
}


int main()
{
	int number[16]={0};
	int m,i=1;
	while(m!=-1)
	{
		do
		{
			cin>>m;
			number[i]=m;
			i++;
		}while(m!=0&&m!=-1);
		int k=1,t,j=0;
		for(k=1;k<=i-1;k++)
		{
			t=number[k];
			int p;
			for(p=1;p<=i-1;p++)
			{
				if(t==2*number[p])
				{
					j++;
				}
				else continue;
			}
		}
	if(m!=-1)
	{
		cout<<j-1<<endl;
	}
	else break;
	i=1;
	j=0;
	}
	return 0;
}


void swap( int* a,int *b )
{
    int temp = *a;*a = *b; *b = temp;
}

int find( int* s, int x, int l, int r )
{
    if ( l > r ) return 0;
    int mid = (l+r)/2;
    if ( s[mid] == x ) return 1;
    else
    {
        if ( s[mid] > x ) return find(s,x,l,mid-1);
        else return find(s,x,mid+1,r);
    }
}

int main()
{
    int n = 0, i = 0, j = 0;
    int x = 0;
    int s[1000] = {0};
    while ( (scanf("%d", &x), x) != -1 )
    {
        if ( x != 0 )
        {
            s[n++] = x;
            for ( i = n-1; (i>0) && (s[i] < s[i-1]); i-- )
                swap(&s[i],&s[i-1]);
        }
        else
        {
            int count = 0;
            for ( i = 0; i < n; i++ )
            {
                if ( find(s,2*s[i], i+1, n) )
                    count++;
            }
            printf("%d\n",count);
            for ( i = 0; i < n; i++ )
                s[i] = 0;
            n = 0;
        }
    }
    return 0;
}


int main()
{
	int number[16];
	int n;
	for( ; ; )
	{
		n = 0;
		cin >> number[0];
		if( number[0] == -1 ) break;
		int i;
		for( i = 1; i < 16; i++ )
		{
			cin >> number[i];
			if( number[i] == 0 ) break;
		}
		for( int j = 0; j < i; j++ )
		{
			for( int k = 0; k < i; k++)
			{
				if( number[k] == 2 * number[j] )
				{
					n++;

				}
			}
		}
		cout << n << endl;
	}

	return 0;
}


int main(int argc, char* argv[])
{
	int num[15];
	int i,m;
	for(i=0;i<15;i++)
	{scanf("%d",&num[i]);
	{if(num[i]==0)
	break;}
    i++;
	}
	int j=0;
	int a;
    m=i;
    i=a=0;
	for(i=0;i<m;i++)
	{
		for(j=0;j<m;j++)
		{if(num[i]/num[j]==2&&num[i]%num[j]==0)
		a++;}
	}
	printf("%d\n",a);
	return 0;
}


int main()
{
	int a[15], b, n = 0, num = 0;
	while (cin >> b)
	{
		if (b == -1)
		break;
		else if (b == 0)
		{
			for (int i=0;i<n;i++)
			for (int j=i;j<n;j++)
			if (a[i] == 2 * a[j] || a[j] == 2 * a[i])
			num++;
			n = 0;
			cout << num << endl;
			num = 0;
		}
		else
		{
			a[n] = b;
			n++;
		}
	}
	return 0;
}


int main()
{
	int i, j, n, x[15], count;
	while (1)
	{
		count = 0;
		for (n = 0; ; n++)
		{
			cin >> x[n];
			if (x[n] <= 0) break;
		}
		if (x[n] == -1) break;
		for (i = 0; i < n; i++)
			for(j = 0; j < n; j++)
			{
				if (j == i) continue;
				if (x[j] == 2 * x[i]) count++;
			};
		cout << count << endl;
	}
	return 0;
}


/*
 * bla.cpp
 *
 *  Created on: 2012-11-4
 *      Author: Administrator
 */

int main()
{
	int m;
	while(cin>>m)
	{
		if(m==-1) break;
		int a[15],i=0,j,k,count=0;
		a[0]=m;
		while(cin>>m)
		{
			if(m==0) break;
			i++;
			a[i]=m;
		}
		k=i+1;
		for(i=0;i<k;i++)
			for(j=0;j<k;j++)
				if(a[i]==2*a[j])
					count++;
		cout<<count<<endl;
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int shu[number];
	int n,i,j;
	int k=0;
    scanf("%d",&shu[0]);
	for(n=0;shu[n]!=0;n++){
	scanf("%d",&shu[n+1]);
	}
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			if(shu[i]==2*shu[j]){
			k++;
			}
		}
	}
	if(k!=0){
		k=k-1;
	printf("%d",k);
	}
	else printf("%d",k);
	return 0;
}


int main(int argc, char* argv[])
{
	int s[16]={0};
	while(1){
		int i,j,count=0,flag=0;
		for(i=0;;i++){
			scanf("%d",&s[i]);
			if(s[i]==-1)
			{
				flag=1;
				break;
			}
			if(s[i]==0)
				break;
			count++;
		}
		if(flag)
			break;
		int num=0;

		for(i=0;i<count;i++){
			for(j=i;j<count;j++){
				if(s[i]==s[j]*2||s[j]==s[i]*2)
					num++;
			}
		}
		printf("%d\n",num);
	}
	return 0;
}


int main ( )
{
	int num[16],i,j,count,a,n;
	while(1)
	{
		count=0;n=0;
		for(i=0;;i++)
		{
			scanf("%d",&num[i]);
			if(num[i]==-1)
				break;
			if(num[i]==0)
				break;
			n+=1;
		}
		if(num[0]==-1)
			break;
		else
		{
			for(i=0;i<n;i++)
			{
				a=num[i];
				for(j=0;j<n;j++)
					if(num[j]==2*a)
						count+=1;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}


int main(int argc, char* argv[])
{
int a[100],i,j,num=0,total=0;
while(1){
	num=0;
while(1){
scanf("%d",&a[num]);
if(a[num]==0) break;
if(a[num]==-1) return 0;
num++;}

total=0;
for(i=0;i<num;i++){

for(j=0;j<num;j++){
if(a[j]==2*a[i]) total++;}}
printf("%d\n",total);}
	return 0;
}


int main()
{
	int str[20],doubl,num=0,a,b,c;
	while(1)
	{
		num=0;
		scanf("%d",&str[0]);
		if(str[0]==-1)
			break;
		else
			for(a=1;str[a-1]!=0;a++)
			{
				scanf("%d",&str[a]);
			}
			for(b=0;b<a-1;b++)
			{
				doubl=2*str[b];
				for(c=0;c<a-1;c++)
				{
					if(str[c]==doubl)
						num++;
					else
						num=num;
					}
				}
				printf("%d\n",num);
			}
			return 1;
	}


int main(int argc, char* argv[])
{
        int n,i,k,d,total;
		total=0;
        int shuzu[16];
        for(i=0;i<16;i++){
        scanf("%d",&n);
		if(n!=-1){
        shuzu[i]=n;
		if(n==0){
		for(d=0;d<i;d++){
		for(k=0;k<i;k++){
			if(shuzu[d]==2*shuzu[k]){
				total++;}}}
			printf("%d\n",total);
		i=-1;
		total=0;}
         }
		else{
			break;}}

        return 0;
}


int main()
{
    int test[100][17]={0};

    int i,j,k,num;
    int turn=0,nonzero=0,valid=0;

    for(i=0;;i++){
                 for(j=0;;j++){
                               scanf("%d",&num);
                               if(num==0)
                                         break;
                               if(num == -1)
                                          goto start;
                               test[i][j]=num;
                               }
                               turn+=1;
                 }
    start: for(i=0;i<turn;i++){
                               for(j=0;;j++){
                                             if(test[i][j] != 0)
                                                           nonzero+=1;
                                             else
                                                 break;
                                             }
                               for(j=0;j<nonzero;j++){
                                                     for(k=0;k<nonzero;k++){
                                                         if((float)(test[i][j])/(float)(test[i][k]) == 2)
                                                            valid+=1;
                                                         }
                                                         }
                               printf("%d\n",valid);
                               valid=0;
                               nonzero=0;
                               }

       return 0;
}


int num[15][20]={0};

int main()
{
	int i,j,k;
	int div(int);

	for(i=0,j=0;;)
	{
		scanf("%d",&num[i][j]);
		if(num[i][j]==-1) break;
		if(num[i][j]==0)
		{
			j=0;
			i++;
			continue;
		}
		j++;
	}

	for(k=0;k<i;k++)
		printf("%d\n",div(k));
	return 0;
}

int div(int n)
{
	int i,j,k=0;

	for(i=0;num[n][i];i++)
		for(j=i;num[n][j];j++)
			if(num[n][i]==2*num[n][j] || num[n][j]==2*num[n][i])
			{
				k++;
			}
	return k;
}


int main()
{
    int output = 0, i, j, length;
    float data[16];

    data[0] = -2;

    while(data[0] != -1)
    {
                  for(i = 0; i <= 15; i++)
                  {
                        scanf("%f", &data[i]);
                        if(data[i] == 0)
                        {
                                   length = i;
                                   break;
                        }
                        if(data[i] == -1)
                                   break;
                  }

                  if(data[i] == -1)
                             break;

                  for(i = 0; i <= length - 1; i++)
                        for(j = 0; j <= length - 1; j++)
                        {
                              if((data[j] / data[i]) == 2)
                                      output = output + 1;
                        }

                  printf("%d\n", output);
                  output = 0;

    }

    return 0;
}


int array[16]={0},n=0,sum=0;
int main()
{
    int i,j;
    while(1)
    {
            n=0;
            sum=0;
            while(1)
            {
                    cin>>array[n];
                    if(array[n]==0 || array[n]==-1)
                    {
                      n--;
                      break;
                    }
                    n++;
            }
            if(array[0]==-1)
             break;
            for(i=0;i<=n;++i)
            {
             for(j=i;j<=n;++j)
              {
                      if((array[i]==array[j]*2) || (array[j]==array[i]*2))
                            {
                             sum++;
                            }
                    }
            }
            cout<<sum<<endl;
    }

    return 0;
}


int main()
{
	int a[15], count = 0;
	int i, j, k;
	for (i = 0; ; i++)
	{
		cin >> a[i];
		if (a[0] == -1)
			break;
		else if (a[i] == 0)
		{
			for (j = 0; j < i; j++)
				for (k = 0; k < i; k++)
				{
					if (a[k] == a[j] * 2)
						count++;
				}
				cout << count << endl;
				count = 0;
				i = -1;
		}
	}

	return 0;
}


int main()
{
	int a[16];
	int i, j, count = 0;
	while(true)
	{
		cin >> a[0];
		if(a[0] == -1)
			break;
		i = 1;
		while(true)
		{
			cin >> a[i];
			if (a[i] == 0)
				break;
			i ++;
		}

		count = 0;
		for(i = 0; a[i] != 0; i ++)
		{
			for(j = 0; a[j] != 0; j ++)
			{
				if (a[i] * 2 == a[j])
					count ++;
			}
		}

		cout << count << endl;
	}

	return 0;
}


int main()
{
	int num[17], n, count = 1, result = 0;
	while ((cin >> n) && (n != -1))
	{
		if (n)
		{
			num[count] = n;
			count++;
		}
		else
		{
			for (int i = 1; i < count; i++)
			{
				for (int j = 1; j < count; j++)
				{
					if (num[i] == 2 * num[j])
						result++;
				}
			}
			cout << result << endl;
			result = 0;
			count = 1;
		}
	}

	return 0;
}


int main(int argc, char *argv[])
{
   int a[1000],n,b[15],m,i,j,z,num=0;
   memset(a,0,1000*sizeof(int));
   memset(b,0,15*sizeof(int));
 while(1){
             i=0;
 do{

 scanf("%d",&m);
 if(m==0)
  break;
  if(m==-1)
  break;
 b[i]=m;
 i++;

 }while(1);
 if(m==-1)
 break;

 for(j=0;j<i;j++){
  for(z=0;z<i;z++){
   if(b[j]*2==b[z])
    a[num]++;
  }
 }
 num++;

 }
 for(j=0;j<num;j++)
  printf("%d\n",a[j]);

  return 0;
}


int mat[300];

int main()
{
	int n,sum=0;
	while(scanf("%d",&n),n!=-1)
	{
		if(n)
		{
			mat[n]=1;
			if(mat[n<<1])
				sum++;
			if(!(n&1)&&mat[n>>1])
				sum++;
		}
		else
		{
			printf("%d\n",sum);
			sum=0;
			memset(mat,0,sizeof(mat));
		}
	}
}


int main(int argc, char* argv[])
{
	int sz[15];
	int a,i,k,count=0;
	for(i=0;i<15;i++)
	{
		scanf("%d",&a);
		if(a==-1)break;
		else if(a==0)
		{   i=-1;
			printf("%d\n",count);
			count=0;
			continue;
		}
		else sz[i]=a;
	    for(k=0;k<=i;k++)
		{
			if(sz[i]==sz[k]*2||sz[k]==sz[i]*2)count++;
		}
	}
	return 0;
}


//??.c

int main(){
    int data;
    int a[15];
    int i=0;
    int j,k;
    while(scanf("%d",&data)!=EOF){
        if(data==-1) break;
        else{
            if(data!=0){
                a[i] = data;
                i++;
            }
            else{
                int tmp;
                for(j=0;j<i;j++){
                    for(k=j+1;k<i;k++){
                        if(a[j]>a[k]){
                            tmp=a[k];
                            a[k]=a[j];
                            a[j]=tmp;
                        };
                    }
                }//??
                int cnt=0;
                for(j=0;j<i;j++){
                    for(k=j+1;k<i;k++){
                        if(a[j]*2==a[k]){
                            cnt++;
                            break;
                        }
                        if(a[j]*2<a[k]) break;
                    }
                }
                printf("%d\n",cnt);
                cnt=0;
                i=0;
            }
        }
    }
    return 0;
}


int find(int *x,int y,int z)
{
 int count=0;
 for(int i=0;i<y;i++)
 {if(x[i]==z) count++;}
 return count;
}

int count(int *x,int y)
{
  int count1=0;
  for(int i=0;i<y;i++)
  {count1+=find(x,y,2*x[i]);}
  return count1;
}

int main()
{
 int temp[16];
 int len=0;
 scanf("%d",&temp[len]);
 while(temp[len]!=-1)
 {
  while(temp[len]!=0)
  {len++;
  scanf("%d",&temp[len]);
    }
  printf("%d\n",count(temp,len));
  scanf("%d",&temp[0]);
  len=0;
 }
 return 0;
}


int main()
{
	int n,i,j,num,count=0,array[15];
	while(cin>>n&&n!=-1)
	{
		memset(array,0,sizeof(array));
		array[0]=n;
		i=1;num=1;
		while(cin>>n&&n!=0)
		{
			array[i++]=n;
			num++;
		}
		sort(array,array+num);
		for(i=num-1;i>0;i--)
			for(j=i-1;j>=0;j--)
			{
				if(array[i]==2*array[j])
					count++;
			}
		cout<<count<<endl;
		count=0;
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int i, num;
	int sz[100] = {0};
	int j,k;
	int geshu=-1;
	while(1)
	{
		i = 0;
		scanf("%d",&num);
		if ( num == -1 )
			break;
		sz[0] = num;
		while(1)
		{
			if ( sz[i] == 0 )
				break;
			i++;
			scanf("%d",&sz[i]);
		}
		for(k=0;k<=i;k++){
			for(j=0;j<=i;j++){
				if(sz[j]==2*sz[k]){
					geshu=geshu+1;
				}
			}
		}
		printf("%d\n",geshu);
		geshu=-1;
	}
	return 0;
}


int main()
{
	int n;
	int num[100];
	int test,count=0;

	cin >> n;
	while(n != -1)
	{
		num[0] = n;
		for (int i = 1; n != 0; i++)
		{
			cin >> n;
			num[i] = n;
		}
		for (int j = 0; num[j] != 0; j++)
		{
			test = num[j];
			for (int k = 0; num[k] != 0; k++)
			{
				if (num[k] == 2 * test)
				{
					count++;
				}
			}//end for k
		}//end for j
		cout << count << endl;
		count=0;
		cin >> n;
	}

	return 0;
}


int main(int argc, char *argv[])
{
    int i,j,k;     int nowi;    int output;
    int part[20][16];   static int jcount[20], group[20];
    for(i=0; i<20; i++)
    {
        for(j=0; j<16; j++)
        {
           cin >> part[i][j];
           jcount[i]++;
           if(part[i][j]<=0)
           break;
        }
        if(part[i][j]== -1)
           break;
    }
    nowi=i;
    for(i=0; i<nowi; i++)
    {
       for(j=0;j<jcount[i]-1; j++)
       {
          for(k=0; k<jcount[i]-1; k++)
          {
             if( (part[i][j]/part[i][k] ==2) && (part[i][j]%part[i][k] ==0) )
             group[i]++;
          }
       }
    }

    for(output=0; output< nowi; output++)
    cout << group[output]<< endl;

    return EXIT_SUCCESS;
}


int main()
{
  int N, I, J, Count, Arr[15];
  while (1)
  {
    N = 0;
    while (1)
    {
      cin >> Arr[N];
      if (Arr[N] == -1) return 0;
      if (Arr[N] == 0) break;
      N ++;
    }
    Count = 0;
    for (I = 0; I < N - 1 ; I ++)
      for (J = I + 1; J < N; J ++)
	if (Arr[I] == 2 * Arr[J] || Arr[J] == 2 * Arr[I])
	  Count ++;
    cout << Count << endl;
  }
  return 0;
}


int main()
{	int shuzu[16];
	int  i,t,k,num=0;

	for(i=0;;i++){
		scanf("%d",&shuzu[i]);
		if(shuzu[i]==-1){
			break;
		}
		if(shuzu[i]==0){

			for(t=0;t<i;t++){
				for(k=t+1;k<i;k++){
					if(shuzu[t]==shuzu[k]*2||shuzu[t]*2==shuzu[k]){
						num++;
					}

				}
			}
			printf("%d\n",num);
			num=0;
			i=-1;
		}

	}

	return 0;
}


 int main()
 {
	 int i,j,a[16],b[100],changdu=0,panduan=1,geshu=0;
	 while(1){
		 for(i=0;i<16;i++){
			 scanf("%d",&a[i]);
			 changdu=i;
			 if(a[i]==-1){
				 panduan=0;
				 break;
			 }
			 if(a[i]==0){
				 break;
			 }
		 }

		 if(panduan==0)
			 break;

		 geshu=0;

		 for(i=0;i<changdu;i++){
			 for(j=0;j<changdu;j++){
				 if(a[i]==a[j]*2){
					 geshu++;
				 }
			 }
		 }

		 printf("%d\n",geshu);
	 }

   return 0;
}


int main()
{
	double a[15] , num , cnt   ;
	int i;
	for(int n = 0 ; n <= 99999 ; n++)
	{
		cnt = 0;
		for( i = 0 ; i <= 15 ; i++)
		{
			cin >> num;
			if(num == 0)break;
			else
				a[i] = num;
		}
		if(a[0] == -1)break;
		else
		{
			for(int j = 0 ; j <= i - 1 ; j++)
				for(int k = 0 ; k <= i - 1 ; k++)
					if(a[j] == 2 * a[k])
						cnt++;
		}
		cout << cnt << endl;

	}
	return 0;
}


int main()
{
	int shuru[20] = {0};

	while (true)
	{
		int i = 1 , j , k , s , no;
		s=0;
		cin>>shuru[0];
		if(shuru[0]==-1)
			break;

		for(i=1;i<=15;i++)
		{
			cin>>shuru[i];
			if(shuru[i]==0)
				break;
			for(j=0;j<i;j++)
				if((shuru[j]==2*shuru[i])||(2*shuru[j]==shuru[i]))
					s++;
		}
		//cout << "yes  " << shuru[0] << endl;
		cout<<s<<endl;
		for(i=0;i<=14;i++)
		shuru[i]=0;
	}
	return 0;
}


int main()
{
	int row,col;
	int a,b;
	int sz[100][100];
	int sum[100];

	for(row=0;row<100;row++)
	{
		sum[row]=0;
	}

	for(row=0;row<100;row++)
	{
		for(col=0;col<100;col++)
		{
			scanf("%d",&sz[row][col]);
			if(sz[row][col]==0)
			{
				break;
			}
			if(sz[row][0]==-1)
			{
				break;
			}
		}
		if(sz[row][0]==-1)
		{
			break;
		}
		a=row;
	}

	for(row=0;row<=a;row++)
	{
		for(b=0;b<100;b++)
		{
			for(col=0;col<100;col++)
			{
				if(sz[row][b]==2*sz[row][col]&&sz[row][b]!=0&&sz[row][col]!=0)
				{
					sum[row]++;
				}
			}
		}
	}

	for(row=0;row<=a;row++)
	{
		printf("%d\n",sum[row]);
	}

	return 0;
}


int main(int argc, char* argv[])
{
	int shuzu[16]={0},i,j,pair=0,n;
		for(i=0;shuzu[0]!=-1;i++)
		{
			scanf("%d",&shuzu[i]);
			if(shuzu[i]==0)
			{
				n=i;
				for(i=0;i<n;i++)
				{
					for(j=0;j<n;j++)
					{
						if(shuzu[i]==2*shuzu[j])
							pair++;
					}
				}
				printf("%d\n",pair);
				i=-1;
				pair=0;
			}
		}
	return 0;
}


int main()
{
	int t,i,j,k,count;
	int group[15];
	scanf("%d",&t);
	do
	{
		i=0;
		do
		{
			group[i]=t;
			scanf("%d",&t);
			i++;
		}
		while(t!=0);
		printf("\n");
        	    count=0;
		for(j=i-1;j>=0;j--)
		{
		   for(k=0;k<i;k++)
		   {
		      if((double)group[k]/2==group[j])//double
			  {
		      count++;
			  }
			  else if((double)group[j]/2==group[k])//!=int!!!!!!!
			  {
		      count++;
              			  }
		   }
		}
	    printf("%d\n",count/2);
		scanf("%d",&t);

	}
	while(t!=-1);
	return 0;
}


int main(int argc, char* argv[])
{
	int s[16]={0};
	while(1){
		int i,j,count=0,flag=0;
		for(i=0;;i++){
			scanf("%d",&s[i]);
			if(s[i]==-1)
			{
				flag=1;
				break;
			}
			if(s[i]==0)
				break;
			count++;
		}
		if(flag)
			break;
		int num=0;

		for(i=0;i<count;i++){
			for(j=0;j<count;j++){
				if(s[i]==s[j]*2)
					num++;
			}
		}
		printf("%d\n",num);
	}
	return 0;
}


int main()
{
	int num[100]={0},index=0,sum=0;
	char c;
for(;num[0]!=-1;)
{while(true)
	{
		scanf("%d",&num[index++]);
		scanf("%c",&c);
		if(c=='\n')
			break;
	}
for(int i=0;i<index;i++)
{
	for(int j=0;j<index;j++)
	{
		if(num[i]==(2*num[j])||(2*num[i])==num[j])
		{
			sum++;
		}
	}
}
if(num[0]==-1)
{return 0;}
else
printf("%d\n",(sum-1)/2);
sum=0;index=0;
}
return 0;
}


int main()
{
	int a[16], j, k, sum;
	while(true)
	{
		cin >> a[0];
		if(a[0] != -1)
		{
			int i;
			for(i = 1 ; ; i++)
			{
				cin >> a[i];
				if(a[i] == 0)
					break;
			}
			sum = 0;
			for (j = 0; j < i; j++)
			{
				for (k = j + 1; k < i ; k++)
							if (a[j] == 2 * a[k] || a[k] == a[j] * 2)
								sum = sum + 1;
			}
							cout << sum << endl;
		}
		else
			break;
	}
	return 0;
}


int main()
{
	int a[20];
	int flag;

	cin >> flag;

	while(flag != -1)
	{
		a[0] = flag;
		int i = 0;
		int count = 0;

		while(a[i] != 0)
		{
			i ++;
			cin >> a[i];
		}

		for(int j = 0; j < i; j ++)
		{
			for(int k = 0; k < i; k ++)
			{
				if(a[j] == 2 * a[k])
				count ++;
			}
		}

		cout << count << endl;

		cin >> flag;
	}

	return 0;
}


int a[16], n=0;
int do_LB(){
    int i, j, c=0;
    for(i=0; i<n; ++i)
        for(j=i+1; j<n; ++j)
            if(a[i]==a[j]+a[j] || a[j]==a[i]+a[i]) c++;
    n=0;
    return c;
}
int main(){
    int cin;
    do{
        scanf("%d", &cin);
        if(cin == -1) return;
        if(cin == 0) printf("%d\n", do_LB());
        a[n++] = cin;
    }while(1);

}


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

}
int chuli(int * p,int i)
{

	int count=0;

	for(int q=0;q<i;q++)
	{
		if(2*(p[q])>p[i-1])return count;

		for(int j=q;j<i;j++)
		{

			if(p[j]==2*(p[q])){count++; break;}
			if(p[j]>2*(p[q])){break;}
		}
	}

	return count;
}
int main()
{
	//freopen("in.txt","r",stdin);
	int a[20];
	int num;
	while(cin>>a[0]&&(a[0]!=-1))
	{
		int i=1;
		while(cin>>a[i]&&a[i])
		{
			i++;
		}

		qsort(a,i,sizeof(int),cmp);

		num=chuli(a,i);
		cout<<num<<endl;
	}
	return 0;
}


int num[16];

int Compare(const void* elem1,const void* elem2)
{
    return *((int*)elem1) - *((int*)elem2);
}

int main()
{
    int n;
    while (cin>>n&&n!=-1)
    {
        memset(num,0,sizeof num);
        num[0] = n;
        int count = 0;
        int i = 1;
        for (;cin>>n&&n!=0;i++)
            num[i] = n;
        qsort(num,i,sizeof(int),Compare);

        for (int j =0;j<i-1;j++)
        {
            int temp = num[j];
            for (int k=j+1;k<i;k++)
            {
                if (num[k]==temp*2)
                {
                    count++;
                    break;
                }
            }
        }

        cout<<count<<endl;
    }

    return 0;
}


void initarray ( int a[] ,int b , int length ); // ?????
void base ( int a[maxlen] ); // ??
int twice ( int a[maxlen]  ); // ????
int main ( void ) // ???
{
	int a[maxlen];
	int t[maxlen];
	int i,j,k,l;
	i = 0;
	for ( i = 0 ; i < maxlen ; i ++ )
	{
		a[i] = -2;
	}
	i = 0;
	k = -2;
	while( a[i] != -1 )
	{
		while ( k != 0 )
		{
			cin>>k;
			a[i] = k ;
			i ++ ;
		}
		base ( a );
		j = twice ( a );
		cout<<j<<endl;
		initarray ( a , -2 ,maxlen);
		i = 0 ;
		k = -2 ;
	}
	return 1;
}

void initarray (int a[] ,int b , int length)
{
	int i;
	for ( i = 0 ; i < length ; i++)
	{
		a[i] = b;
	}
}

void base ( int a[maxlen] )
{
	int b[maxinputint+1];
	int i,j;
	initarray(b,0,maxinputint);
	for ( i = 0 ; i<maxlen; i ++ )
	{
		if ( a[i] > 0 )
		{
			b[a[i]]++;
		}
	}
	j = 0;
	for ( i = 0 ; i<= maxinputint; i ++ )
	{
		if ( b[i] == 1 )
		{
			a[j] = i;
			j++ ;
		}
	}
}

int twice ( int a[maxlen] )
{
	int i,j,t,result;

	i = 0;
	j = 0;
	t = 0;
	result = 0;
	while ( ( a[i] <= 50 ) && ( a[j] > 0 ))
	{
		t = a[i] * 2;
		j = i ;
		while ( (a[j] <= t) && ( a[j] > 0 ) )
		{
			if ( a[j] == t )
			{
				result ++ ;
			};
			j++ ;
		}
		j = 0;
		i ++ ;
	}
	return result;
}


int main()
{
	int x[20],r,ctr,t,i,j;
	while(cin.peek()!='-')
	{
		r=ctr=0;
		while(cin>>t,t)
			x[++r]=t;
		cin.get();
		for(i=1;i<=r;i++)
		{
			for(j=1;j<=r;j++)
			{
				if(x[i]==(x[j]<<1))
					ctr++;
			}
		}
		cout<<ctr<<endl;
	}
	return 0;
}


int main( )
{
	int n,i,j,k,a[20000],counter=0;
	cin>>n;
	for (i=0;i<n;i++)
	{
		cin>>a[i];
		for (j=0;j<i;j++)
			if (a[i]==a[j]) break;
		if(i==j) counter++;
	}
	for (i=0;i<n;i++)
	{
		for (j=0;j<i;j++)
			if (a[i]==a[j]) break;
		if(i==j)
		{cout<<a[i];
		counter--;
		if(counter!=0) cout<<' ';
		}
	}
	return 0;
}


int main()
{int k,i,j,l=0,excit=0;
 scanf("%d",&k);
 int num[k],shulie[k];

 for (i=1;i<=k;i++)
 { scanf("%d",&num[i-1]);
   for (j=0;j<=i-2;j++)
	   if (num[j]==num[i-1])
	   {
		   excit=1;
	      break;
	   }
	if (excit==0)
	{shulie[l]=num[i-1];
	 l=l+1;
	}
	else excit=0;
 }
 printf("%d",shulie[0]);
 for (i=2;i<=l;i++)
		 printf(" %d",shulie[i-1]);
 }


int main() {
    int n, i, j, sign,counter;
    int a[20000];
    scanf("%d", &n);
    for (i=0;i<n;i++) {
        scanf("%d", &a[i]);
    }
    counter=0;
    for (i=0;i<n&&counter==0;i++) {
        sign=0;
        for (j=0;j<i;j++) {
            if (a[j]==a[i]) {
                sign=sign+1;
            }
        }
        if (sign==0) {
            printf("%d", a[i]);
            counter=counter+1;
        }
    }
    for (;i<n;i++) {
        sign=0;
        for (j=0;j<i;j++) {
            if (a[j]==a[i]) {
                sign=sign+1;
            }
        }
        if (sign==0) {
            printf(" %d", a[i]);
        }
    }

    return 0;
}


int a[101];
int main()
{
  int q=0,temp,n,i,flag=0,t[200];
  memset(a,0,sizeof(a));
  	scanf("%d",&n);
  	for(i=0;i<n;i++)
  	{
	  scanf("%d",&temp);
	  if(a[temp]==0)
	  t[q++]=temp;
	  a[temp]++;
    }
    for(i=0;i<q;i++)
    {
    	if(flag==0) flag=1;
    	else printf(" ");
    	printf("%d",t[i]);
    }
}


int main(){
    int n;
    scanf("%d",&n);
    int *SZ=(int*)malloc(sizeof(int)*n);
    for(int i=0;i<n;i++){
        scanf("%d",&SZ[i]);
        }
    for(int j=0;j<n;j++){
        if(j==0){
           printf("%d",SZ[j]);
           }
        for(int k=0;k<j;k++){
            if(SZ[j]==SZ[k]){
               break;
               }else if(k==j-1){
                printf(" %d",SZ[j]);
               }
            }
        }
    return 0;
}


int main()
{
	int n, i, num, count[100] = {0};
	cin >> n ;
	for ( i = 1; i <= n; i++)
	{

		cin >> num;
		count[num]++;
		if (i == 1) cout << num;
		if (count[num] == 1 && i >= 2)  cout <<" " <<num;

	}

	return 0;
}


int main()
{
    int n,i;
    cin>>n;
    if(n==0);
    else
    {int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    cout<<a[0];
    for(i=1;i<n;i++)
    {int k=0,j;
    for(j=0;j<i;j++)
      if(a[i]==a[j])
      k++;
      if(k==0)
      cout<<' '<<a[i];
    } }
    cin.get();cin.get();cin.get();
    return 0;
}


int main() {
    long n;
    cin >> n;
    bitset<101> b;
    for (long i = 0; i < n; i++) {
        long x;
        cin >> x;
        if (!b.test(x)) {
            if (i) cout << ' ';
            cout << x;
            b.set(x);
        }
    }
    return 0;
}


int main()
{
	int count,n,j,i=1;
	int a[20000];
	scanf("%d",&n);
	for(i;i<=n;i++)
	{
		scanf("%d",&a[i]);
		for(count=0,j=1;j<i;j++)
		{
			if(a[i]==a[j])
				count++;
		}
		if(i==1&&count==0)
			printf("%d",a[i]);
		else if(i!=1&&count==0)
			printf(" %d",a[i]);
	}
	return 0;
}


int main()
{
	int n,i,j,a[20001];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		for(j=0;j<i;j++)
		{
			if(a[i]==a[j])
	         break;
			else
		    continue;

		}
		if(j==i)
		{
			if(i==0)
			printf("%d",a[i]);
			else
             printf(" %d",a[i]);
		}
		else
			continue;
	}
}


// ????.cpp : Defines the entry point for the console application.
//

int main(){
    int n,q=1,k;
	int sz[20000],jieguo[20000];
    scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&sz[i]);
	}
	jieguo[0]=sz[0];
	for(int i=1;i<=n;i++){
		k=0;
		for(int j=0;j<q;j++){
			if(jieguo[j]==sz[i]){
				break;
			}else{
				k+=1;
			}
		}
		if(k==q){
			jieguo[q]=sz[i];
			q+=1;
		}
	}
	for(int i=0;i<q-1;i++){
		if(i!=q-2){
			printf("%d ",jieguo[i]);
		}else{
			printf("%d",jieguo[i]);
		}
	}

        return 0;

}


int main()
{
	int n;
	int a[20000];
	int i, j;
	int sum;

	cin >> n;
	sum = n;
	for(i = 0; i < n; i ++)
		cin >> a[i];
	for(i = 0; i < n; i ++)
	{
		if(a[i] == 0)
			continue;
		for(j = i + 1; j < n; j ++)
		{
			if(a[j] == a[i])
			{
				a[j] = 0;
				sum --;
			}
		}
	}
	j = 0;
	for(i = 0; i < n; i ++)
	{
		if(a[i] == 0)
			continue;
		cout << a[i];
		j ++;
		if( j != sum)
			cout << ' ';
	}
	return 0;
}


int main()
{
	int a[20000],i,n,j,flag;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	printf("%d",a[0]);
	for(i=1;i<n;i++)
	{for(j=i-1;j>=0;j--)
	{if(a[i]==a[j])
	{flag=1;
	break;}
	else
	{flag=0;
	continue;}}
	if(flag==0)
		printf(" %d",a[i]);}
	return 0;
}


void main()
{
	int i,j,s,sum,num[100000]={0};
	scanf("%d",&sum);
	for(i=0;i<sum;i++)
	{
		scanf("%d",&num[i]);
	}
	for(i=0;i<sum;i++)
	{
		for(j=0;j<i;j++)
		{
			if(num[i]==num[j])
			{
				num[i]=0;
				break;
			}
		}
	}
	printf("%d",num[0]);
	for(i=1;i<sum;i++)
	{
		if(num[i]==0)
			continue;
		else printf(" %d",num[i]);
	}
}


int main()
{
	int n,i,j;
	cin>>n;
	int num[20000];
	for(i=0;i<n;i++)
	{
		cin>>num[i];
	}
	cout<<num[0];
	for(i=1;i<n;i++)
	{
		int sum=0;
		for(j=0;j<i;j++)
		{
			if(num[i]!=num[j])
			{
				continue;
			}
			else sum++;
		}
		if(sum==0) cout<<' '<<num[i];
	}
	return 0;
}


int main()
{
    int n;
    int a[9000],ans[9000];
    scanf("%d",&n);
    int i,j;
    int num=1,t=0;
    scanf("%d",&a[0]);
    ans[0]=a[0];
    printf("%d",a[0]);
    for(i=1;i<n;i++)
    {
                    scanf("%d",&a[i]);
                    int j=0;
                    while(j<num)
                    {
                                if(a[i]==ans[j])
                                {
                                                 t=1;
                                                 break;
                                }
                                j++;
                    }
                    if(t==0)
                    {
                             ans[num]=a[i];
                             printf(" %d",ans[num]);
                             num++;
                    }
                    else  t=0;
    }
    getchar();
    getchar();
    getchar();
}


int main()
{
	int n, a[20000], b[91], count = 0, i, j;
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> a[i];
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= i; j++)
		{
			if (a[i] == a[j])
				break;
		}
		if (i == j)
		{
			count++;
			b[count] = a[i];
			if(count == 90)
				break;
		}
		if (count == 90)
			break;
	}
	if (count > 1)
	{
		for (i = 1; i <= count - 1; i++)
			cout << b[i] << " ";
		cout << b[count] << endl;
	}
	else if (count == 1)
		cout << b[1] << endl;
	return 0;
}


main()
{
 int n,a[20000],j,temp;
 scanf("%d",&n);
 for(int i=1;i<=n;i++)
            {
             scanf("%d",&temp);
             if(i==1)
                       {
                        j=0;
                        printf("%d",temp);
                        a[j]=temp;
                       }
             else
                 {
                  int c=0;
                  for(int k=0;k<=j;k++)
                          {
                           if(a[k]==temp)
                           c++;
                          }
                  if(c==0)
                           {
                            printf(" %d",temp);
                            j++;
                            a[j]=temp;
                           }
                 }
            }
 getchar();
 getchar();
}


int main()
{
    int n;
    scanf("%d",&n);
    int a[100];
    int i=0;
    int x;
    scanf("%d",&x);
    printf("%d",x);
    a[i]=x;
    i++;
    for(int j=1;j<n;j++)
    {
            int h;
            int k=0;
            scanf("%d",&h);
            for(int t=0;t<i;t++)
            {
                    if(h==a[t])
                    k=1;
            }
            if(k==0)
            {
                   printf(" %d",h);
                   a[i]=h;
                   i++;
            }
    }
    getchar();
    getchar();
}


int main()
{
	int n;
	scanf("%d",&n);
	int num[20001];
	memset(num,0,20001);
	int i,j;
	int count=1;
	int number;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&number);
		if(i==1)
		{
			num[0]=number;
		}
		else
		{
			for(j=1;j<=count;j++)
			{
				if(number==num[j-1])
				{
					break;
				}
				else
				{}
				if(j==count)
				{
					count++;
					num[count-1]=number;
				}
				else
				{}
			}
		}
	}
	for(i=1;i<count;i++)
	{
		printf("%d ",num[i-1]);
	}
	printf("%d",num[count-1]);
	return 0;
}


int main()
{
    int n,i,m,save[20000],count=0;
    for(i=0;i<20000;i++)
    save[i]=0;
    cin>>n;
    while(n--)
    {
              int flag=1;
              cin>>m;
              for(i=0;i<20000;i++)
              {if(save[i]==m) {flag=0;break;}
              }
              if(flag==1)
              {
                          for(i=0;i<20000;i++)
                          {if(save[i]==0){save[i]=m;break;}}
                          count++;
                          }
                          }
                          for(i=0;i<count-1;i++)
                          cout<<save[i]<<" ";
                          cout<<save[count-1];

                          return 0;
                          }


main(){
       int input[20000],output[20000],n,i,j,outLen=1;
       scanf("%d",&n);
       for(i=0;i<n;i++){
           scanf("%d",&input[i]);
           output[outLen]=input[i];
           for(j=1;j<outLen;j++){
               if(input[i]==output[j]) outLen=outLen-1;
               /*else output[outLen]=input[i]; */

           }
           outLen=outLen+1;
       }

       for(i=1;i<outLen;i++){
           printf("%d",output[i]);
           if(i!=outLen-1) printf(" ");
       }

}


int main(){
int n,k,w[200];
cin>>n;memset(w,0,sizeof(w));
for(int i=0;i<n;i++){
cin>>k;
if(!w[k]){
if(i)cout<<' ';
w[k]=1;
cout<<k;
}
}
return 0;
}


void main()
{
	int n,i;
	int a[20005],mark[100]={0},print=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",a+i);
	for(i=0;i<n;i++){
		if(mark[a[i]]==1)continue;
		else{
			if(print)printf(" ");
			printf("%d",a[i]);
			print=1;
			mark[a[i]]++;
		}
	}
	putchar(10);
}


main()
{
      int i,j,n;
      scanf("%d",&n);
      int a[20000];
      for(i=0;i<n;i++)
      {
                      scanf("%d",&a[i]);
                      }
      printf("%d",a[0]);
      for(i=1;i<n;i++)
      {
                      int k;
                      k=0;
                      for(j=0;j<i;j++)
                      {
                                      if(a[j]!=a[i]) k++;
                                      else break;
                                      }
                                      if(k==i) printf(" %d",a[i]);
                      }
      getchar();getchar();getchar();getchar();getchar();
      }


int shuzu[20000];
int main(){
    int n,x;
    scanf("%d",&n);
    for (int t=0;t<n;t++){
        scanf("%d",&shuzu[t]);
    }
    for (int j=0;j<n;j++){
        for (int i=j+1;i<n;i++){
           if (shuzu[i]==shuzu[j]){
                     shuzu[i]=0;
                }
           }
    }
    for (int m=0;m<n;m++){
        if (shuzu[m]!=0){
            if (m==0){
            printf("%d",shuzu[m]);
            }
            else {
                   printf(" %d",shuzu[m]);
                   }
        }
    }
return 0;
}


/*
 * test.cpp
 *
 *  Created on: Nov 7, 2012
 *      Author: Sheldon
 */

int main(){
	int flag[101] = {0};
	int n, a;
	cin >> n;
	int f = 0;
	for(int i = 0; i < n; i ++){
		cin >> a;
		if(flag[a] == 0){
			flag[a] = 1;
			if(f == 0){
				cout << a;
				f = 1;
			}
			else{
				cout << " " << a;
			}
		}
	}
	return 0;
}


int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	cout<<a[0];
	for(int i=1;i<n;i++)
		for(int j=0;j<i;j++)
		{
			if(a[i]==a[j])
				a[i]=1;
		}
	for(int i=1;i<n;i++)
	{
		if(a[i]>1)
			cout<<" "<<a[i];
	}
	return 0;

}


int god(int num1,int num2);
int main(void)
{
	int number,ctr,i;
	int n[20000],c[20000];
	scanf("%d",&number);
	for(i=0;i<=20000;i++)
	{
		c[i]=0;
	}
    for(ctr=0;ctr<number;ctr++)
	{
		scanf("%d",&n[ctr]);
	}
	printf("%d",n[0]);
	for(ctr=1;ctr<number;ctr++)
	{
		for(i=0;i<ctr;i++)
		{
			if(n[i]==n[ctr])
			{
				c[ctr]++;
			}
		}
		if(c[ctr]==0)
			printf(" %d",n[ctr]);
	}

	getchar();
	return 0;
}


int main(){
	int n;
	int i;
	int d;
    int flag[101];
    for (i = 0;i <= 100; i++)
    {
        flag[i] = 0;
    }
    cin>>n;
    int couted = 0;
	for( i = 0; i < n ; i ++)
	{
		cin>>d;
		if(flag[d] == 0)
		{
			if(couted == 0)
			{
				cout<<d;
				couted = 1;
			}
			else
			{
				cout<<" "<<d;
			}
			flag[d] = 1;
		}
	}

return 0;
}


int main()
{
	int a[91];
	int i,n,number;
	cin >> n;
	memset(a,0,sizeof(a));
	cin >> number;
	a[number - 10]++;
		if ( a[number - 10] == 1)
			cout << number ;
	for (i = 1; i < n; i++)
	{
		cin >> number;
		a[number - 10]++;
		if ( a[number - 10] == 1)
			cout << " " << number ;
	}
	cout << endl;
return 0;
}


int main(){
	int n,input[20000],output[20000],i,j,k,x;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&input[i]);
	}
	k=0;
	for(i=0;i<n;i++){
		x=0;
		for(j=0;j<i;j++){
			if(input[i]==input[j]){
				x++;
                                    break;
                  }
		}
		if(x==0){
			k++;
			output[k]=input[i];
		}
	}
	for(i=1;i<k;i++){
		printf("%d ",output[i]);
	}
	if(i==k)
		printf("%d\n",output[i]);
return 0;
}


int main()
{
	int n;
	int i,j,flag;
	int a[MAX];
	scanf("%d",&n);
	a[0]=1;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=1;i<=n;i++)
	{
		flag=1;
	    for(j=i-1;j>=0;j--)
		{
			if(a[i]==a[j])
			{
				flag=0;
				break;
			}
        }
		if(flag==1)
			if(i>1)
		       printf(" %d",a[i]);
			else
				printf("%d",a[i]);
	}
	return 0;
}


int compare(int s, int a[20000], int n)
{
	int i, temp=0;
	for(i=0; i<n; i++)
	{
		if(s==a[i])
		{
			return 1;
			temp=1;
			break;
		}
		else
			continue;
	}
	if(temp=0)
		return 0;
}

int main()
{
	int n, a[20000], i, j, w=0;
	scanf("%d", &n);
	for(i=0; i<n; i++)
	{
		scanf("%d", &a[i]);
		if(compare(a[i], a, i)==1)
			a[i]=-1;
		else
			continue;
	}
	for(i=0; i<n; i++)
	{
		if(a[i]==-1)
			continue;
		else
		{
			if(w==0)
				printf("%d", a[i]);
			else
				printf(" %d", a[i]);
			w++;
		}
	}
	printf("\n");
	return 0;
}


int main()
{
    int n,a[20000];
    int count1,i,j,k;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(j=0;j<n;j++)
    {
                    count1=0;
            for(k=0;k<j;k++)
            {
               if(a[j]==a[k])
               {
               count1=1;
               break;
               }
            }
            if(count1==0)
            {
                       if(j==0)
                       printf("%d",a[0]);
                       else
                       printf(" %d",a[j]);
            }

    }
    getchar();
     getchar();
      getchar();
       getchar();
        getchar();
         getchar();
          getchar();
    return 0;
}


int main(int argc, char* argv[])
{
	int n;
	int histgram[101];
	int i;
	int x;

	scanf("%d",&n);
	for (i=0; i<101; i++)
	{
		histgram[i]=0;
	}

	scanf("%d", &x);
	histgram[x]++;
	printf("%d",x);

	for (i=0; i<n-1; i++)
	{
		scanf("%d", &x);
		if (!histgram[x])
		{
			printf(" %d",x);
		}
		histgram[x]++;
	}

	return 0;
}


/*
 * 4.cpp
 *
 *  Created on: 2011-12-30
 *      Author: Administrator
 */
int main()
{
	int a[10005], n, i, j, flag = 1,flag2 = 0;
	cin >> n;
	for( i = 1; i <= n; i++ )
	{
		flag = 1;
		cin >> a[i];
		for( j = 1; j <= i - 1; j++ )
		{
			if( a[j] == a[i])
				flag = 0;
		}
		if( flag )
		{
			if( flag2 == 0 )
			{
				cout << a[i];
				flag2 = 1;
			}
			else
				cout << " " << a[i];
		}
	}
	return 0;
}


struct arr
{
	long int num;
	struct arr *next;
};
int n;
struct arr *create(int m)                   /*  m?????   */
{
	struct arr *head;
	struct arr *p1,*p2;
	n=1;
	p1=p2=(struct arr *) malloc(LEN);
	scanf("%ld",&p1->num);                             /* ??????????*/
	head=p1;
	while(n<m)
	{
		p1=(struct arr *)malloc(LEN);
		p2->next=p1;
		n++;
		p2=p1;
		scanf("%ld",&p1->num);                         /* ??????????*/
	}
	p1->next=NULL;
	return(head);
}
void print(struct arr *head)
{
	struct arr *p;
	p=head;
	while(p!=NULL)
	{
		if(p==head)
		printf("%ld",p->num);
		else printf(" %ld",p->num);            /* ????????????? */
		p=p->next;
	}
}
void freelist(struct arr *head)
	{
		struct arr *p=head ;
		while(p!=NULL)
		{
			head=head->next;
			free(p);
			p=head;
		}
}
struct arr *del(struct arr *head,long int dnum)
{
	struct arr *p1,*p2;
	p1=p2=head;
	while(p1!=NULL&&p1->num==dnum)
		{
			head=p1->next;
			p2=head;
			free(p1);
			p1=head;
		}
	while(p1!=NULL)
	{
			p2=p1;
			p1=p1->next;
		while(p1!=NULL&&p1->num==dnum)
		{
			p2->next=p1->next;
			free(p1);
			p1=p2->next;
		}

	}
	return(head);
}

void main()
{
	int m;
	struct arr *head,*p;
	scanf("%d",&m);
	head=create(m);
	p=head;
	while(p!=NULL)
	{
		p->next=del(p->next ,p->num);
		p=p->next;
	}
	print(head);
	freelist(head);
}


int main() {

	int n;
	scanf("%d", &n);

	int visit[101] = {0};

	int i;
	for(i = 0; i < n; i++) {
		int num;
		scanf("%d", &num);
		if(visit[num] == 1) {

		} else {
			if(i != 0) {
				printf(" ");
			}
			printf("%d", num);
			visit[num] = 1;
		}
	}
	printf("\n");

	return 0;
}


int main()
{
    register int i,j,flag;
int n;
    flag=0;
    char str1[20000];
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
                     scanf("%d",&str1[i-1]);
                     if(i>=2)
                     {
                            flag=0;
                             for(j=1;j<=i-1;j++)
                             {
                                                if(str1[i-1]==str1[j-1])
                                                {
                                                                       flag=1;
                                                                       break;
                                                                       }
                                                                       }
                                                                       if(flag==0)
                                                                       {
                                                                                printf(" %d",str1[i-1]);
                                                                                }
                                                                                }
                                                                                else
                                                                                {
                                                                                printf("%d",str1[0]);
                                                                                }
                                                                                }
                                                                                return 0;
                                                                                }


int main()
{
	int n, i, j, k = 1, r = 1, number[20001], number1[20001] = {0};
	cin >> n;
	for (i = 1; i != n + 1; i++)
	{
		cin >> number[i];
		for (j = 1, k = 1; j <= i; j++)
		{
			if (number[i] == number1[j])
			{
				k = 0;
				break;
			}
		}
		if (k == 1)
		{
			if (i == 1)
			{
				cout << number[1];
				number1[1] = number[1];
				r++;
			}
			else
			{
				cout << " " << number[i];
				number1[r] = number[i];
				r++;
			}
		}
	}
	return 0;
}


int main()
{
      int n,i=1,m,j,k;
      scanf("%d",&n);
       int a[n];
      while(i<=n)
      {scanf("%d",&m);
      a[i]=m;
      i++;}
      int l=1;
      while(l<=n)
      {
                 if(l==1)
                 printf("%d",a[l]);
                 else
                 {
                     j=1;
                     k=0;
                     while(j<l)
                     {if (a[l]==a[j])
                     k=k+1;
                     j++;}
                 if(k==0)
                 printf(" %d",a[l]);
                 }
      l++;
      }
      getchar();
      getchar();
}


int main()
{
    int n,i,j,flag=0;
    int *p;
    scanf("%d",&n);
    p=(int *)malloc(sizeof(int)*n);
    scanf("%d",&p[0]);
    printf("%d",p[0]);
    for(i=1;i<=n-1;i++)
    {
         scanf("%d",&p[i]);
         for(j=0;j<i;j++)
         {
              if(p[i]==p[j])
              flag=1;
         }
         if(flag==0)
         printf(" %d",p[i]);
         flag=0;
    }
    return 0;
}


int main()
{
	int n, i;
	cin >> n;
	int num, count[100] = {0};
	cin >> num;
	count[num]++;
	cout << num;
	for(i = 2; i <= n; i++)
	{
		cin >> num;
		count[num]++;
		if(count[num] == 1)
			cout << " " << num;
	}
	return 0;
}


int main()
{
	int n,end;
	cin >> n;
	int a[n], b[n];
	memset(b, 0, sizeof(b));
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j< n; j++)
		{
			if(a[i] == a[j])
			{
				b[j] = 1;
			}
		}
	for (int i = n-1; i >= 0; i--)
	{
		if(b[i]==0)
		{
			end = i;
			b[i] = 1;
			break;
		}
	}
if(end!=0)
	{for (int i = 0; i < n; i++)
	{
		if(b[i] == 0)
		cout << a[i] << " " ;
	}}
	cout << a[end] << endl;
	return 0;

}


int main()
{
    int n;
    int a[N];
    int i,j;

    scanf("%d",&n);

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

    for(i=0;i<n;i++)
    {
        if(i==0)
        {
            printf("%d",a[i]);
        }

        else
        {
            for(j=0;j<i;j++)
            {
                if(a[j]==a[i])
                {
                    break;
                }
            }
            if(j==i)
            {
                printf(" %d",a[i]);
            }
            else if(j<i)
            {
                continue;
            }
        }
    }

    return 0;
}


int main(){
	int n,on=0;
	cin>>n;
	int input_array[n],output_array[100],otn_array[n];
	memset(output_array,0,sizeof(output_array));
	for(int i=0;i<n;i++) cin>>input_array[i];
	for(int i=0;i<n;i++){
		int otn=input_array[i];
		if(!output_array[otn-1]){
			output_array[otn-1]=1;
			otn_array[on]=otn;
			on++;
		}
	}
	for(int i=0;i<on;i++){
		cout<<otn_array[i];
		if(i!=on-1) cout<<' ';
	}
	return 0;
}


int main()
{
	int n,i,j;
	scanf("%d",&n);
	int *shuzu=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
	{
	  scanf("%d",&shuzu[i]);
	}
	printf("%d",shuzu[0]);
	for(i=1;i<n;i++)
	{
	  for(j=0;j<i;j++)
	  {
		  if(j<i-1)
		  {
		    if(shuzu[i]==shuzu[j])
		    {
		      break;
		    }
		  }
		  if(j==i-1)
		  {
		    if(shuzu[i]!=shuzu[j])
			{
			  printf(" %d",shuzu[i]);
			}
		  }
	  }
	}
	return 0;
}


int main()
{
	int n;
	cin >> n;
	int mark[101];
	for (int i = 0; i < 101; i++)
		mark[i] = 0;
	int num[20005];
	for (int i = 0; i < n; i++)
	{
		cin >> num[i];
	}
	cout << num[0];
	mark[num[0]] = 1;
	for (int i = 0; i < n; i++)
	{
		if (mark[num[i]] == 0)
		{
			mark[num[i]] = 1;
			cout << " " << num[i];
		}
	}
	cout << endl;
	return 0;
}


int main()
{
	int n,a[20000],i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
    for(i=0;i<n;i++)
	{for(j=i+1;j<n;j++)
	if(j==i)
		continue;
	else if(a[j]==a[i])
		a[j]=-1;

	}
	for(i=0;i<n;i++)
	{if(a[i]==-1)
	continue;
	else
		{printf("%d",a[i]);
break;}
	}
         for(j=i+1;j<n;j++)
	{if(a[j]==-1)
	continue;
	else
		printf(" %d",a[j]);
	}

	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	int *p,*q,*head;
	p=(int *)calloc(n,sizeof(int));
	head=p;
	for(p=head;p<head+n;p++)
	{
		scanf("%d",p);
	}
	p=head;
	printf("%d",*p);
	p++;
	for(;p<head+n;p++)
	{
		for(q=head;q<p;q++)
		{
			if(*q==*p)
			{
				goto chongfu;
			}
		}
		printf(" %d",*p);
		chongfu:;
	}
	return 0;
}


int main()
{
	int n,i,t;
	int flag[100];
	memset(flag, 0, sizeof(flag));
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>t;
		if (0==flag[t])
		{
			flag[t] = 1;
			if (0==i)    cout<<t;
			     else    cout<<" "<<t;
		}
	}
	cout<<endl;
	return 0;
}


int main(){
	int n;
	int *number;
	int i,j;
	int sum;

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

	i=0;
	while((i<n)&&(sum!=0)){
	    if((i==n-1)&&(number[i]!=0)){
			printf("%d",number[i]);
		}
		sum=0;
		for(j=i+1;j<n;j++){
			if(number[j]==number[i]){
				*(number+j)=0;
			}
			sum+=number[j];
		}

		if((sum!=0)&&(number[i]!=0)){
			printf("%d ",number[i]);
		}
		else if ((sum==0)&&(number[n-1]==0)){
			printf("%d",number[i]);
			sum=0;
		}
		i++;

	}

	free(number);
	return 0;
}


int main() {
	int n;
	scanf("%d", &n);
	int number[NUMBER];
	int i;
	i=0;
	while(i<n)
	{
		scanf("%d", &number[i]);
		i++;
	}
	i=1;
	int j=0;
	printf("%d", number[0]);
	while(i<n)
	{
		while(j<i)
		{
		   if(number[i]==number[j])
		   {
			    break;
		   }
		   else
		   {
			   j++;
		   }
		   if(j==i)
		   {
			   printf(" %d", number[i]);
		   }
		}
		j=0;
		i++;
	}
	return 0;
}


main()
{
      int a[101]={0};
      int n,i,now,sign;

      scanf("%d",&n);
      sign=0;
      for (i=1;i<=n;i++)
      {
          scanf("%d",&now);
          if (a[now]==0)
          {
              a[now]=1;
              if (sign==1)
                  printf(" ");
              else
                  sign=1;
              printf("%d",now);
          }
      }
      printf("\n");;
      return 0;
}


int main()
{
	int n ;
	cin >> n ;
	int a[n] ;
	for( int i = 0 ; i < n ; i ++ )
		cin >> a[i] ;
	cout << a[0] ;
	for( int i = 1 ; i < n ; i ++ )
	{
		for( int k = 0 ; k < i ; k ++ )
		{
			if( a[i] == a[k] ) break ;
			if( k == i - 1 ) cout << " " << a[i] ;
		}
	}
	cout << endl ;
	return 0 ;
}


void main()
{
	int n,*p;
	scanf("%d",&n);
	p=(int *)malloc(sizeof(int)*n);
	int i,j;
	for(i=0;i<n;i++)
	{
		scanf("%d",p+i);
	}
	printf("%d",*p);
	for(i=1;i<n;i++)
	{
		for(j=0;j<i;)
		{
			if(*(p+i)==*(p+j))
				break;
			else
				j++;
		}
		if(j==i)
			printf(" %d",*(p+i));
	}
}


int main(){
	int n,a[20000],i,j;
	cin>>n;
	int count=n;
	for(i=0;i<count;i++)
	{
		cin>>a[i];
		for(j=0;j<i;j++)
		{
			if(a[i]==a[j])
			{
				i--;
				count--;
				break;
			}
		}
	}
	for(i=0;i<count;i++)
	{
		if(i==0)
			cout<<a[i];
		else
			cout<<" "<<a[i];
	}
	return 0;
}


int main()
{
	int n,i,j;
	scanf("%d\n",&n);
	int num[n];
	scanf("%d",&num[0]);
	printf("%d",num[0]);
	for(i=1;i<=n-1;i++)
	{
		scanf(" %d",&num[i]);
		for(j=0;j<=i;j++)
		{
		if(j<i&&num[j]==num[i])
		{break;}
		if(j==i)
		{printf(" %d",num[i]);}
		}
	}
return 0;
}


int main()
{
	int a[100];
	int i,n,number,count,countl;
	count=0;
	countl=0;
	for(i=0;i<100;i++)
	{
		a[i]=0;
	}
	scanf("%d",&n);
	int b[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&number);
		if(a[number]==0)
		{
			a[number]=1;

			b[count]=number;
				count=count+1;
		}
	}
	for(i=0;i<count;i++)
	{
			countl=countl+1;
			printf("%d",b[i]);
			if(countl<count)
			{
				printf(" ");
			}

	}

	return 0;
}


int main()
{
	int n,i,j,q,x=1;
	int shuzu[N],panduan[N];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&(shuzu[i]));
	}
	panduan[0]=0;
	for(i=1;i<n;i++)
	{
		for(q=0,j=0;j<i;j++)
		{
			if(shuzu[j]==shuzu[i])
			{
				q=1;
				break;

			}
		}

		panduan[i]=q;
	}
	for(i=0,x=0;i<n;i++)
	{
		if(panduan[i]==0)
		{
			x=x+1;
		}
	}
	for(i=0;i<n;i++)
	{
		if(panduan[i]==0&&(x!=1))
		{
			printf("%d ",shuzu[i]);
			x--;
		}
		else if(panduan[i]==0&&(x==1))
		{
			printf("%d",shuzu[i]);
			x--;
		}

	}

	return 0;
}


//
//  main.cpp
//  hw
//
//  Created by ? ? on 12-12-13.
//  Copyright (c) 2012? ? ?. All rights reserved.
//

int main()
{
    int n,figure[20000]={0},num[100]={0},flag[100]={0};
    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>figure[i];
    }
    flag[figure[0]]++;
    cout<<figure[0];
    for (int i=1; i<n; i++) {
        if (flag[figure[i]]==0) {
            flag[figure[i]]++;
            cout<<" "<<figure[i];
            continue;
        }
    }
    return 0;
}


int main()
{
	struct number
	{
		int num,status;
	}
	a[20000];
	int n,i,j,count;
	scanf("%d",&n);
	count=n;
	for (i=0;i<n;i++)
	{
		scanf("%d",&a[i].num);
		a[i].status=1;
	}
	for (i=0;i<n;i++)
	{
		for (j=0;j<i;j++)
		{
			if (a[i].num==a[j].num)
			{
				a[i].status=0;
				count--;
				break;
			}
		}
	}
	for (i=0,j=0;i<n;i++)
	{
		if (a[i].status && j!=count-1)
		{
			printf("%d ",a[i].num);
			j++;
			continue;
		}
		if (a[i].status && j==count-1)
		{
			printf("%d\n",a[i].num);
			break;
		}
	}
	return 0;
}


int main()
{
	int n;
	int number[1000000];
	cin >> n;
	for (int i1=0;i1<n;i1++)
	{
		cin >> number[i1];
	}
	for (int i2=0;i2<n;i2++)
	{
		for (int i3=i2+1;i3<n;i3++)
		{
			if (number[i2]==number[i3])
			{
				number[i3]=0;
			}
		}
	}
	cout << number[0];
	for (int i4=1;i4<n;i4++)
	{
		if (number[i4]!=0)
		{
			cout <<  " " <<number[i4];
		}
	}
	return 0;
}


int main()
{
	int n,b;
	int m[20002];
	int i=1;
	int a=2;
	int num;
	scanf("%d",&n);
	do
	{
		scanf("%d",&m[i]);
		i++;
	}while(i<=n);
	if(n==1)
	{printf("%d",m[1]);}
	else
	{
		printf("%d",m[1]);
		do
		{
			b=1;
			do
			{
				num=0;
				if(m[b]==m[a]){num++;break;}
				else{b++;}
			}while(b<a);
			if(num==0){printf(" %d",m[a]);}
			else{}
			a++;
		}while(a<=n);
	}
	return 0;
}


main()
{
 int n;
 scanf("%d",&n);
 int*p;
 p=(int*)malloc(n*sizeof(int));
 int i,j;
 for(i=0;i<n;i++)
 scanf("%d",&p[i]);
 printf("%d",p[0]);
 for(i=1;i<n;i++)
 {
  for(j=0;j<i;j++)
  {
   if(p[i]==p[j])
   break;
  }
  if(j==i)
  printf(" %d",p[i]);
 }
 getchar();
 getchar();
 getchar();
 getchar();
 getchar();
 getchar();
}


int main()
{
	int n, i, j, num[20000] , st[91] , tot=0 ;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&num[i]);
	for( i=0 ; i<n ; i++ )
	{
	  for( j=0 ; j<i ; j++ ) if(num[j]==num[i])break;

	  if( j==i ) st[++tot]=num[i];
	}
	for( i=1 ; i<tot ; i++ ) printf("%d ",st[i]);
	printf("%d",st[tot]);
}


int check(int b[],int len,int x)
{
	int i,flag=1;
	for(i=0;i<len;i++)
	{
		if(b[i]==x)
		{
			flag=0;
			return 0;
			break;
		}
	}
	if(flag)
		return 1;
}
int main()
{
	int j,i,n;
	int a[20100],b[20100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	printf("%d",a[0]);
	b[0]=a[0];
	j=1;
	for(i=1;i<n;i++)
	{
		if(check(b,j,a[i]))
		{
			printf(" %d",a[i]);
			b[j]=a[i];
			j++;
		}
	}

	return 0;
}


int main()
{
	int n,i=0,x,m=0,k=0,t=0;
	cin>>n;
	int shuzu[n];
	for(i=0;i<n;i++)
	{
		cin>>x;
		shuzu[i]=x;
	}
	for(m=0;m<n;m++)
	{
		if(m==0){cout<<shuzu[m];}
		else
		{
			for(k=0;k<m;k++)
			{
				if (shuzu[m]!=shuzu[k]) t=1;
				else {t=0;break;}
			}
			if(t==1) cout<<" "<<shuzu[m];

		}

	}

	return 0;
}


int main()
{
    int n;
    int i;
    int buf;
    int appeared[110] = {0};
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &buf);
        if (!appeared[buf]) {
            if (i != 0) {
                printf(" ");
            }
            printf("%d", buf);
            appeared[buf] = 1;
        }
    }
    return 0;
}


int main(){
	int all,name[20000],input[20000],i,p,count,judge;
	scanf("%d",&all);
	count=0;
	for(i=0;i<all;i++){name[i]=0;}
	for(i=0;i<all;i++){scanf("%d",&input[i]);}
	for(i=0;i<all;i++){
		judge=0;
		for(p=0;p<count;p++){if(name[p]==input[i]){judge=1;break;}}
		if(judge==1){continue;}
		name[count]=input[i];
		count++;
	}
	printf("%d",name[0]);
	for(i=1;i<count;i++){printf(" %d",name[i]);}

return 0;
}


int main () {
	int n,k;
	int flag=0;
	int i;
	scanf("%d",&n);
	int *shuzu=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		scanf("%d",&shuzu[i]);
	}
	printf("%d",shuzu[0]);
	for(i=1;i<n;i++){
		for(k=0;k<i;k++){
			if(shuzu[i]==shuzu[k]){
				flag=1;
				break;
			}
		}
		if(flag==0){
			printf(" %d",shuzu[i]);
			}
		flag=0;
	}
	free(shuzu);
	return 0;

}


main()
{
      int m,n,i,j;
      int a[20000];
      int count=0;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      scanf("%d",&a[i]);
      printf("%d",a[0]);
      for(i=1;i<n;i++)
      {
                      int count=0;
                      for(j=0;j<i;j++)
                      {
                      if(a[i]==a[j])
                      count++;
                      }
                      if(count==0)
                      printf(" %d",a[i]);
      }
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
}


/*
 * practice.cpp
 *
 *  Created on: 2014-1-4
 *      Author: 111
 */

int main()
{
	int n;
	cin >> n;
	int str[20001];
	for(int i=0;i<n;i++)
		cin >> str[i];
	int num =0;
	for(int i=1;i<n-num;i++){
		for(int j=0;j<i;j++)
			if(str[j]==str[i]){
				for(int k=i;k<n-1-num;k++)
					str[k] = str[k+1];
				num++;
				//cout << num << endl;
				i--;
				break;
			}
	}
	cout << str[0];
	for(int i=1;i<n-num;i++)
		cout << ' ' << str[i];
	cout << endl;
	return 0;
}


struct student
{
	int num;
	int yw;
	int sx;
	int zong;
}stu[100001];

int main(int argc, char* argv[])
{
	int i,n,max1=0,max2=0,max3=0,fir,sec,thi;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d %d %d",&stu[i].num,&stu[i].yw,&stu[i].sx);
		stu[i].zong=stu[i].yw+stu[i].sx;
		if(stu[i].zong>max1){
			max3=max2;
			thi=sec;
			max2=max1;
			sec=fir;
			max1=stu[i].zong;
			fir=i;
		}else if(stu[i].zong>max2){
			max3=max2;
			thi=sec;
			max2=stu[i].zong;
			sec=i;
		}else if(stu[i].zong>max3){
			max3=stu[i].zong;
			thi=i;
		}
	}

	printf("%d %d\n",stu[fir].num,stu[fir].zong);
	printf("%d %d\n",stu[sec].num,stu[sec].zong);
	printf("%d %d\n",stu[thi].num,stu[thi].zong);
	return 0;
}


struct stu
{
	int num;
	int mark1;
	int mark2;
	long int total_mark;
};

int main(void)
{
	int n,i,j,k,t=0,max;
	struct stu *p;
	struct stu *q;
	scanf("%d",&n);
	p=(struct stu *)malloc(1000000*sizeof(struct stu));
	q=p;
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&(p+i)->num,&(p+i)->mark1,&(p+i)->mark2);
		(p+i)->total_mark=(p+i)->mark1+(p+i)->mark2;
	}
loop:	max=0;
		for(j=0;j<n;j++)
		{
			if((p+j)->total_mark>max)
	               max=(p+j)->total_mark;
		}
		for(k=0;k<n;k++)
			if(max==(p+k)->total_mark&&k<n)
			{
		        printf("%d %ld\n",(p+k)->num,(p+k)->total_mark);
			 	t++;
				(p+k)->total_mark=0;
				break;
			}
		if(t<3) goto loop;
}


struct student
{
	int num;
	int yu;
	int shu;
	struct student *next;
};

void main()
{
	struct student *head,*p1,*p2;
	int n,i,j,k;
	scanf("%d",&n);
	head=p1=p2=(struct student*)malloc(LEN);
	scanf("%d %d %d",&p1->num,&p1->yu,&p1->shu);
	for(i=1;i<n;i++)
	{
		p1=(struct student*)malloc(LEN);
		scanf("%d %d %d",&p1->num,&p1->yu,&p1->shu);
		p2->next=p1;
		p2=p1;
	}
	p2->next=NULL;
	for(i=1;i<=3;i++)
{	p1=p2=head;
	while(p1!=NULL)
	{
		if(p1->yu+p1->shu>p2->yu+p2->shu)
			p2=p1;
		p1=p1->next;
	}
	printf("%d %d\n",p2->num,p2->yu+p2->shu);
	p2->yu=0;
	p2->shu=0;
}

}


void main()
{
	int mat,chi,i,num;
	struct stu{
		int id;
		int to;
	}s[100001],temp1,temp2,max1,max2,max3;
	scanf("%d",&num);
	for(i=0;i<num;i++){
		scanf("%d %d %d",&s[i].id,&chi,&mat);
		s[i].to=chi+mat;
	}
	if(s[0].to>s[1].to&&s[1].to>s[2].to){max1=s[0];max2=s[1];max3=s[2];}
	else if(s[2].to>s[0].to&&s[0].to>s[1].to){max1=s[2];max2=s[0];max3=s[1];}
	else if(s[0].to>s[2].to&&s[2].to>s[1].to){max1=s[0];max2=s[2];max3=s[1];}
	else if(s[2].to>s[1].to&&s[1].to>s[0].to){max1=s[2];max2=s[1];max3=s[0];}
	else if(s[1].to>s[0].to&&s[0].to>s[2].to){max1=s[1];max2=s[0];max3=s[2];}
	else {max1=s[1];max2=s[2];max3=s[0];}
	for(i=0;i<num-1;i++){
		if(s[i].to>max1.to){
			temp1=max1;
			temp2=max2;
			max1=s[i];
			max2=temp1;
			max3=temp2;
		}
		else if(s[i].to>max2.to&&s[i].id!=max1.id){
			temp1=max2;
			max2=s[i];
			max3=temp1;
		}
		else if(s[i].to>max3.to&&s[i].id!=max2.id&&s[i].id!=max1.id)max3=s[i];
	}
	printf("%d %d\n%d %d\n%d %d\n",max1.id,max1.to,max2.id,max2.to,max3.id,max3.to);
}


int main()
{
    int i,n;
    struct{
       int id,chi,math,sum;
    } s,s1,s2,s3;
    s1.sum=s2.sum=s3.sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d%d%d",&s.id,&s.chi,&s.math);
        s.sum=s.chi+s.math;
        if(s.sum>s1.sum)
        {
            s3=s2;s2=s1;s1=s;
        }
        else if(s.sum>s2.sum)
        {
             s3=s2,s2=s;
        }
        else if(s.sum>s3.sum)
        {
             s3=s;
        }
    }
    printf("%d %d\n%d %d\n%d %d\n",s1.id,s1.sum,s2.id,s2.sum,s3.id,s3.sum);
    getchar();
    getchar();
    getchar();
    return 0;
}


struct student{ int num;int a;int b;int c;};
void main()
{
	  int n,i,j,m,t;
      struct student stu[100000];
	  scanf("%d",&n);
	  for(i=0;i<n;i++)
	  {scanf("%d %d %d",&stu[i].num,&stu[i].a,&stu[i].b);
	  stu[i].c=stu[i].a+stu[i].b;}
	  for(i=0;i<3;i++)
		  for(j=i+1;j<n;j++)
		  {
			  if(stu[i].c<stu[j].c){
				  t=stu[i].c;stu[i].c=stu[j].c;stu[j].c=t;
				  m=stu[i].num;stu[i].num=stu[j].num;stu[j].num=m;}
		  }
		  for(i=0;i<3;i++)
			  printf("%d %d\n",stu[i].num,stu[i].c);
}


int main(int argc, char* argv[])
{
	int n;
	scanf("%d",&n);
	struct stu{
	    int id;
		int x,y;

	}stu[100000];
	int no1=0;
	int no2=0;
	int no3=0;
	int i;
	int N1,N2,N3;
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&stu[i].id,&stu[i].x,&stu[i].y);
	}
    for(i=0;i<n;i++)
	{
		if((stu[i].x+stu[i].y)>no1){no2=no1;no1=(stu[i].x+stu[i].y);N2=N1;N1=i;}
        else if((stu[i].x+stu[i].y)>no2){no3=no2;no2=(stu[i].x+stu[i].y);N3=N2;N2=i;}
		else if((stu[i].x+stu[i].y)>no3){no3=(stu[i].x+stu[i].y);N3=i;}
	}
	printf("%d %d\n%d %d\n%d %d",stu[N1].id,(stu[N1].x+stu[N1].y),stu[N2].id,(stu[N2].x+stu[N2].y),stu[N3].id,(stu[N3].x+stu[N3].y));

	return 0;
}


struct student
{long num;
 int math;
 int chinese;
 int sum;
 struct student *next;
};
long n;

struct student *creat(void)
{struct student *head;
 struct student *p1,*p2;
 int i=1;
 scanf("%ld",&n);
 p1=p2=(struct student*)malloc(LEN);
 scanf("%ld%d%d",&p1->num,&p1->math,&p1->chinese);
 p2->sum=p2->chinese+p2->math;
 while (i<=n)
 {
  if(i==1) head=p1;
  else
  {p1=(struct student*)malloc(LEN);
  scanf("%ld%d%d",&p1->num,&p1->math,&p1->chinese);
  p1->sum=p1->chinese+p1->math;
  p2->next=p1;
  p2=p1;}
  i++;
 }
 p2->next=0;
 return head;
}

struct student *del(struct student *head,int max)
{
	struct student *p1,*p2;
	p1=head;
	while (p1->sum!=max&&p1->next!=0)
	{
		p2=p1;p1=p1->next;
	}
	if(p1->sum==max)
	{
		if(p1==head) head=p1->next;
		else p2->next=p1->next;
		n=n-1;
	}
	return(head);
}

void print(struct student *head)
{
	struct student *p1,*p2;
	int i,max,num;
	max=head->sum;
	p1=head;
	p2=p1->next;
	for(i=1;i<=3;i++)
	{
	 while(p1->next!=0)
	 {
		 if((p2->sum)>max) {max=p2->sum; num=p2->num;}
		 p1=p2;
		 p2=p1->next;
	 }
	 printf("%ld %d\n",num,max);
	 head=del(head,max);
	 p1=head;
	 p2=p1->next;
	 max=p1->sum;
	}

}

//void print (struct student*head)
//{
//	struct student *p;
//	p=head;
//	if(head!=0)
//		do
//		{
//			printf("%ld %d %d %d\n",p->num,p->math,p->chinese,p->sum);
//			p=p->next;
//		}while (p!=0);
//}
main()
{
	struct student *head;
	head=creat();
	print(head);
}


void main()
{
	struct stu
	{
		int  num;
		int chinese;
		int math;
		int sum;
		struct stu*next;
	};
	int n,max,i;
	struct stu *p1,*p2,*head,*maxsum;
	scanf("%d",&n);
	p1=p2=(struct stu*)malloc(LEN);
	scanf("%d %d %d",&p1->num,&p1->chinese,&p1->math);
	for(i=1;i<n;i++)
	{
		if(i==1)
			head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct stu*)malloc(LEN);
		scanf("%d %d %d",&p1->num,&p1->chinese,&p1->math);
	}
	p2->next=p1;
	p2=p1;
	p2->next=NULL;

	p1=head;
	while(p1->next!=NULL)
	{
		p1->sum=p1->chinese+p1->math;
		p1=p1->next;
	}
	p1->sum=p1->chinese+p1->math;
	for(i=1;i<=3;i++)
	{
		p1=head;
	    max=p1->sum;
		maxsum=p1;
	    while(p1->next!=NULL)
		{
		  if(p1->sum>max)
		  {
			maxsum=p1;
			max=p1->sum;
		  }
		  p1=p1->next;

		}
		if(p1->sum>max)
		  {
			maxsum=p1;
			max=p1->sum;
		  }
	  printf("%d %d\n",maxsum->num,maxsum->sum);
	  maxsum->sum=0;
	}
}


struct stu{
	int ID;
	int ch;
	int ma;
	int sum;
	struct stu *next;
	};
int main(){
	struct stu *head;
	struct stu *p1,*p2,*a,*b,*c,*t;
	int n,i=0;
	a=b=c=p1=p2=(struct stu *) malloc(sizeof(struct stu));
	scanf("%d",&n);
	scanf("%d%d%d",&p1->ID,&p1->ch,&p1->ma);
	p1->sum=p1->ch+p1->ma;
	head=NULL;
	while(i<n-1){
		i++;
		p1->sum=p1->ch+p1->ma;
		if(i==1)head=p1;
		else p2->next=p1;
		p2=p1;
		if(p1->sum>a->sum) {c=b;b=a;a=p2;}
		else if(p1->sum>b->sum) {c=b;b=p2;}
		else if(p1->sum>c->sum) c=p2;
		p1=(struct stu *) malloc(sizeof(struct stu));
		scanf("%d%d%d",&p1->ID,&p1->ch,&p1->ma);
	}
	p2->next=NULL;
	printf("%d %d\n%d %d\n%d %d\n",a->ID,a->sum,b->ID,b->sum,c->ID,c->sum);
	return 0;
}


//#define NULL 0
struct student
{
	int num;
	int ch;
	int math;
	int sum;
	struct student*next;
};

struct student *creat(int n)
{
	struct student *head;
	struct student *p1,*p2;
	int i;
	p1=p2=(struct student *)malloc(sizeof (struct student));
	scanf("%d %d %d",&p1->num,&p1->ch,&p1->math);
	//head=NULL;
	for(i=0;i<n-1;i++)
	{
		if(i==0)head=p1;

		p1=(struct student*)malloc(sizeof(struct student));
		scanf("%d %d %d",&p1->num,&p1->ch,&p1->math);
		p2->next=p1;
		p2=p1;
	}

	p2->next=NULL;
	return (head);
}
void print(struct student*head)
{
	struct student*p;
	p=head;
	if(head!=NULL)
		do
		{
			printf("%d %d %d",p->num,p->ch,p->math);
			p=p->next;
		}while(p!=NULL);
}

main()
{
	int n,i,j,k,t;
	struct student *p1,*p2,*p3,*p;
	struct student g;
	scanf("%d",&n);
	p=creat(n);p1=p;

	p2=p;p3=p;
	for(i=0;i<n;i++)
	{
		p1->sum=p1->math+p1->ch;
        //printf("%d\n",p1->sum);
		p1=p1->next;

	}
    p1=p;p2=p;printf("\n\n");
	i=0;
	while(i<3)
	{
		p1=p2->next;
		while(p1!=NULL)
		{

			if((p2->sum)<(p1->sum))
			{
				g.num=p2->num;
				p2->num=p1->num;
				p1->num=g.num;
                g.sum=p2->sum;
				p2->sum=p1->sum;
				p1->sum=g.sum;
			}
			p1=p1->next;

		}

		p2=p2->next;i=i+1;

	}
	p1=p;p2=p;
	//printf("\n\n");
    /*for(i=0;i<n;i++)
	{

        printf("%d\n",p1->sum);
		p1=p1->next;

	}*/
	p1=p;
	for(i=0;i<3;i++)
	{

		printf("%d %d\n",p1->num,p1->sum);
		p1=p1->next;
	}
}


/*
 * jiegou_1.cpp
 *
 *  Created on: 2011-1-2
 *      Author: Iris
 *      ????????
 * ????STUDENT_NUM???????????????? ?????????ID???????????
 * ???????????????????????????????
 */

int main(){
	int n,i;
	cin>>n;//??????
	struct student{
		int stuNo;
		int yuwen;
		int shuxue;
		int zongfen;
	} stu[n];//?????????????????????????t?????
	struct tri{
		int stuNo;
		int zongfen;
	} qian[3]={0,0,0,0,0,0};//??????????????????????
	for(i=0;i<n;i++){
		cin>>stu[i].stuNo;
		cin>>stu[i].yuwen;
		cin>>stu[i].shuxue;//????????????
		stu[i].zongfen=stu[i].yuwen+stu[i].shuxue;//?????????
	}
	for(i=0;i<n;i++){
		if(stu[i].zongfen>qian[0].zongfen){
			qian[2]=qian[1];
			qian[1]=qian[0];
			qian[0].stuNo=stu[i].stuNo;
			qian[0].zongfen=stu[i].zongfen;
			continue;
		}
		if(stu[i].zongfen>qian[1].zongfen){
			qian[2]=qian[1];
			qian[1].stuNo=stu[i].stuNo;
			qian[1].zongfen=stu[i].zongfen;
			continue;
		}
		if(stu[i].zongfen>qian[2].zongfen){
			qian[2].stuNo=stu[i].stuNo;
			qian[2].zongfen=stu[i].zongfen;
		}
	}//?????
	for(i=0;i<3;i++)
		cout<<qian[i].stuNo<<' '<<qian[i].zongfen<<endl;//????????????
	return 0;
}


struct student
{
	int num;
	int c;
	int m;
	int sum;
    struct student *next;
};
void main()
{
	int n,i,j;
	scanf("%d",&n);
    struct student *head,*p0,*p,*q;
    head=(struct student*)malloc(sizeof(struct student));
	head->next=NULL;
	for(i=0;i<n;i++)
	{
		q=(struct student*)malloc(sizeof(struct student));
		scanf("%d %d %d",&q->num,&q->c,&q->m);
		q->sum=q->c+q->m;
		q->next=NULL;
		p0=head;
		p=p0->next;
		j=0;
        while(p!=NULL&&q->sum<=p->sum)
		{
			p0=p;
			p=p->next;
			j++;
			if(j>3)
				goto A;
		}
        p0->next=q;
		q->next=p;
A:		continue;
	}
	p=head->next;
	for(i=0;i<3;i++)
	{
		printf("%d %d\n",p->num,p->sum);
		p=p->next;
	}
}


/*
 * mark.cpp
 *
 *  Created on: 2011-12-9
 *      Author: admin
 */
struct student{
	int id;
	int chi;
	int math;
};
struct maxer{
	int id;
	int mark;
};
int main(){
	int n,i,j;
	struct student a[100001],temp;
	struct maxer max,top[3];                         //top3????
	cin>>n;
	for (i=1;i<=n;i++){
		cin>>a[i].id>>a[i].chi>>a[i].math;
	}
	for (i=1;i<=3;i++){                              //????
		max.mark=0;
		for (j=i;j<=n;j++){
		if 	(a[j].chi+a[j].math>max.mark){
			max.id=a[j].id;
			max.mark=a[j].chi+a[j].math;             //?????
		}
		}
		top[i-1]=max;                                //????????????????????????
		temp=a[i];
		a[i]=a[max.id];
		a[max.id]=temp;
	}
	for (i=0;i<=2;i++){
		cout<<top[i].id<<' '<<top[i].mark;
		if (i!=2)cout<<endl;
	}
return 0;
}


// ????????.cpp : ??????????????
//

struct student
{
	int id;
	int chinese;
	int math;
	int total;
};

int main()
{
	int number;
	struct student stu[100000];
	scanf("%d\n",&number);
	for(int i=1;i<=number;++i)
	{
		scanf("%d%d%d",&stu[i].id,&stu[i].chinese,&stu[i].math);
		stu[i].total=stu[i].chinese+stu[i].math;
	}
	for(int i=1;i<=3;++i)
	{
		for(int j=i+1;j<=number;++j)
		{
			if(stu[i].total<stu[j].total)
			{
				struct student temp;
				temp=stu[i];
				stu[i]=stu[j];
				stu[j]=temp;
			}
		}
		printf("%d %d\n",stu[i].id,stu[i].total);
	}
	return 0;
}


struct stu
{
	int id;
	int Chinese;
	int math;
}a[100000];
void main()
{
	int n,i,first,second,third,h1=0,h2=0,h3=0,e;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&a[i].id,&a[i].Chinese,&a[i].math);
	}
	first=0;
	second=0;
	third=0;
	for(i=0;i<n;i++)
	{
		if(first<(a[i].Chinese+a[i].math))
		{
			third=second;
			h3=h2;
			second=first;
			h2=h1;
			first=a[i].Chinese+a[i].math;
			h1=a[i].id;
		}
		else if(first==(a[i].Chinese+a[i].math)&&first>second)
		{
			third=second;
			h3=h2;
			h2=a[i].id;
			second=a[i].Chinese+a[i].math;
		}
		else if(first==(a[i].Chinese+a[i].math)&&first==second&&second>third)
		{
			third=a[i].Chinese+a[i].math;
			h3=a[i].id;
		}
		else if(first>(a[i].Chinese+a[i].math)&&second<(a[i].Chinese+a[i].math))
		{
			third=second;
			h3=h2;
			second=a[i].Chinese+a[i].math;
			h2=a[i].id;
		}
		else if(second>(a[i].Chinese+a[i].math)&&third<(a[i].Chinese+a[i].math))
		{
			third=a[i].Chinese+a[i].math;
			h3=a[i].id;
		}
	}
	printf("%d %d\n%d %d\n%d %d",h1,first,h2,second,h3,third);
}


struct student
{int id;
int yw;
int sx;
}stu[100000];
void main()
{
	int n,i,sum[100000],temp[3],max;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d",&stu[i].id,&stu[i].yw,&stu[i].sx);
		sum[i]=stu[i].yw+stu[i].sx;
	}
	for(i=0,max=-1,temp[0]=0;i<n;i++)
	{
		if(sum[i]>max)
		{
			max=sum[i];
			temp[0]=i;
		}
	}
    for(i=0,max=-1,temp[1]=0;i<n;i++)
	{
		if(i==temp[0])continue;
		else
		{
			if(sum[i]>max)
			{
				max=sum[i];
				temp[1]=i;
			}
		}
	}
    for(i=0,max=-1,temp[2]=0;i<n;i++)
	{
		if(i==temp[0]||i==temp[1])continue;
		else
		{
			if(sum[i]>max)
			{
				max=sum[i];
				temp[2]=i;
			}
		}
	}
	printf("%d %d\n",stu[temp[0]].id,sum[temp[0]]);
    printf("%d %d\n",stu[temp[1]].id,sum[temp[1]]);
	printf("%d %d",stu[temp[2]].id,sum[temp[2]]);
}


struct student
{
	int n1;
	int n2;
	int n3;
	struct student *next;
};
void main()
{
	struct student *p,*head,*tail;
	int n,i,sum[100000],max1,max2,max3,k1,k2,k3;
	scanf("%d",&n);
	head=NULL;tail=NULL;
	for(i=1;i<=n;i++)
	{
		p=(struct student*)malloc(len);
		scanf("%d%d%d",&p->n1,&p->n2,&p->n3);
		if(head==NULL)
			head=tail=p;
		else
		{
			tail->next=p;
			tail=p;}
		sum[i]=p->n2+p->n3;
	}
	max1=sum[1];k1=1;
	for(i=1;i<=n;i++)
		if(sum[i]>max1) {max1=sum[i];k1=i;}
	sum[k1]=0;

         max2=sum[1];k2=1;
         for(i=1;i<=n;i++)
		if(sum[i]>max2) {max2=sum[i];k2=i;}
	sum[k2]=0;

	max3=sum[1];k3=1;
	for(i=1;i<=n;i++)
		if(sum[i]>max3) {max3=sum[i];k3=i;}
	printf("%d %d\n%d %d\n%d %d\n",k1,max1,k2,max2,k3,max3);
}


struct student
{
	long number;
	int chinese;
	int math;
	int sum;
	struct student *next;
	struct student *last;
};
struct student *creat(int n)
{
	struct student *head,*p1,*p2;
	int i;
	p1=(struct student *)malloc(len);
	scanf("%d %d %d",&p1->number,&p1->chinese,&p1->math);
	p1->sum=p1->chinese+p1->math;
	p1->last=null;p1->next=null;
	head=p1;p2=p1;
	for(i=2;i<=n;i++)
	{
		p1=(struct student *)malloc(len);
		scanf("%d %d %d",&p1->number,&p1->chinese,&p1->math);
		p1->sum=p1->chinese+p1->math;
		p1->last=p2;
		p2->next=p1;
		p1->next=null;
		p2=p1;
	}
	return(head);
}
struct student *print(struct student *head)
{
	struct student *max,*p;
	p=head;max=head;
	while(p)
	{
		if(p->sum>max->sum)max=p;
		p=p->next;
	}
	printf("%d %d\n",max->number,max->sum);
	if(max==head)
	{
		max->next->last=null;
		head=max->next;
	}
	else
	{
		max->next->last=max->last;
		max->last->next=max->next;
	}
	return(head);
}
void main()
{
	int n;
	struct student *head;
	scanf("%d",&n);
	head=creat(n);
	print(head);
	print(head);
	print(head);
}


struct stu
{
  int num;
  int a;
  int b;
  int total;
  int flag;
  struct stu *next;
};

void main()
{

  struct stu *p,*head;
  struct stu *p1,*p2,*pmax;
  int N,i;
  int max;

  scanf("%d",&N);

  //??
  p1=p2=(struct stu*)malloc(LEN);
  scanf("%d%d%d",&p1->num,&p1->a,&p1->b);
  p1->total=p1->a+p1->b;
  p1->flag=0;
  p1->next=NULL;

  head=p1;

  for(i=0;i<N-1;i++)
  {
	p2=p1;
	p1=(struct stu *)malloc(LEN);
    scanf("%d%d%d",&p1->num,&p1->a,&p1->b);
	p1->total=p1->a+p1->b;
	p1->flag=0;
	p1->next=NULL;

	p2->next=p1;
  }

  for(i=0;i<3;i++)
  {

	for(p=head,max=0;p!=NULL;p=p->next)
	   if(max<p->total&&p->flag==0)
	   {
	     max=p->total;
		 pmax=p;
	   }
	pmax->flag=1;
	printf("%d %d\n",pmax->num,pmax->total);
  }

 /*  p=head;
  do
  {
    printf("%d*,",p->num);
	p=p->next;
  }while(p!=NULL);*/

 // for(i=0;i<3;i++)
   //  printf("%d %d\n",pmax[i]->num,pmax[i]->total);

}


struct student
{
	char num[6];
	int score[2];
	int sum;
} stu[100000];

void main()
{
	long n,i,j,maxi1,maxi2,maxi3;
         int max1=0,max2=0,max3=0;
	scanf("%ld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",stu[i].num);
		for(j=0;j<2;j++)
			scanf("%d",&stu[i].score[j]);
	}
      for(i=0;i<n;i++)
	  stu[i].sum=stu[i].score[0]+stu[i].score[1];

      for(i=0;i<n;i++)
        if(stu[i].sum>max1)
          {max1=stu[i].sum;
           maxi1=i;
          }
      stu[maxi1].sum=0;
      for(i=0;i<n;i++)
         if(stu[i].sum>max2)
           {max2=stu[i].sum;
            maxi2=i;
           }
	  stu[maxi2].sum=0;
      for(i=0;i<n;i++)
         if(stu[i].sum>max3)
           {max3=stu[i].sum;
            maxi3=i;
           }
     printf("%s %d\n%s %d\n%s %d",stu[maxi1].num,max1,stu[maxi2].num,max2,stu[maxi3].num,max3);
}


int main()
{
	struct student{
		int number;
		int chinese;
		int math;
		int sum;
		}students[100000];
		int n,i;
        int a1,b1,a2,b2,a3,b3;
		int c1,c2;
		int max=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&students[i].number,&students[i].chinese,&students[i].math);
		students[i].sum=students[i].chinese+students[i].math;
	}
	max=0;
	for(i=0;i<n;i++)
	{
		if(students[i].sum>max)
		{
			max=students[i].sum;
			a1=students[i].number;
			b1=students[i].sum;
			c1=i;
		}
	}
	max=0;
	for(i=0;i<n;i++)
	{
	if(students[i].sum>max&&i!=c1)
		{
			max=students[i].sum;
			a2=students[i].number;
			b2=students[i].sum;
			c2=i;
		}
	}
   max=0;
   for(i=0;i<n;i++)
	{
		if(students[i].sum>max&&i!=c2&&i!=c1)
		{
			max=students[i].sum;
			a3=students[i].number;
			b3=students[i].sum;
		}
	}
	printf("%d %d\n",a1,b1);
    printf("%d %d\n",a2,b2);
    printf("%d %d\n",a3,b3);
	return 0;
}


struct student
{
	int num;
	int chi;
	int math;
	int add;
	struct student *next;
};
//struct student*creat()
//{
//	struct student*p1,*p2,*head;
//	int i=0;
//	p1=p2=(struct student *)malloc(LEN);
//
//	head=NULL;
//	i=i+1;
void main()
{
	int n,i;
	scanf("%d",&n);
	struct student *p1,*p2,*head;
	head=p1=p2=(struct student *)malloc(LEN);
	scanf("%d%d%d",&p1->num,&p1->chi,&p1->math);
	p1->add=p1->chi+p1->math;
	for(i=1;i<n-1;i++)
    {
	    p1=(struct student *)malloc(LEN);
		scanf("%d%d%d",&p1->num,&p1->chi,&p1->math);
		p1->add=p1->chi+p1->math;
		p2->next=p1;
		p2=p1;
	}
	scanf("%d%d%d",&p1->num,&p1->chi,&p1->math);
	p1->add=p1->chi+p1->math;
	p1->next=NULL;
//		printf("%d\n",p1->add);
	for(i=0;i<3;i++)
	{
		p1=head;
		int max=p1->add;
	    int *pp=&p1->num;
	    int *pp1=&p1->add;
	    while(p1->next)
		{
		  p1=p1->next;
		  if(p1->add>max)
		  {
			max=p1->add;
			pp=&p1->num;
			pp1=&p1->add;
		  }
		}
//	    if(p2->add>max)
//		{
//			max=p2->add;
//			pp=&p2->num;
//			pp1=&p2->add;
//		}
    	 printf("%d %d\n",*pp,max);
	     *pp1=0;
	}
}


struct student{
  int num;
  int chin;
  int math;
  int sum;
};
int main()
{
 int n,i;
 scanf("%d",&n);
 struct student *stu;
 stu=(struct student*)malloc(n*sizeof(int)*4);
 for(i=0;i<n;i++){
  scanf("%d%d%d",&stu[i].num,&stu[i].chin,&stu[i].math);
  stu[i].sum=stu[i].chin+stu[i].math;
 }
 int j,e1,e2;
 for(j=1;j<4;j++){
  for(i=0;i<n-j;i++){
   if(stu[i].sum>=stu[i+1].sum){
         e1=stu[i+1].sum;
	e2=stu[i+1].num;
         stu[i+1].sum=stu[i].sum;
	stu[i+1].num=stu[i].num;
	stu[i].sum=e1;
         stu[i].num=e2;
   }
  }
 }

 printf("%d %d\n",stu[n-1].num,stu[n-1].sum);
 printf("%d %d\n",stu[n-2].num,stu[n-2].sum);
 printf("%d %d\n",stu[n-3].num,stu[n-3].sum);
 free(stu);
 return 0;
}


struct student
{
	int id,word,math,sum;
}stu[100000];
void main()
{
	int n,i=1,maxi;
	scanf("%d",&n);
	while(i<=n)
	{
		scanf("%d %d %d",&stu[i].id,&stu[i].word,&stu[i].math);
		stu[i].sum=stu[i].word+stu[i].math;
		i=i+1;
	}
	i=n;
	stu[n+1].sum=0;
	stu[n+2].sum=0;
	stu[n+3].sum=0;
	stu[n+1].id=0;
	stu[n+2].id=0;
	stu[n+3].id=0;
	stu[n+1].math=0;
	stu[n+2].math=0;
	stu[n+3].math=0;
	stu[n+1].word=0;
	stu[n+2].word=0;
	stu[n+3].word=0;
	while(i>=1)
	{
		if(stu[i].sum>=stu[n+1].sum)
		{	stu[n+1]=stu[i];
		maxi=i;
		}
		i=i-1;
	}
	printf("%d %d\n",stu[n+1].id,stu[n+1].sum);
	stu[maxi].sum=0;
	i=n;
	while(i>=1)
	{
		if(stu[i].sum>=stu[n+2].sum)
		{	stu[n+2]=stu[i];
		maxi=i;
		}
		i=i-1;
	}
	printf("%d %d\n",stu[n+2].id,stu[n+2].sum);
	stu[maxi].sum=0;
	i=n;
	while(i>=1)
	{
		if(stu[i].sum>=stu[n+3].sum)
			stu[n+3]=stu[i];
		i=i-1;
	}
	printf("%d %d\n",stu[n+3].id,stu[n+3].sum);
}


struct marks
{
    long ID;
    int Chinese;
    int Maths;
    int total;
}student[100000],first,second,third;

void main()
{
   first.total=0;
   second.total=0;
   third.total=0;
   int student_num,i,count=0;
   scanf("%ld",&student_num);
   for(i=0;i<student_num;i++)
   {
       scanf("%ld%d%d",&student[i].ID,&student[i].Chinese,&student[i].Maths);
   }
   for(i=0;i<student_num;i++)
  {
      student[i].total=(student[i].Chinese+student[i].Maths);
   }
    for(i=0;i<student_num;i++)
   {
       if(student[i].total>first.total)
       {
             first=student[i];
       }
   }
  for(i=0;i<student_num;i++)
  {
         if(student[i].total==first.total)
         {count++;printf("%ld %d\n",student[i].ID,student[i].total);}
         if(count>3) break;
   }
   for(i=0;i<student_num;i++)
  {
     if(student[i].total>second.total&&student[i].total<first.total)
     {
                 second=student[i];
     }
   }
  for(i=0;i<student_num;i++)
  {
         if(count>=3) break;
         if(student[i].total==second.total)
         {count++;printf("%ld %d\n",student[i].ID,student[i].total);}
   }
   for(i=0;i<student_num;i++)
  {
     if(student[i].total>third.total&&student[i].total<second.total)
     {
                 third=student[i];
     }
   }
   for(i=0;i<student_num;i++)
  {
         if(count>=3) break;
         if(student[i].total==third.total)
         {count++;printf("%ld %d\n",student[i].ID,student[i].total);}
   }
}


void main()
{
 struct stu
 {
  long num,c,m,d;
  struct stu *next;
 };
 long n,i,f;
 struct stu *head,*p1,*p2;
 scanf("%ld",&n);
 for (i=1;i<=n;i++)
   {
   p1=(struct stu*)malloc(LEN);
   scanf("%ld%ld%ld",&p1->num,&p1->c,&p1->m);
   p1->d=p1->c+p1->m;
   if (i==1)
     {
     p1->next=0;
     head=p1;
     }
     else
     {
     if (i<=3) f=1;
       else
       {
       p2=head->next->next;
       if (p1->d>p2->d) f=1;
	 else f=0;
       }
     if (f==1)
     {
     p2=head;
     if (p2->d<p1->d)
       {
       p1->next=p2;
       head=p1;
       }
       else
	 {
	 while ((p2->next!=0)&&(p2->next->d>p1->d))
	   p2=p2->next;
	 p1->next=p2->next;
	 p2->next=p1;
	 }
     }
     }
   }
 p1=head;
 for (i=1;i<=3;i++)
   {
   printf("%ld %ld\n",p1->num,p1->d);
   p1=p1->next;
   }
}


int main()
{
	int n,i;
	int sum[100000];
	int max1,max2,max3;
	int x=0;
	scanf("%d",&n);
	struct {
		int number;
		int chin;
		int math;
	}student[100000];
	for(i=0;i<n;i++){
		scanf("%d%d%d",&student[i].number,&student[i].chin,&student[i].math);
		sum[i]=student[i].chin+student[i].math;}
	max1=sum[0];
	max2=sum[0];
	max3=sum[0];
	for(i=0;i<n;i++){
		if(sum[i]>max1)
			max1=sum[i];}
	for(i=0;i<n;i++){
		if(sum[i]==max1){
			printf("%d %d\n",student[i].number,sum[i]);
			x++;}
		if(x>=3)
			break;
	}
	for(i=0;i<n;i++){
		if((sum[i]>max2)&&(sum[i]!=max1))
			max2=sum[i];}
	for(i=0;i<n;i++){
		if(x>=3)
			break;
		if(sum[i]==max2){
			printf("%d %d\n",student[i].number,sum[i]);
			x++;}
	}
	for(i=0;i<n;i++){
		if((sum[i]>max3)&&(sum[i]!=max1)&&(sum[i]!=max2))
			max3=sum[i];}
	for(i=0;i<n;i++){
		if(x>=3)
			break;
		if(sum[i]==max3){
			printf("%d %d",student[i].number,sum[i]);
		x++;}
	}
	return 0;
}


int main()
{
    int n,i,j,t,First=0,FirstNum,Second=0,SecondNum,Third=0,ThirdNum;
    scanf("%d",&n);
    struct Student
    {
       int Chinese;
       int Math;
       int Sum;
       int Num;
    }Student[n+1];
    for (i=1;i<=n;i++)
      {
         scanf("%d %d %d",&Student[i].Num,&Student[i].Chinese,&Student[i].Math);
         Student[i].Sum=Student[i].Chinese+Student[i].Math;
      }
    for (i=1;i<=n;i++)
      {
        if (Student[i].Sum>First)
         {
             First=Student[i].Sum;
             FirstNum=i;
         }
      }
    for (i=1;i<=n;i++)
      {
        if (Student[i].Sum>Second&&Student[i].Sum<=First&&i!=FirstNum)
         {
             Second=Student[i].Sum;
             SecondNum=i;
         }
      }
    for (i=1;i<=n;i++)
      {
        if (Student[i].Sum>Third&&Student[i].Sum<=Second&&i!=SecondNum&&i!=FirstNum)
         {
             Third=Student[i].Sum;
             ThirdNum=i;
         }
      }
    printf("%d %d\n",FirstNum,First);
    printf("%d %d\n",SecondNum,Second);
    printf("%d %d\n",ThirdNum,Third);

}


int main()
{
	struct stu
	{
		int yu;
		int shu;
		char name[6];
	};
	struct stu s[100000],one,two,three;
	one.yu=0;one.shu=0;
	two.yu=0;two.shu=0;
	three.yu=0;three.shu=0;
	int n,j,k;
	scanf("%d",&n);
	for(j=0;j<n;j++)
	{
		scanf("%s %d %d",s[j].name,&s[j].yu,&s[j].shu);
	}
	for(j=0;j<n;j++)
	{
		if((s[j].yu+s[j].shu)>(one.yu+one.shu))
		{
			one=s[j];
			k=j;
		}
	}
	s[k].yu=0;s[k].shu=0;
	for(j=0;j<n;j++)
	{
		if((s[j].yu+s[j].shu)>(two.yu+two.shu))
		{
			two=s[j];
			k=j;
		}
	}
	s[k].yu=0;s[k].shu=0;
	for(j=0;j<n;j++)
	{
		if((s[j].yu+s[j].shu)>(three.yu+three.shu))
		three=s[j];
	}
	printf("%s %d\n%s %d\n%s %d\n",one.name,one.yu+one.shu,two.name,two.yu+two.shu,three.name,three.yu+three.shu);
	return 0;
}


struct stu
{
	int ID;
	int Chinese;
	int math;
	int sum;
}zz[100000],mx,mx1,mx2;
int main()
{
	int n,i,j;
	cin>>n;
	for ( i = 0 ; i < n ; i ++ )
	{
		cin>>zz[i].ID>>zz[i].Chinese>>zz[i].math;
		zz[i].sum = zz[i].Chinese + zz[i].math;
	}
	mx = zz[0];
	for ( i = 0 ; i < n ; i ++ )
	{
		if ( zz[i].sum > mx.sum )
			mx = zz[i];
	}
		cout<<mx.ID<<' '<<mx.sum<<endl;
		mx.sum=0;
		mx1 = mx;
		for ( i = 0 ; i < n ; i ++ )
	{
		if ( zz[i].sum > mx1.sum )
			{
				if ( zz[i].ID == mx.ID )
				continue;
			mx1 = zz[i];
			}
	}
		cout<<mx1.ID<<' '<<mx1.sum<<endl;
		mx1.sum=0;
		mx2 = mx1;
		for ( i = 0 ; i < n ; i ++ )
	{
		if ( zz[i].sum > mx2.sum )
			{
				if ( zz[i].ID == mx.ID || zz[i].ID == mx1.ID)
				continue;
			mx2 = zz[i];
			}
	}
		cout<<mx2.ID<<' '<<mx2.sum<<endl;
}


struct student{
	int no;
	int ch;
	int math;
	int sum;
	struct student *next;
};

struct student *creat(long n)
{
	long i;
	struct student *head, *p,*q;
	head=(struct student *)malloc(len);
	p=(struct student *)malloc(len);
	head->next=q=p;
	scanf("%d %d %d",&p->no, &p->ch,&p->math);
	p->sum=(p->ch)+(p->math);

	for(i=1;i<n;i++)
	{
		p=(struct student *)malloc(len);
		scanf("%d %d %d",&p->no, &p->ch,&p->math);
		p->sum=(p->ch)+(p->math);
		q->next=p;
		q=p;
		p->next=NULL;
	}
//	for(p=head->next;p!=NULL;p=p->next)printf("%d %d",p->no,p->sum);
	return(head);
}

void sort(struct student *head)
{
	struct student *p,*q1,*q2,*q3;
	int m1,m2,m3;
	for(p=head->next,m1=p->sum;p!=NULL;p=p->next)
		if(p->sum>m1){m1=p->sum;q1=p;}
	printf("%d %d\n",q1->no,q1->sum);
	for(p=head->next,m2=p->sum;p!=NULL;p=p->next)
		if(p->sum>m2 && p!=q1){m2=p->sum;q2=p;}
	printf("%d %d\n",q2->no,q2->sum);
	for(p=head->next,m3=p->sum;p!=NULL;p=p->next)
		if(p->sum>m3 && p!=q1 && p!= q2){m3=p->sum;q3=p;}
	printf("%d %d\n",q3->no,q3->sum);
}

int main()
{
	long n;
	struct student *head;
	scanf("%d",&n);
	head=creat(n);
	sort(head);
	return 0;
}


int main()
{
	int n;
	cin>>n;
	struct student
	{
		int ID;
		int chinese;
		int math;
		int total;
	}score[100000];
	for(int i=0;i<n;i++)
	{
		cin>>score[i].ID>>score[i].chinese>>score[i].math;
		score[i].total=score[i].chinese+score[i].math;
	}
	for(int i=0;i<3;i++)
		for(int j=n-1;j>0;j--)
			if(score[j].total>score[j-1].total)
			{
				struct student temp=score[j];
			    score[j]=score[j-1];
			    score[j-1]=temp;
			}
	if(n==2)
			for(int i=0;i<n;i++)
				cout<<score[i].ID<<score[i].total<<endl;
	else {
	for(int i=0;i<3;i++)
		cout<<score[i].ID<<' '<<score[i].total<<endl;
	}
}


struct student
{
	int num;
	int chi;
	int mat;
	int all;
	struct student *next;
}
main()
{
	struct student *head,*p1,*p2,*p;
	long n,i;
	int j,max;
	scanf("%d",&n);
	p1=p2=(struct student*)malloc(LEN);
	scanf("%d%d%d",&p1->num,&p1->chi,&p1->mat);
	p1->all=p1->chi+p1->mat;
	head=p1;
	for(i=1;i<n;i++)
	{
		if(i>1)
			p2->next=p1;
		p2=p1;
		p1=(struct student*)malloc(LEN);
		scanf("%d%d%d",&p1->num,&p1->chi,&p1->mat);
		p1->all=p1->chi+p1->mat;
	}
	p2->next=NULL;
	for(j=0;j<3;j++)
	{
		p=p1=head;
		max=p->all;
		while(p->next!=NULL)
		{
			p2=p;
			p=p->next;
			if(p->all>max)
			{
				max=p->all;
				p1=p2;
			}
		}
		printf("%d %d\n",p1->next->num,p1->next->all);
		if(max==head->all)
			head=head->next;
		else
			p1->next=(p1->next)->next;
	}
}


struct student
    {
           int id;
           int ch;
           int math;
    };
int main()
{
    int max(int *p,int n);
    void shuchu(int *p,int n,int k,struct student student[100001]);
    struct student student[100001];
    int n,i,*p,k;
    p=(int *)calloc(100001,sizeof(int));
    scanf("%d\n",&n);
    for(i=0;i<n;i++)
    {
                    scanf("%d %d %d",&student[i].id,&student[i].ch,&student[i].math);
                    (*(p+i))=(student[i].ch+student[i].math);

    }
    k=max(p,n);
    shuchu(p,n,k,student);
    k=max(p,n);
    shuchu(p,n,k,student);
    k=max(p,n);
    shuchu(p,n,k,student);

    return 0;
}

int max(int *p,int n)
{
    int k=0,i;
    for(i=0;i<n;i++)
    {
                    if((*(p+i))>k)
                    k=(*(p+i));
    }
    return (k);
}

void shuchu(int *p,int n,int k,struct student student[100001])
{
     int i;
     for(i=0;i<n;i++)
     {
                     if((*(p+i))==k)
                     {

                                   printf("%d %d\n",student[i].id,k);
                                   (*(p+i))=0;
                                   break;
                     }
     }
}


int main() {
	struct stu{
		int xh;
		int yw;
		int sx;
		int zf;
	}data[100000];
	int n,i,max,x,j;
	scanf ("%d",&n);
	for(i=0;i<n;i++) {
		scanf("%d %d %d",&data[i].xh,&data[i].yw,&data[i].sx);
		data[i].zf=data[i].yw+data[i].sx;
	}
	for(i=0;i<3;i++) {
		max=data[0].zf;
		x=0;
		for(j=1;j<n;j++) {
			if(data[j].zf>max) {
				max=data[j].zf;
				x=j;
			}
		}
		printf("%d %d\n",data[x].xh,data[x].zf);
		data[x].zf=0;

	}
}


struct student
{
	int num;
	int yuwen;
	int math;
	int total;
};
int main()
{
	int n,i,j;
	struct student stu[4],temp;
	scanf("%d",&n);
	for(i=0;i<3;i++)
	stu[i].total=0;
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&stu[3].num,&stu[3].yuwen,&stu[3].math);
		stu[3].total=stu[3].yuwen+stu[3].math;
		temp=stu[3];
		for(j=2;j>=0;j--)
		if(temp.total>stu[j].total)
		{
			stu[j+1]=stu[j];
			stu[j]=temp;
		}
		else
		{
			stu[j+1]=temp;
			break;
		}
	}
	for(i=0;i<3;i++)
	printf("%d %d\n",stu[i].num,stu[i].total);
	return 0;
}