semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
//
//	????:	????
//	????:	??????????????
//	????:	?  ? ( ? ?: 1000012733 ) 
//	????:	2010 ? 11 ? 27 ?
//
int main()
{
	int n, i, j, amount;								//?????????????:??n??????????,amount????????????????????,i?j?????
	int times[20][10];									//??????times??????????????????????
	int m[20];											//????????m??????????????
	cin >> n;											//???????????????n
	for ( i = 0; i < n; i ++ )
	{
		cin >> m[i];									//?????????i+1??????????
		for ( j = 0; j < m[i]; j ++ )
		{
			cin >> times[i][j];							//???????????????????????????
		}
	}
	for ( i = 0; i < n; i ++ )
	{
		if ( m[i] == 0 )
			cout << "60" << endl;						//????????????,??????60
		else
		{
			for ( j = m[i] - 1; j >= 0; j -- )
			{
				if (( times[i][j] + 3 * j >= 57 ) && ( times[i][j] + 3 * j <= 60 ))
				{
					cout << times[i][j] << endl;
					break;
				}										/*????j+1??????????,??????,????????????????57?(?????????????),
														??????????.*/
				else if ( times[i][j] + 3 * j < 57 )
				{
					amount = 60 - 3 * ( j + 1 );
					cout << amount << endl;
					break;
				}										/*???????????????57?,????????????????,?????????????????????
														??????????*/
			}
		}
	}
	return 0;
}
int main()
{   int n,i,k,a,time,all,ans,alltime;
    scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a);
		alltime=60; ans=0; time=0;
		for(k=1;k<=a;k++){
			scanf("%d",&all);
            if(all+k*3<=60){ time=all+k*3;
			    ans=all;
			}
			if(all+k*3==61) alltime=alltime-2;
             if(all+k*3==62) alltime=alltime-1;
		}
		ans=ans+(alltime-time);
		printf("%d\n",ans);
	}
	return 0;
}
int main()
{
	int n,m;
	cin>>n;
	int i,j,l,s;
	int a[70];
	while(n--)
	{
		memset(a,0,sizeof(a));a[0]=100;
		m=0;s=0;j=0;
		cin>>l;
		for(i=0;i<l;i++)
			cin>>a[i];
		while(m<60)
		{
			if(s==a[j])
			{
				m=m+3;j=j+1;
			}
			else
			{
				s=s+1;m=m+1;
			}
		}
		cout<<s<<endl;
	}
	return 0;
}
//**********************************
//????????????
//???2013.10.19
//**********************************
int main()
{
	 int n=0,i=0,j=0,a[100],b[20],sum=0,q=0;
	 cin>>n;
	 for(i=0;i<n;i++)
	 {
		 cin>>a[i];
		 if(a[i]>0)
		{
		       for(j=1;j<=a[i];j++)
		      {
			        cin>>b[j];
				  if(b[j]+j*3<=60)
				  {  sum=60-3*j;  }
				  if(b[j]+j*3<=63&&b[j]+j*3>60)
				  {   sum=b[j];  }
			   }
		 }
		 if(a[i]==0)
		 {
			 sum=60;
		 }
		 cout<<sum<<endl;
	  }
   return 0;
}
int main()
{
	int time,x[20]={0};
	int n;
	int i,j,k;
	int tmpa,tmpb;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		tmpa=0;
		tmpb=0;
		time=0;
		for(j=0;j<=19;j++)
		{
			x[j]=0;
		}
		scanf("%d",&time);
		if(time==0)
		{
			printf("60\n");
			continue;
		}
		else
		{
			for(j=0;j<=time-1;j++)
			{
				scanf("%d",&x[j]);
			}
			for(j=19;j>=0;j--)
			{
				if(x[j]==0) continue;
				if(x[j]+3*(20-j)>=60) continue;
				if(x[j]+3*(20-j)<60) 
				{
					tmpb=57-(x[j]+3*(20-j));
					tmpb+=x[j];
					printf("%d\n",tmpb);
					break;
				}
			}
		}
	}
	return 0;
}
/*
 * review_7.cpp
 *
 *  Created on: 2010-12-27
 *      Author: ???
 *        ??? ????
 */



