semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
	int n,i,j;
	struct{
		int m,x[10],t[10],s;            //t???s?60?????
	}a[100];
	scanf("%d",&n);
	for(i=0; i<n; i++)
	{
		scanf("%d",&a[i].m);
		for(j=0; j<a[i].m; j++)
			scanf("%d",&a[i].x[j]);
	}

	for(i=0; i<n; i++)
	{
		if(a[i].m==0)
		{
			a[i].s=60;
			printf("%d\n",a[i].s);
		}
		else
		{
			if(a[i].x[a[i].m-1]+a[i].m*3<=60)
			{
				a[i].s=60-3*a[i].m;
				printf("%d\n",a[i].s);
			}
			else
			{
				for(j=a[i].m-1; a[i].x[j]+(j+1)*3>=60; j--){}  //j=4
				if(a[i].x[j+1]+3*(j+1)>=57 && a[i].x[j+1]+3*(j+1)<=60)
					printf("%d\n",a[i].x[j+1]);
				else{
                    a[i].s=60-3*(j+1);
				    printf("%d\n",a[i].s);
				}
			}
		}
	}
	return 0;
}
int N, Total, Time, PNum, Stop;
inline int Max(int x, int y)
{ return (x > y ? x : y); }
int main()
{
	cin >> N;
	for (int i = 0; i < N; i ++)
	{
		cin >> Stop;
		if (Stop == 0) {cout << "60" << endl; continue;}
		Total = 0; Time = 60;
		for (int j = 0; j < Stop; j ++)
		{
			cin >> PNum;
			if (Time - PNum - 3 * j >= 0) 
			{
				Total = PNum;
				if (Time - PNum - 3 * j > 3)
				Total += Time - PNum - 3 * (j + 1);
			}
		}
		cout << Total << endl;		
	}
	return 0;
}
int main()
{
	int n,num;
	cin>>n;//??n????????
	int i=1;
	for(i=1;i<=n;i++)//????????????
	{
		int m;
		cin>>m;//??????????
		int a[60];//??????
		if(m==0)cout<<"60"<<endl;//??????????????60
		else{
			int j=1;
			for(j=1;j<=m;j++)
			{
				cin>>a[j];
				if((a[j]+3*j)>=60&(a[j]+3*j)<=63)num=a[j];
				else if(((a[j-1]+3*(j-1))<60)&(a[j]+3*j)>63)num=(63-3*j);
				else if((a[j]+3*j)<60){num=(60-3*j);continue;}/*??????????????????????????????????????????????????*/
			}
			cout<<num<<endl;//
		}
	}
}
int main()
{
	int n=0,a[100][15];
	cin >>n;
	for(int i=0;i<n;i++)
	{
		cin >>a[i][0];
		for(int j=1;j<=a[i][0];j++)
			cin >>a[i][j];
	}
	for(int i=0;i<n;i++)
	{
		if(a[i][0]==0)
			cout <<60 <<endl;
		else
		{
			int num=a[i][a[i][0]]+a[i][0]*3;
			if(num<=60)
				cout <<60-3*a[i][0] <<endl;
			else if(num<=63)
				cout <<a[i][a[i][0]] <<endl;
			else
			{
				int j=1;
				for(j=1;j<=a[i][0];j++)
				{
					num=a[i][j]+j*3;
					if(num>=60&&num<=63)
					{
						cout <<a[i][j] <<endl;
						break;
					}
					else if(num>63)
					{
						cout <<63-j*3<<endl;
						break;
					}
				}
			}
		}
	}
	return 0;
}
int main(){
	int i,u,num,n,a[100],b[100][100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		num=a[i]*3;
		for(u=0;u<a[i];u++){
			scanf("%d",&b[i][u]);
			if(u*3+b[i][u]>59){
				num-=3;
			}
			if(u*3+b[i][u]==59){
				num-=2;
			}
			if(u*3+b[i][u]==58){
				num-=1;
			}
		}
		printf("%d\n",60-num);
	}
	return 0;
}
int main()
{
	int a[21];
	int m,n,j,i,sum,sum1;
	scanf("%d",&m);
	for(j=1;j<=m;j++){
	scanf("%d",&n);
	sum=sum1=0;
	for(i=1;i<=20;i++)
	{
		a[i]=0;
	}
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=1;i<=20;i++)
	{
		if((a[i]<=60-(i-1)*3)&&a[i]!=0)
		{
			sum=a[i];
			sum1=a[i]+3*i;
		}
		if(a[i]==0)
		{
			sum=sum+60-sum1;
			sum1=60;
		}
		if(sum1>=60)
		{
			break;
		}
	}
	if(n==0)
	{
		printf("60\n");
	}
	else
	{
		printf("%d\n",sum);
	}
	}
	return 0;
}
int main()
{
	int n,a[60][60],b[60],i,j,c[60],d[600],e[600];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&b[i]);
		c[i]=0;
		e[i]=0;
		for(j=0;j<b[i];j++)
		{
			scanf("%d",&a[i][j]);
			if(a[i][j]+3*j<58)c[i]++;
			if(a[i][j]+3*j<61&&a[i][j]+3*j>57)e[i]=60-a[i][j]-3*j;
		
		}
		d[i]=60-3*c[i]-e[i];
	}
	for(i=0;i<n;i++)
	{
		printf("%d\n",d[i]);
	}
	
	return 0;
}
int main()
{
	int n,m,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		int*sum=(int*)malloc(sizeof(int)*20);
		scanf("%d",&m);
		if(m==0) 
		{
			printf("60\n");
			continue;
		}
		for(j=0;j<m;j++)
		{
			scanf("%d",&sum[j]);
			sum[j]+=3*(j+1);
		}
		for(j=m-1;j>=0;j--)
		{
		    if(sum[j]>=63) continue;
			else if(sum[j]<=60) 
			{
				printf("%d\n",60-(j+1)*3);
				break;
			}
		    else if(sum[j]==61) 
			{
				printf("%d\n",58-j*3);
				break;
			}
		    else if(sum[j]==62) 
			{
				printf("%d\n",59-j*3);
				break;
			}
		}
		free(sum);
	}
	return 0;
}
//***********************
//*???????********
//*??????**********
//*???1000012832******
//***********************
int main()
{
	int n,	i;//???? n ?????????
	cin	>>	n;
	for(i	=	1;	i	<=	n;	i	++)//??????
	{
		int m,	x[100]	=	{0},	j;//???????
		cin	>>	m;
		if(m	==	0)//???0????????60
		{
			cout	<<	60	<<	endl;
			continue;
		}
		else//??
		{
			for(j	=	0;	j	<	m;	j	++)//???????m???
			{
				cin	>>	x[j];
			}
			for(j	=	0;	j	<	m;	j	++)//????
			{
                
				if(x[j]	<	60)
				{
					if(x[j]	+	3	*	(j	+	1)	>=	60)//???????60????????????????60?????????
					{ 
						cout	<<	x[j]	<<	endl;
						break;
					}
					else if(3	*	(j	+	1)	+	x[j	+	1]	>=	60)//?????60????????????????????60????60??????
					{
						cout	<<	60	-	3	*	(j	+	1)	<<	endl;
						break;
					}
				}
			}
			if(j	==	m)//???????j==m???????????????60??????
			{
				cout	<<	60	-	3	*	m	<<	endl;
			}
		}
	}
	return 0;
}
int main()
{
    int n,i,j;
    int m,a,a0,time,result,k;
    //freopen("test2.in","r",stdin);
    scanf("%d",&n);
    
    for(i=0;i<n;i++)
    {
    	scanf("%d",&m);
    	time=0;
    	a0=0;
    	for(j=1;j<=m;j++)
    	{
	    	scanf("%d",&a);
	    	time=time+(a-a0)+3;//a-a0??????????????????????????????3????????????3???? 
	    	if(time>=60)
	    	{
	    		for(k=j+1;k<=m;k++)//??for ???????????????????????????? 
	    			scanf("%d",&a);
	    	    break;	
	    	}
 	        a0=a;
	    }
	    if(time<60)//?j<=m?????? 
	    {
    		result=60-3*m;//???????????????????3??????1???60?????60?????????m????????3*m?? 
    	}
    	else
    	{
	    	if(time==60)//?j????????j?????3???????60??????????????????????60????????60-j*3? 
	    	{
	    		result=60-j*3;
	    	}
	    	else
	    	{
	    		if(time-3<=60)//?j????60????????????3????????60?? 
	    		{
		    		result=time-3-(j-1)*3;//?j?????????????????????j-1???????? 
		    	}
	    		else result=60-(j-1)*3;//?j??????????60??? 
	    	}
	    }
	    printf("%d\n",result);
    }
	return 0;
}
int main() 
{ 
int n,m,a,b,i,j;

scanf("%d",&n);
for(i=0;i<n;i++)
{
   scanf("%d",&m);
   b=0;
   for(j=0;j<m;j++)
   {
      scanf("%d",&a);
       if(a+b<60)
       if(a+b+3<60)
        b+=3;
       else
        b=60-a;
   }
   printf("%d\n",60-b);
}
return 0; 
}
void main()
{
	int n, i, m, j, score[60], sum;
	scanf("%d", &n);
	
	for(i=0;i<n;i++){
		
		scanf("%d", &m);
		for(j=0;j<m;j++){
			scanf("%d", &score[j]);			
		}	
	    sum=0;					
	    if(m==0){
		   sum+=60;
		}
		else if(m!=0){
			for(j=0;j<m;j++){
			    sum=0;				
				if(score[j]+3*j>=60){
			       sum+=60-(3*j);
				   break;
				}
				else{
				   if(score[j]<=45){
				   sum+=60-(3*m);
				   }			   
				   else if(score[j]>45){
				   sum+=score[j];					   
				   break;
				   }
				}
			}
		}
		printf("%d\n", sum);
	}
}
int main()
{   int m,n,i,j,t=0;
    int a[500];
	scanf("%d",&m);
	for(j=1;j<=m;j++){
		for(i=0;i<500;i++){
			a[i]=0;
		}
		scanf("%d",&n);
		if(n==0){
			printf("60\n");
		}
		else{
			for(i=0;i<n;i++){
				scanf("%d",&a[i]);
			}
			for(i=0;i<n;i++){
				if(a[i]+3*(i+1)>60){
					t=1;
					if(a[i]+3*i<60){
						printf("%d\n",a[i]);
					}
					else{
						printf("%d\n",60-3*i);
					}
					break;
				}
			}
			if(t==0){
				printf("%d\n",60-3*n);
			}
			t=0;
		}
	}
	return 0;
}
int main()
{
	int n,m,t[60],i,j,p[1000]={0},a,ms;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&m);
		if(m==0){
			p[i]=60;
		}else{
		for(j=0;j<m;j++){
			scanf("%d",&t[j]);
		}
		for(j=0;j<m;j++){
			ms=t[j]+3*j;
			if(ms>=60){
				
				p[i]=60-3*j;
				break;
			}
			else if(ms<60&&ms>57){
				p[i]=60-(3*j+60-ms);
				break;
			}else{
				p[i]=60-(3*(j+1));
			}
		}
		}
	}
	for(i=0;i<n;i++){
		printf("%d\n",p[i]);
	}
	
	return 0;

}
void main()
{
	int m,n,i,j,k;
	int count,a[60];
	int time;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		count=0;
		scanf("%d",&m);
		for(j=0;j<m;j++)
			scanf("%d",&a[j]);
		for(k=1;k<=60;k++)
		{
			time=1;
			for(j=0;j<m;j++)
			{
				if(k==a[j])
				{
					time=4;
					break;
				}
			}
			count+=time;
			if(count>=60)
				break;
		}
		printf("%d\n",k);
	}
}
int main(int argc, char* argv[])
{
    int n,i,j,pause,t,number[60],total;
	scanf("%d",&n);
	for (j=0;j<n;j++)
	{
		scanf("%d",&pause);
		if (pause==0)
		{
			total=60;
		}
		else
		{
			for (i=1;i<=pause;i++)
			{
				scanf("%d",&number[i]);
			}
			for (i=1;i<=pause;)
			{
				t=number[i]+3*(i-1);
				if (t+3<60)
				{   total=57-3*(i-1);
					i=i+1;
				}
				if (t<60&&t+3>=60)
				{
					total=number[i];
					break;
				}
				if (t>=60)
				{
					total=63-3*i;
					break;
				}
			}
		}
		printf("%d\n",total);
	}
	
	return 0;
}
int main()
{
    int n;
    int a[100], num;
    int i, j;

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

    return 0;
}

