semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
 int n,a[100][21],i,j;
 scanf("%d",&n);
 for(i=0;i<n;i++)
  {
   scanf("%d",&a[i][0]);
   for(j=1;j<=a[i][0];j++)
    scanf("%d",&a[i][j]);
  }
 for(i=0;i<n;i++)
  for(j=0;j<=a[i][0];j++)
   {
    if(a[i][0]==0)
     {printf("60\n"); break;}
     else if(a[i][j]+3*(j-1)>=60) 
       {printf("%d\n",60-3*(j-1)); break;}
       else if(a[i][j]+3*j>=60) 
        {printf("%d\n",a[i][j]); break;}
        else if(a[i][j]+3*j<60&&j==a[i][0])
         {printf("%d\n",60-3*j); break;}
    }
 return 0;
}
int main()
{
	int n,a[10][10],i,j,s,p,m;
	cin>>n;
	for(i=0;i<n;i++)
	{
		p=0;
		    cin>>a[i][0];
			for(j=1;j<=a[i][0];j++)
		    {
			   cin>>a[i][j];
		     }
			if(a[i][0]!=0)
		    {for(j=1;j<=a[i][0];j++)
		     {
			   p=a[i][j]+3*j;
			   if(p>63)
				   {
					   p=a[i][j-1]+3*j-3;
					   if(p>=60)
						   s=3-(p-60)+3*(j-2);
					   else
						   s=3*(j-1);
				   break;
			   }
			   else
				   if(p>=60)
					   s=3-(p-60)+3*(j-1);
				   else
				   s=3*j;
			}
			   m=60-s;
			   cout<<m<<endl;
	        }
		   else
			  cout<<"60"<<endl;
	}
	return 0;
}
int main()
{
	int i,j,n,A[100],m,B[100],k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		B[i]=0;
		scanf("%d",&m);
		if(m==0)
		{
			B[i]=60;
		}
		else{
			for(j=0;j<m;j++)
			{
				scanf("%d",&A[j]);
			}
			if(A[0]>=60)
			{
				B[i]=60;
			}
			else if(A[m-1]+3*m<=60)
			{
				B[i]=60-3*m;
			}
			else if(A[m-1]+3*m-3<=60)
			{
				B[i]=A[m-1];
			}
			else
			{
				for(k=1;k<m;k++)
				{
					if(A[k]+3*k<=60)
					{
						B[i]=A[k];
					}
					else{
						if(A[k-1]+3*k<60)
						{
							B[i]=60-3*k;
							break;
						}
						else{
					    B[i]=A[k-1];
						break;
					}
				}
			}
		}
	}
	}
	for(i=0;i<n;i++)
	{
		printf("%d\n",B[i]);
	}
	return 0;
}
int main()
{
    int m,n,i,j,a[10000],sum;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&m);
        if(m==0)
            printf("60\n");
        if(m!=0)
        {
            sum=0;
            for(j=0;j<m;j++)
            {
                 scanf("%d",&a[j]);
            }
                 sum=a[m-1]+3*m;
            if(sum<=60)
                printf("%d\n",(60-3*m));
            if(sum>60)
            {
                for(j=0;j<m;j++)
                {
                    if((a[j]+3*(j+1))<60&&(a[j+1]+3*(j+1))>=60)
                    {
                         printf("%d\n",(60-3*(j+1)));
                         break;
                    }
                    if((a[j]+3*(j+1))>=60&&(a[j]+3*(j+1))<=63)
                    {
                         printf("%d\n",a[j]);
                         break;
                    }
                }
            }  
        }
    }  
    scanf("%d",1); 
    return 0;
    }