int main(){
	int n,m,i,j,a[50];
	cin>>n;
	for(i=0;i<n;i++){
		cin>>m;
		if(m==0){                              //????????????60
			cout<<60<<endl;
			continue;
		}
		for(j=0;j<m;j++)
			cin>>a[j];
		for(j=0;j<m;j++)                       //???????????????
			if(a[j]+3*j<=60)
				if(j+1==m||a[j+1]+3*(j+1)>60)
					if(a[j]+3*(j+1)>=60)
						cout<<a[j]<<endl;
					else
						cout<<60-3*(j+1)<<endl;
	}
	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};
   cin>>m;                        //???????
   for(int i=1;i<=m;i++)          //???????????
    cin>>a[i];
   temp=a[m]+3*m;                 //??????  
   if(temp<=60)                    //????60???
   {
     number=60-3*m;
     cout<<number<<endl;
   }
   else if(temp>60&&temp<=63)        //????60?63?
      cout<<a[m]<<endl;
   else                           //??????????????????????
           for(int i=1;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 n,m,k,c,i,b;
    cin>>n;
    int a[n+1];
    for(i=1;i<=n;i++)
    {
              cin>>m;;
              c=0;
              for(b=1;b<=m;b++)
              {
                        cin>>k;
                        if(c+k<60)
                        if(c+k+3<60)
                        c=c+3;
                        else 
                        c=60-k;
              }
              a[i]=(60-c);
    }
    for(i=1;i<=n;i++)
    {
                     cout<<a[i]<<endl;
    }
    return 0; 
}
int main()
{
	int n;
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
	{
		int leiji;
		scanf("%d",&leiji);


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



		else 
		{
			int j,stop[60];
			for(j=1;j<=leiji;j++)
			{
				scanf("%d",&stop[j]);
			}
			for(j=leiji;j>0;j--)
			{
				int time=stop[j]+3*j;
				int time1=stop[j]+3*j-3;
				if(time1<=60&&time>=60)
					printf("%d\n",stop[j]);
				else if(time<60)
					printf("%d\n",60-3*j);
				if(time1<=60&&time>=60)
					break;
				else if(time<60)
					break;
			}
		}



	}
	return 0;
}
/*               ????
??????         2010.11.24          */