int comp(int a[], int num)
{
    int i, re = 0;
    for (i=0; i<num; i++) {
        re = 3*(i+1) + a[i];
        if ((re>60) && ((re-3)<60)) /* not jump in 60 */
            return a[i];
        else if (re > 60) /* jumped in 60 */
            return 60 - 3*i;
    }
    if (re <= 60)
        return 60-3*i;
}
int main()
{
    int n, m, i, j, t, a[20];
	cin >> n;
	for(i = 1; i <= n; i++)
	{
		cin >> m;
			for(j = 0; j < m; j++)
				cin >> a[j];
			for(j = 0; j < m; j++)
			{
				t = a[j] + 3 * (j + 1);
				if(t > 60 && t < 63)
				{
					cout << a[j] << endl;
					break;
				}
				else
					if(t >= 63)
					{
						cout << 60 - 3 * j << endl;
						break;
					}
					else
						continue;
				if(t > 60)
					break;
			}
			if(j == m)
				cout << 60 - 3 * m << endl;
	}
    return 0;
}
int main()
{
	int n ;
	cin>>n ;
	for(int i = 0;i<n;i++)
	{
		int m,a[20];
		cin>>m;
		if(m==0)
			cout<<"60"<<endl;
		else if(m!=0)
		{
		for(int k = 0 ; k<m ; k++)
		{
			cin>>a[k];
		}
		for(int j=m ; j>=1 ; j--)
		{
			if((a[j-1]+3*j)>=63)
				continue ;
			else if((a[j-1]+3*j)<=60)
			{
				cout<<(60-3*j)<<endl;
				break;
			}
			else 
			{
				cout<<a[j-1]<<endl;
				break;
			}
		 }
		}
	}
	return 0 ;
}
int main ()
{
    int n,m;
    int i,j;
    int a[201];
    a[0]=0;
    int b[201];
    int sum,c,d;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
		            sum=0;
                    scanf("%d",&m);
                    if(m==0){b[i]=60;}
                    if(m!=0)
					{
						for(j=1;j<=m;j++)
						{
                                         scanf("%d",&a[j]);
                        }
                        for(j=1;j<=m;j++)
						{
							c=a[j];
							d=a[j-1];
							sum=a[j]+3*j-3;
							if(sum<60)continue;
							else break;
						}
						if(sum<=60&&sum>=57)b[i]=c;
						else if(sum<57)b[i]=57-sum+c;
						else if(sum>60&&sum-(c-d)<=63&&sum-(c-d)>=60)b[i]=d;
						else if(sum>60&&(sum-(c-d))<60)b[i]=c-sum+60;
					}
	}
	for(i=0;i<n;i++){printf("%d\n",b[i]);}
	return 0;
}
int main()
{ 
int n0,i0;
cin>>n0;
for(i0=0;i0<n0;i0++)
{
int time=0,a[100]={0},i,n,s;
cin>>n; 
if(n==0)
{cout<<60<<endl;continue;} 
for (i=0;i<n;i++)
cin>>a[i]; 
for(i=0;i<n;i++)
{  if(a[i]+3*time<60) time++;
   else break;}
if(a[i-1]+3*time<60)
{s=60-3*time;
cout<<s<<endl;
continue; 
} 
if(a[i-1]+3*(time-1)<60)
{ s=60-3*time+a[i-1]+3*time-60;}
else 
{s=60-3*time;}
cout<<s<<endl;            
} 

return 0; 
}
int main(){
int n,m,i,j,a[20],s,t;
scanf("%d",&n);
for(i=0;i<n;i++){
s=60;
scanf("%d",&m);
if(m!=0){
for(j=0;j<m;j++) scanf("%d",&a[j]);
for(j=0;j<m;j++){
t=a[j]+3*j+3;
if(t>62) break;
else if(t==62){s-=1;break;}
else if(t==61){s-=2;break;}
else s-=3;}}
printf("%d\n",s);}
return 1;}
int main(){
	int n,i,t,p,j;
	int a[1000][30];
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i][0];
		for(j=1;j<a[i][0]*2;j=j+2)
			cin>>a[i][j];
		for(j=2;j<=a[i][0]*2;j=j+2)
			a[i][j]=3;
		for(j=j-3;j>=3;j=j-2)
			a[i][j]=a[i][j]-a[i][j-2];
		for(j=1,t=0;j<=a[i][0]*2;j++){
			t=t+a[i][j];
			if(t>60){
				if(j<=a[i][0]*2)
					j--;
				break;  //??????
                }
		}
		if((j%2==0&&t>60)||t<=60)
			cout<<60-(j/2)*3<<endl;
		else if(j%2==1&&t>60){
			for(p=1,t=0;p<j+1;p=p+2)
				t=a[i][p]+t;  //????
			cout<<t<<endl;
		}
	}
}
int main()
{
	int n, m, a[60];
	cin >> n;
	for(int i=0; i < n; i++)
	{
		cin >> m;
		if(m == 0)
		{
			cout<<60<<endl;
		}
		else
		{
			for(int j=0; j < m; j++)
			{
				cin >> a[j];
			}
			for(int k=m-1; k >= 0; k--)
			{
				if(a[k]+3*(k+1) <= 60)
				{
					cout<<a[k]+60-a[k]-3*(k+1)<<endl;
					break;
				}
				else
				{
					if(a[k]+3*k <= 60)
					{
						cout<<a[k]<<endl;
						break;
					}
					else
					{
						continue;
					}
				}
			}
		}
	}
	return 0;
}
int main()
{
int num,m,i,time[21],count[21];
cin>>num;
while(cin>>m)
{
	if(m==0)                                   //????m?1
		cout<<60<<endl;
	else if(m==1)
	{
	cin>>time[1];
	if(time[1]<=57)
		cout<<57<<endl;
	else if(time[1]>60)
		cout<<60<<endl;
	else 
		cout<<time[1]<<endl;
	}
	else
	{
     for(i=1;i<=m;i++)
     {
		 cin>>count[i];
		 time[i]=count[i]+3*i;
	 }
     if(time[m]<60)
	 {
	 cout<<60-3*m<<endl;
	 
	 }
	 else
	 {
	 i=1;
	 while(i<=m)
	 {
	 if(time[i]>=60)
	 {   
	 if(60-time[i-1]>count[i]-count[i-1])
		 cout<<count[i]<<endl;
	 else
		 cout<<60-time[i-1]+count[i-1]<<endl;
	 break;
	 }
	 else
		 i++;
		 
	 }
	 }
	 
	    
	}
}	 
return 0;
	 
}
int main()
{
	int n,m[100],i,j,sum,c[100][20];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&m[i]);
		for(j=1;j<=m[i];j++)
		{
			scanf("%d",&c[i][j]);
		}
	}
	for(i=0;i<n;i++)
	{
		if(m[i]==0)
			printf("60\n");
		if(m[i]==1)
		{
			if(c[i][1]<=57)
			    printf("57\n");
			if(c[i][1]>57)
				printf("%d\n",c[i][1]);
		}
		if(m[i]>1)
		{
			if((c[i][m[i]]+3*(m[i]))<=60)
			{
				sum=60-3*m[i];
				printf("%d\n",sum);
			}
			else if((c[i][m[i]]+3*(m[i]))<=63)
			{
				printf("%d\n",c[i][m[i]]);
			}
			else if((c[i][m[i]]+3*(m[i]))>63)
			{
				if((c[i][m[i]-1]+3*(m[i]-1))<60)
				{
					sum=60-3*(m[i]-1);
				    printf("%d\n",sum);
				}
		        else if((c[i][m[i]-1]+3*(m[i]-1))<63)
				{
		    	  	printf("%d\n",c[i][m[i]-1]);
				}
				else if((c[i][m[i]-1]+3*(m[i]-1))>63)
				{
					if((c[i][m[i]-2]+3*(m[i]-2))<60)
					{
					    sum=60-3*(m[i]-2);
				        printf("%d\n",sum);
					}
		            else if((c[i][m[i]-2]+3*(m[i]-2))<63)
					{
		        	  	printf("%d\n",c[i][m[i]-2]);
					}
				}
			}
		}
	}
	return 0;
}
int main()
{
	int j=0,n, m, y[100], a[63], b[10];
	for (int t=0;t<63;t++)
		a[t]=1;
	
	for (int s=0;s<10;s++)
		b[s]=0;
	scanf("%d", &n);
	for(int i=0;i<n;i++)
	{    y[i]=0;
		scanf("%d", &m);
		for( j=0;j<m;j++)
		{
			scanf("%d", &b[j]);
		
		
			a[b[j]+3*j+1] = 0;
			a[b[j]+2+3*j] = 0;
			a[b[j]+3*j] = 0;
		}
		for(int k=0;k<60;k++)
		{
			y[i] += a[k];
		}
	
	
		for (int t=0;t<63;t++)
		a[t]=1;
	for (int s=0;s<10;s++)
		b[s]=0;
		
	}
	for (int l=0;l<n;l++)
		printf("%d\n",y[l]);
	return 0;
}
int main()
{
    int k,n;
    scanf("%d",&n);
    for(k=1;k<=n;k++)
    {
                     int m,a[100],i,j;               
                     scanf("%d",&m);
                     if(m!=0)
                     {
                        for(i=1;i<=m;i++)
                        {
                                scanf("%d\n",&a[i]);
                        }
                        for(j=1;j<=m;j++)
                        {
                                         if(j<m)
                                         {
                                                if((a[j]+3*j<=60)&&(a[j+1]+3*j>=63))
                                                {
                                                 printf("%d\n",60-3*j);
                                                 break;
                                                 }
                                                 else if(a[j]+3*j==61||a[j]+3*j==62)
                                                 {
                                                 printf("%d\n",a[j]);
                                                 break;
                                                 }
                                         }
                                         else 
                                         {
                                              if(a[j]+3*j<60)
                                              {
                                              printf("%d\n",60-3*j);
                                              break;
                                              }
                                               else if(a[j]+3*j==63||a[j]+3*j==61||a[j]+3*j==62)
                                               {
                                               printf("%d\n",a[j]);
                                                break;
                                                }
                                         }
                        }
                     }
                        else printf("60\n");
  }
}
int main()
{
	int n,i,m,j;
	int data;
	scanf("%d",&n);
	for( i = 1; i <= n; i++ )
	{
		int sum = 0;
		int flag = 1;
		int num = 0;
		scanf("%d",&m);
		for( j = 1; j <= m ; j++ )
		{
			scanf("%d",&data);
			if( data + num >= 60 && flag )
			{
				sum = 60 - num;
				flag = 0;
			}
			num += 3;
			if( data + num >= 60 && flag)
			{
				sum = data;
				flag = 0;
			}

		}
		if( sum == 0 )
			sum = 60 - num;
		printf("%d\n",sum);

	}
	return 0;
}
int main()
{
	int n,m,a,b,t,x,c,d;
	int z[1000];
	scanf("%d",&n);
	for(a=0;a<=n-1;a++)
	{
		scanf("%d",&m);
		for(b=0;b<=m-1;b++)
		{
			scanf("%d",&z[b]);
		}
		if(m==0)
		{
			printf("60\n");
		}
		
		else
		{
		    t=60;x=0;c=0;d=0;
	    	while(t>0)
			{
			    t--;
				if(d==0)
				{
					if(c<m)
					{
					if(x==z[c]-1) 
					{
						d=3;
						c++;
					}
					}
					x++;
				}
				else d--;
			}
			printf("%d\n",x);
		}
		
	}
	return 0;
}
int main()
{
	int n,i,j,k,l,q,m=0;
	int time[10]={0};
	int t=0;
	int sum=0;
	int a[100]={0};
	scanf("%d",&n);
	for(q=0;q<=n-1;q++)
	{
		scanf("%d",&k);
		for(j=0;j<=k-1;j++)
		{
			scanf("%d",&a[j]);
		}
		if(k==0)
		{
			printf("%d\n",60);
		}
		else
		{
			for(i=0;i<=k-1;i++)
			{
				t=a[i]+3*i;
				if(t>=60)
				{
					m++;
					l=i-1;
					break;
					
				}
			}
			if(m==0) 
			{
				if((a[k-1]+3*k)<60)
				{
				sum=60-3*k;
				}
				if((a[k-1]+3*k)>=60)
				{
					sum=a[k-1];
				}
			printf("%d\n",sum);
			}
			else{
			if((a[l]+(l+1)*3)<=60)
			{
				sum=60-3*(l+1);
				printf("%d\n",sum);
			}
			if((a[l]+(l+1)*3)>60)
			{
				printf("%d\n",a[l]);
			}
			}
			m=0;
			t=0;
			sum=0;
			l=0;
		}
	}

	return 0;
}
//******************************************
//*???????.cpp                     **
//*??: ??     1100012808              **
//*???2011.12.17                       **
//******************************************
int main()  //???
{        //?????
	int n, j, m, i, a[200], t[200] = {0};
	cin >> n;
	for (j = 0; j < n; j++)
	{
		cin >> m;
		memset (t, 0, sizeof(t));
		if (m == 0)
			cout << 60 << endl;
		for (i = 0; i < m; i++)
		{
			cin >> a[i];
			t[i] = a[i] + (i + 1) * 3 + 1;
		}
		for (i = 0; i < m; i++)
		{
			if ((t[i] <= 60 && t[i + 1] > 60) || (t[i] <= 60 && t[i + 1] == 0))
			{
				if (t[i + 1] == 61 || t[i + 1] == 62 || t[i + 1] == 63)
				{
					cout << a[i + 1] << endl;
					break;
				}
				else
					cout << 60 - 3 * (i + 1) << endl;
			}
		}
	}
	return 0;
} //?????
int main()
{
	int n;
	scanf("%d",&n);
	int i=1;
	while(i<=n){
		int sz[50];
		int m;
		int j;
		if(i!=1){
		    	printf("\n");
			}
		scanf("%d",&m);
		
		if(m==0){
			printf("60");
		}else{
			
		    for(j=0;j<m;j++){
		    	scanf("%d",&sz[j]);
			}
			
	    	sz[m]=60;

	    	int count=sz[0]+3;
	    	int num=sz[0];
		    for(j=1;j<=m;j++){
			    if(count+3+sz[j]-num<=60){
				    count+=3+sz[j]-num;
		     		num=sz[j];
				}else{
			    	if(count-num+sz[j]<=60){				    	
					    num=sz[j];
				        break;
					}
			    	else{
		    			num=num+60-count;
						
			    		break;
					}
				}
			}

	    	
	        printf("%d",num);
		}
	    	i++;
	}
	return 0;
}
int main()
{
	int n;
    scanf("%d",&n);
	int i=0, j=0, f_num, result=0, score[20];
	for (i=0; i<n ;i++){
		scanf(" %d", &f_num);
		if (f_num==0){
			result=60;
		}
		else{
			for (j=0; j<f_num; j++){
		      scanf(" %d", &score[j]);
			  if (score[j]<= 60-3*f_num){
				  if (score[j]>= 60-3*(f_num+1)){
                      result=score[j];
				  }
				  else{
					  result= 60-3*f_num;
				  }
			  }
			  else{
				if (score[j-1]>= 60-3*(f_num- 1) && score[j-1]<= 60-3*(f_num-2)){
				result= score[j-1];
				}
				else{
				   if (score[j]<= 60-3*(f_num-1) && score[j]>=60-3*f_num){
			           result= score[j];
				   }
			       else{
					   if (score[j-1]>=60-3*(f_num-1)){
						   result= 60- 3*(f_num-2);
					   }
					   else{
						   result= 60- 3*(f_num- 1);
					   }
					   
				   }
				}
			  }
			}
		}
        printf("%d\n", result);
	}
	return 0;
}
int main()
{
	int i,c,j,k,num[100],n,timess=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&c);
		for(j=0;j<c;j++)
		{
			scanf("%d",&num[j]);
		} 
		if((num[c-1]+3*c)<=60)
		{
			timess=60-c*3;
			printf("%d\n",timess);
		}
        else 
		{
			for(k=1;k<=c;k++)
			{
		        if((num[k-1]+3*k)<=63&&(num[k-1]+3*k)>60)
				{
					timess=num[k-1];
		            printf("%d\n",timess);
					break;
				}
		        else if((num[k-1]+3*k)>63) 
				{
					timess=60-(k-1)*3;
					printf("%d\n",timess);
					break;
				}
			}
		}
		timess=0;
	}
	return 0;
}
main()
{
	  int m,a[100],n,i,j,t,p,q;
	scanf("%d",&n);
	for(j=0;j<n;j++)
	{
	
  
    scanf("%d",&m);
    for(i=0;i<m;i++)
      { scanf("%d",&a[i]);}
    
       
       	t=m*3+a[m-1];
       	p=(m-1)*3+a[m-2];
       	q=(m-2)*3+a[m-3];
       	if(t<=60)
       	{printf("%d\n",a[m-1]+(60-t));}
       	else if(t>60&&p<=60&&(a[m-1]-a[m-2])>=(60-p))
       	{printf("%d\n",a[m-2]+(60-p));}
        else if(t>60&&p<=60&&(a[m-1]-a[m-2])<(60-p))
        {printf("%d\n",a[m-1]);}
       	else if(p>60&&q<=60&& (a[m-2]-a[m-3])>=(60-q)  )
       	{printf("%d\n",a[m-3]+(60-q));}
       	else if(p>60&&q<=60&& (a[m-2]-a[m-3])<(60-q))
       	{printf("%d\n",a[m-2]);}
          
       
	}
	return 0;
}
int main()
{   int a[20]={0},b[100]={0};
    int i,j,m,n,k;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>m;
		if(m==0)
			b[i]=60;
		else{
		for(j=0;j<m;j++)
		   cin>>a[j];
        for(j=0;j<m;j++){
			k=a[j]+3*j;
			if(k<57 && j==m-1){
				    b[i]=60-3*m;
					break;
			}
			else{ if(k>=57 && k<=60){
					    b[i]=a[j];
				        break;
			}
			else if(k>60){
					        b[i]=60-3*j;
				            break;
				}
				
			 
		}
			
	}
	}
	}
	for(i=0;i<n;i++)
		cout<<b[i]<<endl;
					

	return 0;
}
int main()
{
	int m,n,a[10],i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&m);
		if(m==0)
		{
			printf("60\n");
		}
		else
		{
			for(j=1;j<=m;j++)
			{
				scanf("%d",&a[j]);
			}
			if(a[m]+3*m<=60)
				printf("%d\n",60-3*m);
			else
			{
			    for(j=1;j<=m;j++)
				{
					if(a[j]+3*j>60)
					{
						if(a[j]+3*j<=63)
						{
							printf("%d\n",a[j]);
						    break;
						}
						else
						{
							printf("%d\n",63-3*j);
							break;
						}
					}
				}

			}
		}
	}
	return 0;
}
int main()
{
	int n;
	int m,i,j;
	int t,tp;
	cin>>n;
	while(n--)//?????
	{
		tp=0;
		t=0;
		j=0;
		cin>>m;//??????
		if(m)
			for(i=1;i<=m;i++)//??60????????????
			{
				tp=t;
				cin>>t;
				if(t+3*i-3>=60)
				{
					t=tp;
					if(j==0)
						j=i-1;//60?????
				}
			}
		else
		{
			cout<<60<<endl;//???????60
			continue;
		}
		if(j==0)
			j=i-1;
		if(t+3*j-3<=57)
			cout<<60-3*j<<endl;//???????????60?
		else
			cout<<60+t%3-3*j<<endl;//??
	}
	return 0;
}
int main()
{
	int n;
	scanf("%d",&n);
	int i,j;
	for(i=0;i<n;i++)
	{
		int m,sum=60;
		scanf("%d",&m);
		for(j=0;j<m;j++)
		{
			int a;
			scanf("%d",&a);
			if(a<(sum-3))
			{
			    sum -= 3;
			}
			else if(a>=(sum-3)&&a<=sum)
			{
				sum=a;
			}
		}
			printf("%d\n",sum);
	}
	return 0;
}
int main()
{
	int n,i,e,t[50],m[50][50],max[50],num[50];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&t[i]);
		for(e=0;e<t[i];e++)
		{
			scanf("%d",&m[i][e]);
		}
	}
	for(i=0;i<n;i++)
	{
		num[i]=60-3*t[i];
		for(e=0;e<t[i];e++)
		{
			if((m[i][e]+3*e)>=57&&(m[i][e]+3*e)<=60)
			{
				num[i]=m[i][e];
				break;
			}
			if((m[i][e]+3*e)>60)
			{
				t[i]=e;
				num[i]=60-3*t[i];
				break;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%d\n",num[i]);
	}
	return 0;
}