//?????????
//20101116 ??
int main()
{
	int n,pause[20],ps[20][20],sum[20],i,j;//pause[]???????ps[][]????????????sum[]??60??????
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>pause[i];                                      //??????????
			for(j=1;j<=pause[i];j++)
				cin>>ps[i][j];                          //???????????
	}
	for(i=1;i<=n;i++)
	{
		if(pause[i]==0)     sum[i]=60;                           //????????60
		for(j=1;j<=pause[i];j++)        
		{   
		    if(ps[i][pause[i]]+3*pause[i]<=60)  sum[i]=60-3*pause[i];         //????          
				else if((ps[i][j]+3*j<60)&&(ps[i][j+1]+3*j>60))
				sum[i]=60-3*j;
			else if((ps[i][j]+3*j<60)&&(ps[i][j+1]+3*j<=60)&&(ps[i][j+1]+3*j+3>=60))
				sum[i]=ps[i][j+1];
		}
	cout<<sum[i]<<endl;               //??
	}
return 0;
}
int main()
{
	int n,m[99];               //???????
	int i,j,k,p,q;           //????
	int num[99][19],sum[99];   //num[i][j]:?i????j?????????  sum[i]:?i????????????
	scanf("%d", &n);
	for(i=0;i<n;i++)          //???????
	{
		scanf("%d", &m[i]);
		for(j=0;j<m[i];j++)
			scanf("%d", &num[i][j]);
	}

	for(k=0;k<n;k++)           //?????????
	{
		if(m[k]==0)            //???????0
		{
			sum[k]=60;         //?????60
		}
	    else                   //????????0
		{
			int l;
			l=m[k]-1;          
			if(num[k][l]+3*l<=57)   //???????????????????????3???57??????57??
				sum[k]=60-3*m[k];          //????????????????
			else if(57<num[k][l]+3*l && num[k][l]+3*l<=60)   //???????????????????????3???58??60?
				sum[k]=num[k][l];          //?????????????????
			else                           //??????????????1??
			{
				//printf("??1\n");
				for(q=l;q>=0;q--)          //???????????
				{
					//printf("%d\n", q);
					if(num[k][q]+3*q<=57)
					{
						//printf("??1\n");
						sum[k]=60-3*(q+1);
						//printf("%d", sum[k]);
						break;
					}
					else if(57<num[k][q]+3*q && num[k][q]+3*q<=60)
					{
						//printf("??2\n");
						sum[k]=num[k][q];
						//printf("%d", sum[k]);
						break;
					}
					else;
				}
			}	
		}
	}	


	for(p=0;p<n;p++)
		printf("%d\n", sum[p]);

	return 0;
}
int main(){
    int n,sa[100000],sb[10000],i,j,x;
    scanf("%d",&n);
   
    for(i=0;i<n;i++){
           
            scanf("%d",&x);
           
            for(j=0;j<x;j++){scanf("%d",&sa[j]);}
            sb[i]=60;
            for(j=0;j<x;j++){
                    sb[i]-=3;
                    if(sb[i]-sa[j]<=0&&sb[i]-sa[j]>=-3){sb[i]=sa[j];break;}
                    else if(sb[i]-sa[j]<0){sb[i]=sb[i]+3;break;}
                    if(sb[i]-sa[j]>0){continue;}
                    }
            }
            for(i=0;i<n;i++){
                    printf("%d\n",sb[i]);
                    }
    
    return 0;
}
int main(){
	int n,m,i,j;
	scanf("%d",&n);
	int a[n],b[N];
	b[0]=0;
	for(i=0;i<n;i++){
		scanf("%d",&m);
		for(j=0;j<m;j++)
			scanf("%d",&b[j]);
		for(j=0;j<m;j++){
			b[j]+=(j+1)*3;
			if(b[j]>60)
				break;
		}
		if(j==m-1&&b[j]<=60)
			a[i]=b[j]-j*3;
		else if(b[j]>60&&b[j]<=63)
			a[i]=b[j]-(j+1)*3;
		else
			a[i]=60-j*3;
	}
	for(i=0;i<n;i++)
		printf("%d\n",a[i]);
	return 0;
}
int main()
{
	int n;
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
	{
		int sum;
		scanf("%d",&sum);
		if(sum==0){printf("60\n");continue;}
		int j,k,a[20];
		for(j=0;j<sum;j++)
		{
			scanf("%d",&a[j]);
		}
		for(j=1;j<=sum;j++)
		{
			if(j!=sum)
			{
				if(a[j-1]+j*3<60&&a[j]+(j+1)*3>=60)
				{
					if(a[j-1]+j*3<=a[j])
					{printf("%d\n",60-j*3);break;}
					else
					{printf("%d\n",a[j]);break;}
				}
			}
			else
			{
				printf("%d\n",60-j*3);
			}
		}
	}
	return 0;
}
int main(){
  int i,j,k,h,n,c,t,y,a[70],b[30];
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&h);
    for(j=0;j<h;j++){
      scanf("%d",&a[j]);
    }
    c=0;
    t=1;
    while(t<=60){
      c++;
      y=0;
      for(j=0;j<h;j++){
        if(c==a[j]){
          t+=4;
          y=1;
          break;
        }
      }
      if(y==0){
        t++;
      }
  
    }
    b[i]=c;
  }
  for(i=0;i<n;i++){
    printf("%d\n",b[i]);
  }
  