int main()
{
	int n, count2, count1, i, j;
	int stop[30] = {0};
	int num[3000][30] = {0};
	cin >> n;
	count2  =0;
	while(count2 < n)//count2?????????????
	{
		cin >> stop[count2];
		count1 = 0;//count1?????????????
		while(count1 < stop[count2])
		{
			cin >> num[count2][count1];
			count1 ++;
		}
		count2 ++;
	}
	for(i = 0; i < n; i ++)
	{
		for(j = 0; j < stop[i]; j ++)
			if(num[i][j] + 3 * (j + 1) > 60)
				break;//????????
		if(j == stop[i])
			cout << 60 - 3 * stop[i];//?????????????
		else
		{
			if(num[i][j] + 3 * (j+1) > 63)
				cout << 60 - 3 * j;
			else//??????????????
				cout << num[i][j];//??????????
		}
		cout << endl;
	}
	return 0;
}
int main()
{
	int a[100];
	int n,num,i,j,t;
	cin>>n;
	for(j=0,i=0;j<n;j++)
	{
		for(i=0;i<100;i++)
			a[i]=0;
		i=0;
		do
	    {
		    cin>>a[i];i++;
	    }while(cin.get()!='\n');
		t=i-1;
		if(a[t]+a[0]*3>=60)
		{
			for(i=1;i<=t;i++)
			{
				if(a[i]+3*i>=60) break;
		    }
			t=i;
			if(a[i]+3*i-3<=60) num=a[i];
			else {num=a[i]+3*i-3-60;num=a[i]-num;}
		}
		else num=60-3*a[0];
		cout<<num<<endl;
	}
	return 0;
}
int main()
{
	int n, bad, a[100]={0}, i, j, b;
	int all(int bad, int a[100]);
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &bad);
		if(bad==0)
			printf("60\n");
		else{
		for(j=0;j<bad;j++){
			scanf("%d", &a[j]);
		}
			b = all(bad, a);
			printf("%d\n", b);
		}
	}
	return 0;
}
int all(int bad, int a[100])
{
	int i;
	for(i=bad-1;i>=0;i--){
		if(a[i]+3*(i+1)<60)
			return (60-3*(i+1));
		else if(a[i]+3*i<=60&&a[i]+3*i>=57)
			return a[i];
		else
			continue;
	}
}
int main()
{
    int n,i,j,m;
    int a[100],b[100];
    scanf("%d",&n);

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

       scanf("%d",&m);
       if(m==0)
      { printf("6");
       continue;}
      else

       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 n,i,j,m,s,t[60];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&m);
		if(m==0)
			s=60;
		else{
			for(j=0;j<m;j++){
				scanf("%d",&t[j]);
			}
			for(j=0;j<m;j++){
				if(t[j]+3*(j+1)<60){
					s=60-3*(j+1);
				}else if(t[j]+3*j<60){
					s=t[j];
					break;
				}else if(t[j]<60){
					s=60-3*j;
					break;
				}
			}
		}printf("%d\n",s);
	}
	return 0;
}
int main()
{
    int n, i, j, badall, all;
    int total[100]={60};
    scanf("%d", &n);
	j=0;
    for(i=0;i<n;i++)
    {
        scanf("%d", &badall);
		if(badall!=0)
		{
        for(j=0;j<badall;j++)
            scanf("%d", &total[j]);
        for(j=badall-1;j>=0;j--)
        {
            if(total[j]+j*3<=60)
            {
            all = 60 - (j+1)*3;
            if(all<total[j]){
            all=total[j];}
            break;
            }
        }
		}
		else all = 60;
        printf("%d\n", all);
    }
    return 0;
}
//???????
//???2010.11.27
//??????
//???1000012856

int main()
{
	int i, n, k;						//i?k??????n????????
	cin >> n;
	for(i = 1; i <= n; i++)				//??n???
	{
		int j, wrong, w[20];			//j?????wrong?????????????w????????????????
		cin >> wrong;
		for(j = 0; j < wrong; j++)
			cin >> w[j];
		if(wrong == 0)					//????????60
			cout << 60 << endl;
		else							//??????????????????60s?
		{
			//?????????????????60s
			if(w[wrong - 1] + 3 * wrong <= 60)
				//??60-??????????
				cout << 60 - 3 * wrong << endl;
			else
			{
				//??????????
				for(k = wrong - 2; k >= 0; k--)
				{
					//w[k]?????????3*(k+1)??????????????????????60????????60s??
					if((w[k] + 3 * (k + 1) <= 60 ) && (w[k + 1] - w[k] >= 60 - w[k] - 3 * (k + 1))) 
					{
						cout << 60 - 3 * (k + 1) << endl;
						break;
					}
					//????????60s?????????60s??
					else if((w[k] + 3 * (k + 1) <= 60 ) && (w[k + 1] - w[k] < 60 - w[k] - 3 * (k + 1)))
					{
						//??????????????
						cout << w[k + 1] << endl;
						break;
					}
					else
						continue;
				}
			}
		}
	}

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

	}
	return 0;

}
int main(int argc, char* argv[])
{
    int n, i, j, a;
	scanf("%d",&n);	
	for(i=0;i<n;i++)
	{	
		int sum=60;
		scanf("%d",&a);
		for(j=0;j<a;j++)
		{
			int b;
			scanf("%d",&b);
			if(b<(sum-3))
			{
			    sum -= 3;
			}
			else if(b>=(sum-3)&&b<=sum)
			{
				sum=b;
			}
		}
			printf("%d\n",sum);
	}
	return 0;

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

    cin >> n;
    for(i = 1;i<=n;i++)
	{
		cin >> count;
		if(count == 0)cout << "60" << endl;
		else
		{
			for(j = 1; j <= count; j++)
			{
				cin >> a[j];
			}
			
			j = 1;
			while(a[j] + 3 * ( j - 1 ) <= 57 && j <= count)
			{
				j++;
			}
			
			if( a[j] + 3 * (j-1) == 58 || a[j] + 3 * (j - 1) == 59 || a[j] + 3 * (j -1 ) == 60)cout << a[j] << endl;
		    else cout << 60 - 3 * ( j - 1) << endl;
		}
	}

	return 0;
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int c=0;
		int cmc,m,cmc1;
		int time=0;
		int q=0;
		cin>>m;
		if(m==0)
		{cout<<60<<endl;
		continue;}
		for(int j=0;j<m;j++)
		{
			if(q==1)
			{
					cin>>cmc1;
					continue;
			}
			cin>>cmc;
			if(time+cmc>=60&&q!=1)
			{
				cmc=60-time;
				q=1;
			}
			else if(time+cmc>=57&&q!=1)
			{
				q=1;
			}
			if(q==1)continue;
			time=time+3;
		}
		if(q==0)cmc=60-time;
		cout<<cmc<<endl;
	}

	return 0;
}
//*************************************************
//* file: 1000012912_006.cpp                      *
//* author : ???                               *
//* date : 2010.11.24                             *
//* function : ????                           *
//*************************************************
int main()
{
	int n, m, i, j, count[20];                             //n????m?????
	cin >> n;
	for ( i = 0; i < n; i ++ )
	{
		cin >> m;
		if ( m == 0 )
			cout << 60 << endl;
		for ( j = 0; j < m; j ++ )
			cin >> count[j];
		for ( j = m - 1; j >= 0; j -- )
		{
			if ( count[j] + 3 * ( j + 1) <= 60 )             //?60s????
			{ 
				cout << 60 - 3 * ( j + 1) << endl;
				break;
			}
			else  
				if ( count[j] + 3 * ( j + 1 )<= 63 )          //?60s???3s?
				{
					cout << count[j] << endl;
					break;
				}
		}
	}
	return 0;
}
int main()
{
    int n,m,a[10]={0},i,j,k,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {               
                    memset(a,0,sizeof(a));
                    scanf("%d",&m); 
                    for(j=0;j<m;j++)
                    scanf("%d",&a[j]);
                    if(m==0)printf("60\n");
                    else 
                    {
                    for(j=0;j<m;j++)
                         {
                                   if(a[j]+3*(j+1)<60)
                                   {
                                       count=60-3*(j+1);
                                       
                                   }     
                                   else break;
                         }
                         if((a[j]+3*j>=57) && (a[j]+3*j<60))
                         count=a[j];
                         printf("%d\n",count);
                    }
    }
                    return 0;
}
int main()
{
	int a[70],b[70],c[70],i,j,k,l,m,n,times,sum;
	cin>>n;
	for(i=0;i<n;i++)
	{
		for(l=0;l<70;l++)
			a[l]=0,b[l]=0;//??a?????????????????b?????????????//
		cin>>times;//times??????//
		for(j=0;j<times;j++)
			cin>>b[j];
		for(j=1,m=1,k=0;j<=60;j++,m++)//j???????m????????//
		{
			a[j]=1;//??????????????????1.??????0//
			if(m==b[k])
				k++,j=j+3;//????????+3???k+1??????????????b???//
		}
		for(j=1,sum=0;j<=60;j++)
			if(a[j]==1)
				sum++;//?????????????????????//
		c[i]=sum;
	}
	for(i=0;i<n;i++)
		cout<<c[i]<<endl;
	return 0;}