return 0;




}
int main()
{
 int n=0;
 cin>>n;
 for(int k=0;k<n;k++)
 {
  int m=0,number=0,temp=0;
 int a[100]={0};
 a[0] = 60;
 cin>>m;                        //???????
 for(int i=1;i<=m;i++)          //???????????
  cin>>a[i];                        //??????????????????????
 for(int i=0;i<=m;i++)
 {
      temp=a[m-i]+3*(m-i);
      if(temp<=60)                             //?m-i???????
      {
       number=60-3*(m-i);
       cout<<number<<endl;break;
      }
      else if(temp>60&&temp<=63)
      {
           cout<<a[m-i]<<endl;break;
      }
           
 }
}
}
int main()
{
    int a;int i,j,m,n,k;
    scanf("%d",&a);
    int time;int times[a];
    int jump[30][30];
    for(i=0;i<a;i++)
    {
        times[i]=60;
        scanf("%d",&m);
        for(j=0;j<m;j++)
            scanf("%d",&jump[i][j]);
        for(k=0;k<m;k++)
        {
            if(jump[i][k]>=times[i]) times[i]+=3;
            else if(times[i]-jump[i][k]==1) times[i]+=2;
            else if(times[i]-jump[i][k]==2) times[i]+=1;
            times[i]-=3;
        }
    }

    for(i=0;i<a;i++)
        printf("%d\n",times[i]);
    return 0;
}
int main(){
	int m[1000],a[1000][30],i,j,b,c=0,n;
	scanf("%d",&n);

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

	for(i=0;i<n;i++){
            j=0;
		for(b=1;b<=60;b++){
			c++;
		   if(c==a[i][j]){
			   b+=3;
			   j++;
		   }
		}
		printf("%d\n",c);
		c=0;
	}

	return 0;
}
struct jumps
{
	int error,c[100],sum,xia;
};