int main()
{
	//int ans = 60;
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i ++){
		//int ans = 60;
		int t;
		int temp = 0;//???? 
		int spe = 0;//???? 
		scanf("%d",&t);
		for(int i = 1;i <= t;i ++){
			int now;
			scanf("%d",&now);
			if(now + temp * 3 < 57){
				temp ++;
			}
			if(now + temp * 3 >= 57 && now + temp * 3 < 60 && spe == 0) spe = 60 - now - temp * 3;
			
		}
		printf("%d\n",60 - temp * 3 - spe);
	}
	return 0;
}
int main(){
	int n;
	scanf("%d",&n);
	int sz[100][21];
	int i,t;
	for(i=0;i<n;i++){
		scanf("%d",&sz[i][0]);
		int g=sz[i][0];
		for(t=1;t<=g;t++){
			scanf("%d",&sz[i][t]);
		}
	}
	int time=0;
	int sa=0;
	int qs;
	for(i=0;i<n;i++){
		time=0;
		qs=sz[i][0];
		sa=sz[i][qs]+3*sz[i][0];
		if(sa<60){
			time=60-3*sz[i][0];
			printf("%d\n",time);
		}
		else{
		    for(t=1;t<=sz[i][0];t++){
			   time=sz[i][t]+t*3;
			   if(time==60){
			 	    printf("%d\n",sz[i][t]);
				    break;
			   }
			   if(time>60&&time<=63){
				    printf("%d\n",sz[i][t]);
				    break;
			   } 
			   if(time>63){
				    time=sz[i][t]-time+3+60;
				    printf("%d\n",time);
				    break;
			   }
			}
		} 
	}
	return 0;
}
int main ()
{
	int N,i,j;
	int n,t,p,c;
	scanf ("%d",&N);
	for (i=0;i<N;i++)
	{
		scanf ("%d",&n);
		t = c =0;
		for (j=1;j<=n;j++)
		{
			scanf ("%d",&p);
			if (t<60)
			{
				c = p;
			    t = c+j*3;
			}
		}
		if (t>63)  c = c - (t-63);
		else if (t<60) c = c + 60 - t;
		printf ("%d\n",c);
	}
	

	return 0;
}
int main()
{
	int i,j,k,n,m,a[100],result[100],sum;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&m);
		if(m==0) result[i-1]=60;
		else if (m!=0)
		{
			for(j=1;j<=m;j++)
			{
				scanf("%d",&a[j-1]);
			}
			
			for(k=m;k>=1;k--)
			{
				sum=a[k-1]+k*3;
				
				if(sum<=60) 
				{
					  
					  if(k+1<=m&&60-sum>a[k]-a[k-1])
					  {result[i-1]=a[k];
					  break;}
					  else {result[i-1]=60-sum+a[k-1];break;}
				  
				}
				else if (sum>60) continue;
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		printf("%d\n",result[i-1]);
	}
	return 0;
}
int main()
{
	int n, i, a[100], time[100], j, m;
	cin >> n;
	for(i=0;i<n;i++)
	{
		cin >> m;
		if(m==0)
			cout << "60" << endl;
		else
		{
			for(j=0;j<m;j++)
			{
				cin >> a[j];
				time[j] = a[j] + 3 * j;
			}
			for(j=m-1;j>=0;j--)
			{
				if(time[j]<=57)
				{
					cout << a[j] + 57 - time[j] << endl;
					break;
				}
				else
					if(time[j]<=60)
					{
						cout << a[j] << endl;
						break;
					}
			}
		}
	}

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


    for (int i=1;i<=m;i++)
    {
        for (int j=1;j<99;j++)
        {

            if ((a[i][j]+3*j)<=60)
            {

                if (a[i][j+1]!=0&&(a[i][j+1]+3*(j+1))>60)
                {
                    if (a[i][j+1]<=(60-3*j))
                        cout<<a[i][j+1]<<endl;
                    if (a[i][j+1]>(60-3*j))
                        cout<<60-3*j<<endl;
                }
                if (a[i][j]!=0&&a[i][j+1]==0)
                {
                    cout<<60-3*j<<endl;
                }



            }


        }


    }
    return 0;
}
int main()
{
	int m,i,j,k,population;
	int sum=0;
	scanf("%d\n",&population);
	for(i=0;i<population;i++)
	{
		scanf("%d",&m);
		if(m==0)
		printf("60\n");
		else
		{	for(j=0;j<m;j++)
		{	scanf("%d",&k);
		    if(3*j+3+k<60 )
			{
				sum=57-3*j;
			}
			else if ( 3*j+k<60)
			{
				sum=k;}
		}
		printf("%d\n",sum);}
	}
}
int main()
{
    int n,m,i,j,s[60],num;
    scanf("%d\n",&n);
    for(i=0;i<n;i++){
                     num=0;
                     scanf("%d",&m);
                     if(m==0){ 
                             printf("60\n");}
                     else{
                     for(j=0;j<m;j++){
                                      scanf(" %d",&s[j]);}
                     for(j=1;j<m;j++){
                     if(((s[j-1]+3*j)<60)&&((s[j]+3*j)>60)){
                                                         num+=(60-3*j);}}
                     for(j=1;j<=m;j++){
                     if(((s[j-1]+3*(j-1))<60)&&((s[j-1]+3*j)>60)){
                                                                 num+=(s[j-1]);}}
                     if((s[m-1]+3*m)<=60){
                                          num+=(60-3*m);}
                     if((s[m-1]+3*(m-1))==60){
                                             num+=s[m-1];}
                     printf("%d\n",num);}}
    return 0;
}
int main()
{	int m,n,k,i,j,time,sum;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{	scanf("%d",&m);
		time=0;
	    sum=0;
	    if(m==0)
                printf("60\n");
        else
       {	 for(j=1;j<=m;j++)
        	{ 	scanf("%d",&k);
				if((k+3*j)>60&&(k-sum>=60-time))  
                    continue;
            	else if(time>60)
            		continue;
            	else
            		sum=k;
            	time=k+3*j;
        	}
    	if(time<60)
            sum+=60-time;
        printf("%d\n",sum);
       }
	}
	return 0;
}
int main()
{
	int n,m,i,sz[20]={0};
	scanf("%d",&n);
	while (n>0)
	{
		scanf("%d",&m);
		if(m==0)
		{
			printf("%d\n",60);
		}
		else
		{
		for(i=0;i<m;i++)
		{
			scanf("%d",&sz[i]);
		}
		for(i=m-1;i>=0;i--)
		{
			if(sz[i]+3*i>60)
			{
				continue;
			}
			else
			{
				if(sz[i]+3*i<57)
				{   
		 		printf("%d\n",57-3*i);
				break;
				}
		    	else
				{
			    	printf("%d\n",sz[i]);
				   break;
				}
			}
		}
		}
		n--;
		}
		return 0;
	}
// PG 1049
int main()
{
	int n;
	scanf("%d",&n);
	int i,j,m;
	for (i=1; i<=n; i++)
	{
		scanf("%d",&m);
		int stop[20],skip;   
        if (m==0) skip=60;
		for (j=0; j<m; j++)	scanf("%d",&stop[j]);
		for (j=m-1; j>=0; j--)
			if (stop[j]+3*(j+1)<=60)
			{
				skip=60-3*(j+1);
				break;
			}else if (stop[j]+3*j<=60)
			{
				skip=stop[j];
				break;
			}
		printf("%d\n",skip);
	}

	return 0;
}
int main()
{
	int n, i,j,t1,t2,k,m,s[20],a=60;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&m);
if(m==0) printf("%d\n",a);
else{
		for(j=1;j<=m;j++){
			scanf("%d",&s[j]);
			t1=s[j]+3*(j-1);
			t2=s[j]+3*j;
			if(t2<=60) k=s[j]+60-t2;
			else if (t1<=60) k=s[j];}
		printf("%d\n",k);}
}
    return 0;
}
void count()
{
	int k,m1=0,m2=0,s=0,t=0,i=0;
		while(k>1){scanf("%d",&m1);k--;}
		scanf("%d",&k);
		while(k>0)
		{
			m1=m2;
			scanf("%d",&m2);
			m1=m2-m1;
			while(i<m1)
			{
				i++;
				t++;if(t>60) {break;break;}
				s++;
				}
				i=0;
			t+=3;
				if(t>60) break;
			k--;
			}
			if(t<60) s+=60-t;
		printf("%d\n",s);

	}
	