int main()
{
	struct jumps jump[100];
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d ",&jump[i].error);
		for(j=0;j<jump[i].error;j++)
		{
			scanf("%d ",&jump[i].c[j]);
		}
	}
	for(i=0;i<n;i++)
	{
		if(jump[i].c[jump[i].error-1]+jump[i].error*3<60)
			jump[i].xia=60-jump[i].error*3;
		else 
		{
			for(j=0;j<jump[i].error;j++)
			{
				if(jump[i].c[j]>=47&&jump[i].c[j]<=49)
				{
					jump[i].xia=jump[i].c[j];
					break;
				}
				else if(jump[i].c[j]+(j+1)*3>60&&jump[i].c[j-1]+(j)*3<60)
				{
					jump[i].xia=60-(j)*3;
					break;
				}
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%d\n",jump[i].xia);
	}
	return 0;
}
int main()
{
    int time,n,m,i,j,k,a[61];
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    { scanf("%d",&m);
      for(j=1;j<=m;j++) scanf("%d",&a[j]);
      k=1; time=0;
      for(j=1;j<=60;j++) 
	  { 
           time++;
           if(time==a[k])
                         {k++;j=j+3;}
         }
	  for(j=1;j<=m;j++) a[j]=0;
       printf("%d\n",time);
    }
return 0;
}
void print(int a[],int m,int k,int n);
int main()
{
	int n,a[500],m,j,i=1,k=0;
	cin>>n;
	while(i<=n)
	{
		cin>>m;
		k++;
		if(m==0)
		{
			if(k!=n)
			{
				cout<<60<<endl;
			}
			else
			{
				cout<<60;
			}
			i++;
		
		continue;
		}

		for(j=1;j<=m;j++)
		{
			cin>>a[j];
		}
	    print(a,m,k,n);
		i++;
	}
  return 0;
}
void print(int a[],int m,int k,int n)
{

   
	    if(a[m]+3*m<60)
		{
			if(k!=n)
			{
				cout<<(60-3*m)<<endl;
			}
			else
			{
				cout<<(60-3*m);
			}
		}
		else if(a[m]+3*m>=60&&a[m]+3*m<=62)
		{
			if(k!=n)
			{
				cout<<a[m]<<endl;
			}
			else
			{
				cout<<a[m];
			}
		}

		else
		{
		   print( a, m-1,k,n);
		}
}
int main(){
   int n,i,j,m,h,k;
   int s[30]={0};
   scanf("%d",&h);
 for(k=0;k<h;k++){
   scanf("%d",&n);
   if(n!=0){
   for(i=0;i<n;i++){
    scanf("%d",&s[i]);}
   if(s[n-1]+(n-1)*3<60&&s[n-1]+n*3<=60){
    m=60-n*3;}
	else { 
	   for(j=0;j<n;j++){
	       if(s[j]+j*3<=60&&s[j]+(j+1)*3>=60){
			     m=s[j];break;}else if(s[j]+j*3>60){m=60-j*3;break;}}}
	printf("%d\n",m);}else{ printf("60\n");}}
	return 0;
	}
int main(){
 int i,n,j,k,f;
 int sz[100];
 int sz2[100][100];

 for(i=0;i<100;i++)
 {
	 for(j=0;j<100;j++)
	 {
	 sz2[i][j]=1;
	 }
 }
	 scanf("%d",&n);
 for(k=0;k<n;k++)
 {	int t=0;
	 scanf("%d",&f);
	 for(i=0;i<f;i++)
	 scanf("%d",&sz[i]);
   for(j=0;j<f;j++)
   {
		   sz2[k][sz[j]+t*3]=0;
	       sz2[k][sz[j]+1+t*3]=0;
          sz2[k][sz[j]+2+t*3]=0;
		  t++;
   }  
}
 
for(k=0;k<n;k++)
{  int p=60;
 for(i=0;i<60;i++)
{
if(sz2[k][i]==0)
{
	p--;
}
}
printf("%d\n",p);
}
return 0;
}
int main()
{
int n;
cin>>n;
while(n-->0)
{
	int stop,num[60],beat=60;
	cin>>stop;
	for(int i=0;i<stop;i++)
	{
		cin>>num[i];
	}
	for(int i=0;i<stop;i++)
		if(num[i]+3*(i+1)<=60)
					beat=60-3*(i+1);
				else if(num[i]+3*i>=60) {
					beat=beat=60-3*(i);
					break;
				}
				else {
					beat=num[i];
					break;
				}
	cout<<beat<<endl;
}
return 0;
}
void main()
{
int n;
int i,j,k;
scanf("%d",&n);
int m=0,h=0,p=0;
int a[60][60];
int b[60][60];
for(j=0;j<n;j++){
scanf("%d",&a[j][0]);
for(i=1;i<=a[j][0];i++){
scanf("%d",&a[j][i]);
}
}

for(j=0;j<n;j++){
if(a[j][0]==0){
printf("60\n");
}
else if(a[j][0]!=0){
h=a[j][0];
for(i=1;i<=h;i++){
b[j][i]=a[j][i]+3*i;
}
for(k=1;k<=h;k++){
if(b[j][k]>63){
b[j][k]=0;
}
}

for(p=h;p>=1;p--){
if((b[j][p]==63)||(b[j][p]==62)||(b[j][p]==61)){
printf("%d\n",a[j][p]);
break;
}
else if(b[j][p]<=60&&b[j][p]!=0){
m=60-3*p;
printf("%d\n",m);
break;
}
}
}
}


}
int main()
{
    int d,c,n,m,i,j,k,a[20],b[100];
	cin>>n;
    for(i=0;i<n;i++)
		{cin>>m;
	    if(m==0) {b[i]=60;continue;}//??????????60?
		for(j=0;j<m;j++)
		    {cin>>a[j];}//??????????(??????)
		if(a[m-1]<=(60-m*3))//?????????????????????×3??????
		    {b[i]=(60-m*3);}
		else 
			 {if(m==1) b[i]=c;
			 else{{for(k=m-1;;k--)
			 if(a[k]+(k+1)*3<=60) break;}//????????????(???3s??60s?)?????
		      c=60-((k+1)*3);//c????????3s??60s?????
			  if(c<=a[k+1]) b[i]=c;
			  else b[i]=a[k+1];}}//???3s???????????60s?,60s???????????????????
	       }
	  for(i=0;i<n;i++) cout<<b[i]<<endl;
	return 0;
}
int main(){
    int n,m,a,b,zongshu[1000];
    scanf("%d",&n);
    for(a=0;a<n;a++){
        scanf("%d",&m);
        if(m==0){
            printf("60\n");
            continue;
        }
        for(b=1;b<=m;b++){
            scanf("%d",&zongshu[b]);
        }
        for(int k=m;k>=0;k--){
            if((zongshu[k]+3*k)<=60){
                printf("%d\n",60-3*k);
                break;
            }
            else if((zongshu[k]+3*k-3)<=60){
                printf("%d\n",zongshu[k]);
                break;
            }
            else continue;
        }
    }
    return 0;

          }
int main(){                               //???
	int n;
	cin>>n;                     //n????
	while(n>0){               //while???????????
		int m;                     //?????
		cin>>m;
		if(m==0)cout<<60<<endl;
		else {
			int count[m];             //????????????????????
			for(int i=0;i<m;i++)
				cin>>count[i];               //??
			while(1){
			if(count[m-1]+3*m<=60){
				cout<<60-3*m<<endl;     //?????????????????
				break;
			}
			if(count[m-1]+3*m>=63){     //????????????????
				m--;
				continue;
			}
			else {
				cout<<60-3*m+(count[m-1]+3*m-60)<<endl;   //??????????
				break;
			}
		}
		}
		n--;
	}
	return 0;                   //?????????????????
}
int main()
{
	int counts[16] = {0}, n, m, i, j, flag, time;
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		flag = time = 0;
		cin >> m;
		if (m == 0)
		{
			cout << 60 << endl;
			time = 60;
		}
		for (j = 1; j <= m; j++)
		{
			cin >> counts[j];
		}
		for (j = 1; j <= m; j++)
		{
			flag += counts[j] - counts[j - 1];
			time += counts[j] - counts[j - 1];
			if (time >= 60)
			{
				cout << flag - time + 60 << endl;
				break;
			}
			time += 3;
			if (time >= 60)
			{
				cout << flag << endl;
				break;
			}
		}
		if (time < 60)
		{
			cout << flag - time + 60 << endl;
		}
	}
	return 0;
}
int main()
{int n,i,j;
 cin>>n;
 for(i=1;i<=n;i++)
 {int m,a[10]={0},flag=1;
  cin>>m;
  for(j=0;j<m;j++)
     cin>>a[j];
  for(j=0;j<m&&flag;j++)
   if((60-3*j-a[j])<=3)
      flag=0;
  if(!flag)
	if((60-3*(j-1)-a[j-1])>=0)
	  cout<<a[j-1]<<endl;
    else cout<<(60-3*(j-1))<<endl;
  else cout<<(60-3*m)<<endl;
 }
 return 0;
}
int main()
{
    int n,i,j,a[100],m,b[100];

    scanf("%d",&n);

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

       scanf("%d",&m);

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

       for(j=m-1;j<m;j--){
           if((60-a[j]-3*j)>0){
				break;
		   }
	   }

       if((60-a[j]-3*j)<4){
          b[i-1]=a[j];
	   }
       else{
		  b[i-1]=57-3*j;
	   
          }

	}
	   for(i=1;i<=n;i++){
		   printf("%d\n",b[i-1]);
       }
      return  0;
}
int main()
{
    int people;
    cin>>people;
    int num=0;
    while(true)
    {
        int badjump[20]={0};
        int n;
        cin>>n;
        for(int i=0;i<=n-1;i++)
        {
            cin>>badjump[i];
        }
        int realtime;
        int realjump=0;
        int j=0;
        for(realtime=1;;realtime++)
        {
            realjump++;
            if(realtime==3*j+badjump[j])
            {
                realtime+=3;
                j++;
            }
            if(realtime>=60)break;
        
        }
        cout<<realjump<<endl;
        
        num++;
        if(num==people)break;
    }
    return 0;
}
int main()
{
	
    int n,fail_n,fail[60],i,k,a,x,b;
	cin>>n;
	
    for(i=0;i<n;i++)
	
    {
		x=0;
	  cin>>fail_n;
	
        for(k=0;k<fail_n;k++)  cin>>fail[k];

        for(k=0;k<fail_n+1;k++)
		{   

			a=0;b=0;
			if(fail[k]+3*(k+1)>60&&fail[k]+3*k<60) {b=1;break;}
			if(fail[k]+3*(k+1)<=60)  a=1;
			else {a=2;x=fail[k-1]+3*(k);break;}
		 
		}
        
	    if(b==1) cout<<fail[k]<<endl;

		if(a==1) cout<<60-3*fail_n<<endl;
		if(a==2) cout<<fail[k-1]+(60-x)<<endl;

		
	  
	  
 }
	
   return 0;
}
int main()
{
	int n, m, i , j, current, lost;
	cin >> n;
	for( i = 0; i < n; i++)
	{
		cin >> m;
		lost = 0;
		for (j = 0; j < m; ++j)
		{

			cin >> current;
			if ((lost + current) < 60 )
			{
				if( 60 - current - lost > 3)
				lost += 3;
			    else
				lost = 60 - current ;
			}
		}
		cout << 60 - lost << endl;
	}
	return 0;
}
int main(){
	int a,b,n,m,p[100],i,j;
	scanf("%d",&n);
	for(j=0;j<n;j++)
	{
		scanf("%d",&m);	
		for(i=0;i<m;i++)
		{
			scanf("%d",&p[i]);
		}	
		if(m==0)
			printf("60\n");
		else
		{
			a=p[m-1]+m*3;
			if(a<=60)
				printf("%d\n",(60-a)+p[m-1]);
		    else if(a>60&&a<=63)
			    printf("%d\n",p[m-1]);
		    else{
			    for(i=m-1;i>=0;)
				{
					b=p[i]+(i+1)*3;
			        if(b<=60)
					{
						printf("%d\n",(60-b)+p[i]);
						break;
					}
			        else if(b>60&&b<=63)
					{
						printf("%d",p[i]);
						break;
					}
				    else
						i--;
				}
			}
		}
	}
	return 0;
}
int s(int);
int main()
{
	int n, k;
	cin >> n;
	while(n--)
	{
		cin >> k;
		cout << s(k) << endl;
	}
	return 0;
}
int s(int k)
{
	int i, j, a[15], total = 0;
	for(i = 0; i <= k - 1; i++)
		cin >> a[i];
	int t = 0;
	for(i = 0; i <= k - 1; i++)
	{
		if(t < 60)
			t = a[i] + 3 * (i + 1);
		else
			break;
	}
	j = i - 1;
	if(t <= 60) //t<=60????????????
		total = 60 - 3 * (j + 1);
	else 
	{
		if(a[j] + 3 * j > 63)
			total = 60 - 3 * j;
		else
			total = a[j];
	}
	return total;
}
void main()
{
	int m,n,t,j,i,s=60,a[1000];
	scanf("%d",&t);
	for(j=0;j<t;j++)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		if(60>=(a[n-1]+3*n)) printf("%d\n",60-3*n);
		else {
			for(i=0;i<n;i++)
		{
			if(s>a[i]) 
			{s=s-3;
			if(s<a[i]) 
			{s=a[i]; break;}}
			if(s<a[i]) 
			{s=60-3*i;break;}
		}
			printf("%d\n",s);
		}
		s=60;
	}

}
int main()
{int n,i,p,z,m,sum=0,lum=0,kum=0;
int duan[1000]={0};
int cishu[50][100];
	scanf("%d",&n);
for(i=0;i<n;i++)
{scanf("%d",&duan[i]);
	for(p=0;p<duan[i];p++)                                       
	{scanf("%d",&cishu[i][p]);}
}
for(z=0;z<n;z++)
{   if (duan[z]==0)
	{printf("60\n");}
else {
	for(m=1;m<=duan[z];m++)
		{if ((m*3+cishu[z][m-1])<=60)
			{if (m==duan[z])
				{lum=60-3*m;
				printf("%d\n",lum);}
				else continue;
			}
		if (((m*3+cishu[z][m-1])>60)&&((m*3-3+cishu[z][m-1])<=60))
			{printf("%d\n",cishu[z][m-1]);}
		if (((m*3+cishu[z][m-1])>60)&&((m*3-3+cishu[z][m-1])>60))
			{kum=60-m*3+3;
			printf("%d\n",kum);break;} 
		}
	}

}
return 0;
}
int main(){
	int N,M,Lose,i,j;
	//????N????M?????
	int Times[101],Bad[101];
	//????Times???Bad??
	cin>>N;
	//????
	for(i=1;i<=N;i++){
		//??????
		Lose=0;
		//?????????
		cin>>M;
		//??????
		for(j=1;j<=M;j++){
			//??
			cin>>Times[j];
			//??????
			if(Lose==0){
				//????????
			if((Times[j]+j*3)>=60){
				//???????????????????????
				if((Times[j]+3*(j-1)>=60))
					//???????????
					Bad[i]=60-3*(j-1);
				//???????60????????
				else//??
					Bad[i]=Times[j];
				//????????????
				Lose=1;
				//??????
			}
			}
		}
		if(M==0)
			//??????
			Bad[i]=60;
		//???60?
		else if((Times[M]+3*M)<=60)
			//????????????
			Bad[i]=60-3*M;
		//????????
	}
	for(i=1;i<=N;i++){
		//????
		cout<<Bad[i];
		if(i!=N)
		    cout<<endl;
	}
	return 0;
	//????
}
int main(){
	int n,m,sz[100],i,result;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&m);

		if(m==0)
			printf("60\n");

		else{
			for(i=0;i<m;i++){
				scanf("%d",&sz[i]);
			}

			if(sz[m-1]+3*(m)<=60){
				result=60-(sz[m-1]+3*(m))+sz[m-1];
				printf("%d\n",result);
			}

			else if(sz[m-1]+3*m>60&&sz[m-1]+3*m<=63)
				printf("%d\n",sz[m-1]);

			else {
				for(i=m-2;i>=0;i--){
					if(sz[i]+3*(i+1)<=60){
						printf("%d\n",60-(sz[i]+3*(i+1))+sz[i]);
						break;}
					if(sz[i]+3*(i+1)>60&&sz[i]+3*(i+1)<=63){
						printf("%d\n",sz[i]);
						break;}
				}
			}


		}
	}
	
	return 0;
}
int main()
{
	int n,p,q,i,l,a[50],t;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		t=1;
		scanf("%d",&p);
		for(l=0;l<p;l++)
		{
			scanf("%d",&q);
			if(q+3*l<60&&(q+3*(l+1))>=60&&t) {a[i]=q;t=0;}
			if(q+3*l>=60&&t) {a[i]=60-3*l;t=0;}
			if(l==p-1&&q+3*(l+1)<60&&t) {a[i]=60-3*(l+1);t=0;}
		}
		if(p==0) a[i]=60;
	}
	for(i=0;i<n;i++) printf("%d\n",a[i]);
	return 0;
}
int main()
{
    int n,m,x,t;
    int a[N];
    int i,j;

    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&m);
        a[i]=0;
        t=0;
        for(j=0;j<m;j++)
        {
            scanf("%d",&x);
            x=x-a[i];
            if(t+x>=60)
            {
                a[i]=a[i]+60-t;
                t=60;
            }
            else if(t+x<60&&t+x+3>=60)
            {
                t=60;
                a[i]=a[i]+x;
            }
            else if(t+x+3<60)
            {
                t=t+x+3;
                a[i]=a[i]+x;
            }

        }

        a[i]=a[i]+(60-t);
    }

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

    return 0;
}
int main()
{
    int i,j,n,m,a,total=0,b;
    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);
					if(total<60)
                    {total=a+3*j;
                    b=j;
					}
                    }
                    if(total<=62&&total>=60)
                    {total-=3*b;
                   
                    }
                    else if(total<60)
                    {total=60-3*m;
                    
                    }
                    else
                    {total=60-3*(b-1);
                    
                    }
                    printf("%d\n",total);
					}
    }

	return 0;
}
int main()
{
    int m,n,i,j,N[60],sum;
    cin>>n;
    for(j=0;j<n;j++)
    {
        cin>>m;
        if(m==0)
        cout<<60<<endl;
        else
        {
        for(i=0;i<m;i++)
        cin>>N[i];
        i=m-1;
        while(N[i]+3*i>60)
        i--;
        if(N[i]+3*(i+1)>60)
        sum=N[i];
        else
        sum=60-3*(i+1);
        cout<<sum<<endl;
    }
    }
    return 0;
}
int main()
{
int n, interuptCount, currentNum, sec, lostTime ;
const int maxSeconds = 60;
cin >> n;
for (int i = 0; i < n; ++i)
{ cin >> interuptCount;
lostTime = 0; 
for (int j = 0; j < interuptCount; ++j)
{ cin >> currentNum;
sec = currentNum + lostTime; 
if (sec < maxSeconds)
if ((maxSeconds - sec) > 3)
lostTime += 3;
else
lostTime += maxSeconds - sec;
}
cout << maxSeconds - lostTime << endl;
} 
	return 0;
}
int main()
{
    int n;
    scanf("%d",&n);
    int num[n];
    int sum[n];
    int sz[n][1000];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num[i]);
        if(num[i]!=0)
        {
        	for(int j=0;j<num[i];j++)
        	{
            	scanf("%d",&sz[i][j]);
            }
            if(sz[i][num[i]-1]+3*num[i]<=60)
            {
                sum[i]=60-3*num[i];
            }
            else if(sz[i][num[i]-1]+3*(num[i]-1)<=60)
            {
                sum[i]=sz[i][num[i]-1];
            }
            else if(sz[i][num[i]-2]+3*(num[i]-1)<=60)
            {
                sum[i]=60-3*(num[i]-1);
            }
            else if(sz[i][num[i]-2]+3*(num[i]-2)<=60)
            {
                sum[i]=sz[i][num[i]-2];
                        
            }
            else if(sz[i][num[i]-3]+3*(num[i]-2)<=60)
            {
                sum[i]=60-3*(num[i]-2);
            }
            else if(sz[i][num[i]-3]+3*(num[i]-3)<=60)
            {
                sum[i]=sz[i][num[i]-3];
                        
            }
        }
        else sum[i]=60;
        printf("%d\n",sum[i]);
    }
}
int main()
{
	int n, m, num[100] = {0}, i, j, time;              //????n, m, num[100], i, j, time
	cin >> n;										   //????????
	for (i = 0; i < n; i++)							   //??????????????????
	{
		cin >> m;
		for(j = 0; j < m; j++)
			cin >> num[j];
		for(j = 0; j < m; j++)						   //?????????????
		{
			time = num[j] + j * 3;
			if ((time >= 57) && (time <= 60))		   //????????????
			{
				cout << num[j] << endl;
				break;
			}
			if (time > 60)							   //??????????????
			{
				num[j] = num[j] - (time - 60);
				cout << num[j] << endl;
				break;
			}
		}
		if (j == m)									   //?????????????????
		{
			num[j] = 60 - j * 3;
			cout << num[j] << endl;
		}
	}
	return 0;
}