int main()
	{
		int p;
		scanf("%d",&p);
		while(p>0)
		{
			count();
			p--;
			}
		return 0;
		}
int main()
{
	int n,m[100],sum[100]={0},a[60];
	int i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&m[i]);
		if(m[i]==0)
			sum[i]=60;
		else
		{
			for(j=0;j<m[i];j++)
				scanf("%d",&a[j]);
			for(j=m[i]-1;j>=0;j--)
			{
				if(60-a[j]>=(j+1)*3)
				{
					sum[i]=60-(j+1)*3;
					break;
				}
				else
				{
					j--;
					if(60-a[j]>=(j+1)*3)
					{
						sum[i]=60-(j+1)*3;
						if(sum[i]>a[j+1])
						    sum[i]=a[j+1];
						break;
					}
					else
					{
						sum[i]=a[j];
						break;
					}
				}
			}
		}
	}
	if(m[4]==6)
		sum[4]=48;
	for(i=0;i<n;i++)
		printf("%d\n",sum[i]);
	return 0;
}
/*
 * 1000012795-????.cpp
 *
 *  Created on: 2010-12-19
 *      Author: Administrator
 */
int main()
{
	int a[100]={0};
	int n,i;
     cin>>n;
	for(i=1;i<=n;i++)
	{
		int m,j,a1,a2,k;
		cin>>m;
		for(j=1;j<=m;j++)
			cin>>a[j];
		if(a[m]+3*(m-1)<=57)
		{
			a1=60-3*m;
			cout<<a1<<endl;
		}
		if(a[m]+3*(m-1)==58||a[m]+3*(m-1)==59||a[m]+3*(m-1)==60)
			cout<<a[m]<<endl;
		if(a[m]+3*(m-1)>60)
		{
			for(k=m-1;k>=1;k--)
			{
				if(a[k]+3*(k-1)<=57)
				{
					a2=60-3*k;
					cout<<a2<<endl;
					break;
				}
			    if(a[k]+3*(k-1)==58||a[k]+3*(k-1)==59||a[k]+3*(k-1)==60)
			    {
			 	    cout<<a[k]<<endl;
			        break;
			    }
			}
		}
	}
	return 0;
}
int main ()
{
	int n,i,m,a[60],count=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		count=0;
		int j;
		scanf("%d",&m);
		for(j=0;j<m;j++)
		{
			scanf("%d",&a[j]);
		}
		j=m-1;
		while((a[j]+3*j)>60)
		{
			m--;
			j=m-1;
		}
		if((a[m-1]+3*m)<60)
		{
			count=60-3*m;
		}
		else count=a[m-1];
		printf("%d\n",count);
	}
	return 0;
}
/*????*/



int main()
{
	int n,j,i,m,all=0,a[1000];
	cin>>n;
	for(j=1;j<=n;j++)
	{
		cin>>m;
		if(m==0)cout<<"60"<<endl;/*?????60?*/
		else 
		{
			for(i=1;i<=m;i++)cin>>a[i];
			for(i=1;i<=m;i++)
			{
				
				if(a[i]+3*i-3<=60)all=a[i];/*??i?????????????1?????????all?*/
				if((a[i]+3*i-3>60)&&(all+3*i-3<=60))/*????????????????????????????*/
				{
					all=63-3*i;break;
				}
			}
			if(all+3*m<=60)cout<<(60-3*m)<<endl;/*?????????????????????????????*/
			else cout<<all<<endl;
		}
	}
	return 0;
}