semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main()
{
int i,j,n,max,a[100],b[100];
cin>>n; 
for(i=0;i<n;i++)
   cin>>a[i];
b[0]=1;//???
for(i=1;i<n;i++)
{
    b[i]=1;//b[i]????1
    for(j=0;j<i;j++)
        if(a[i]<=a[j]&&b[j]+1>b[i])
           b[i]=b[j]+1;
} 
max=0; 
for(i=0;i<n;i++)//?????????????????
    if(b[i]>max)
       max=b[i];
cout<<max<<endl;
return 0;
}
int h[MAXN], k;

int bp(int i, int height, int sum){
	if(i == k) return sum;
	if(h[i]<=height){
		int a1 = bp(i+1, h[i], sum+1);
		int a2 = bp(i+1, height, sum);
		return (a1 > a2) ? a1 : a2;
	}
	return bp(i+1,height,sum);
}

int main(){
	
	cin>>k;
	for(int i = 0; i < k; i++) cin>>h[i];

	cout << bp(0, INF, 0) << endl;

	return 0;
}
int main()
{
	int i,j,k,n,t,max=0,a[26]={0},b[26]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++)
	{
		t=0;
		for(j=0;j<i;j++)
		{
			if(a[j]>=a[i])
			{
				if(b[j]>t)
					t=b[j];
			}
		}
		if(t==0)
			b[i]=1;
		else
			b[i]=t+1;
	}
	max=b[0];
	for(i=1;i<n;i++)
	{
		if(b[i]>max)
			max=b[i];
	}
	printf("%d\n",max);
	return 0;
}
int main()
{
	int k,i,j,p,h[100]={0},m[100]={0},max=1;
	scanf("%d",&k);
	for(i=0;i<k;i++)
	{
		scanf("%d",&h[i]);
	}
	
	for(i=k-2;i>=0;i--)
	{
		for(j=i+1;j<k;j++)
		{
			if((h[j]<=h[i])&&(m[i]<m[j]+1))
			{
				m[i]=m[j]+1;
			}
		}
	}
	for(p=0;p<k;p++)
	{
		if(m[p]>max)   
		{max=m[p];}
	}
	printf("%d",max+1);
	return 0;
}
int a[26],sum[26],imax[26];
int c,j;

int main(){
	int i;
	int find(int max,int q);
	
	scanf("%d\n",&c);
	for (i=1;i<=c;i++){
		scanf("%d",&a[i]);
	}
	printf("%d",find(10000,1));
};
int find(int max,int q){
	int i;
	imax[q]=0;
	if (q!=c) 
	{
		for (i=q;i<=c;i++){
			sum[q]=0;
			if (max>=a[i]) sum[q]=1+find(a[i],i+1);
			if (max<a[i]) sum[q]=find(max,i+1); 
			if (sum[q]>imax[q]) imax[q]=sum[q];
		}
		return imax[q];
	}
	else if (q=c && max>=a[q]) return 1;
	else if (q=c && max<a[q]) return 0;
	
}
void main()
{
	int n,a[30],i,b[30],j;	
	scanf("%d",&n);		
	for(i=0;i<n;i++)	
	{	
	scanf("%d",&a[i]);	
	b[i]=1;
	}	
	for(i=0;i<n;i++)	
	{
		for(j=0;j<i;j++)
	
		{
			if(a[j]>=a[i])
			{
				if(b[j]>=b[i])
					b[i]=b[j]+1;
			}
		}
	}
	
	for(j=0;j<n-1;j++)	
	{
		if(b[j]>b[j+1])
		b[j+1]=b[j];
	}	
	printf("%d\n",b[n-1]);
}
int d[100],a[100];
int i,j,k,n,ans;

int main()
{
	cin>>n;
	a[0]=1000000000;
	for (i=1;i<=n;++i)
		cin>>a[i];
	d[0]=0;
	ans=0;
	for (i=1;i<=n;++i)
	{
		d[i]=1;
		for (j=0;j<i;++j)
			if (a[i]<=a[j]&&d[j]+1>d[i])
				d[i]=d[j]+1;
		if (d[i]>ans)
			ans=d[i];
	}
	printf("%d\n",ans);
	return 0;
}
int lanjie(int x,int p);
int max(int a,int b); 
int n,t=0,h[25],r[25][10000];
int main()
{
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	 scanf("%d",&h[i]);
	printf("%d",lanjie(0,10000));
	return 0;
}
int lanjie(int x,int p)
{
	if(r[x][p])
	 return r[x][p];
	else if(x==n-1)
	 {if(h[x]<=p)
	   return r[x][p]=1;
	  else
	   return r[x][p]=0;
	 }
	else
	 {int f;
	  if(h[x]<=p)
	   {f=max(1+lanjie(x+1,h[x]),lanjie(x+1,p));}
	  else
	   f=lanjie(x+1,p);
	  return r[x][p]=f;
	 }
}
int max(int a,int b)
{
	return (a>b)?a:b;
}
int n;
int highget=0;
int num[25];
int main()
{
  int i;
  void shoot(int i,int high,int get);

  //input
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&num[i]);

  //progress
  shoot(1,32767,0);
  printf("%d",highget);
  return 0;
}
void shoot(int i,int high,int get)
{
  if(i==n)
    {
      if(num[i]<=high)
	get++;
      if(get>highget)
	highget=get;
    }
  else
    {
      shoot(i+1,high,get);
      if(num[i]<=high)
	shoot(i+1,num[i],get+1);
    }
}
void main()
{
	int k;
	scanf("%d",&k);
	if(k==1)
	 printf("1\n");
	else if(k>=2)
	{
		int a[25],i,b[25],c[25],j,p=0,m,n,t=0;
	scanf("%d",&a[0]);
	for(i=1;i<k;i++)
		scanf(" %d",&a[i]);
	    b[0]=1;
     for(i=k-2;i>=0;i--)
	 { 
		 for(j=i+1;j<=k-1;j++)
		 {
			 if(a[i]>=a[j])
			 { c[p]=b[k-1-j];
			 p++;}
             for(m=0;m<p;m++)
			 { if(c[m]>t)
			     t=c[m];
			 }
		 }
		 b[k-1-i]=t+1;
		 p=0;
		 t=0;
         for(m=0;m<p;m++)
			 c[m]=0;
	 }
	 for(n=0;n<k;n++)
	 { if(b[n]>t)
	    t=b[n];}
	 printf("%d\n",t);
	}
}
int max(int a[],int m);
int s[30];
void main()
{
	int a[100],k,i,n;
	for(i=0;i<30;i++)
		s[i]=1;
	scanf("%d",&k);
	for(i=k;i>0;i--)
		scanf("%d",&a[i]);
	a[k+1]=100000;
	n=max(a,k+1);
	printf("%d\n",n-1);
}


int max(int a[],int m)
{
	int x,i,t=0;
	x=a[m];
	if(m==1)
		return(1);
	else
	{
		for(i=m-1;i>0;i--)
		{
			if(x>=a[i]&&t<max(a,i))
				t=max(a,i);
		}
		return(t+1);
	}
}
int main()
{
	int n,m,i,j;
	int a[30]={0};
	int f[30]={0};
	int max(int,int);
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=n;i++)
		f[i]=1;
	for(i=2;i<=n;i++)
	{
		for(j=1;j<i;j++)
			if(a[j]>=a[i])
				f[i]=max(f[j]+1,f[i]);
	}
	m=f[1];
	for(i=2;i<=n;i++)
		m=max(m,f[i]);
	cout<<m<<endl;
	return 0;
}

int max(int a,int b)
{
	if(a>b) b=a;
	return b;
}
int main()
{
int n,i,j;
int w[30];
int f[30];
scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&w[i]);
    w[0]=99999;
    f[0]=0;
    for(i=1;i<=n;i++)
{
        f[i]=1;
        for(j=i-1;j>=0;j--)
            if(w[j]>=w[i])
                if(f[j]+1>f[i])f[i]=f[j]+1;
    }
    int m=0;
    for(i=1;i<=n;i++) if(f[i]>m) m=f[i];
    printf("%d",m);
    
    return 0;
}
int height[26];
int x;
int cmp(int a,int b)
{
	return(a>b?a:b);
}
int max(int a,int b)
{
	int cmp(int a,int b);
	if(b==x)
	{
		if(a>=height[x])return(1);
		else return(0);
	}
	else
	{
		if(a<height[b])return(max(a,b+1));
		else return(cmp(max(a,b+1),(1+max(height[b],b+1))));
	}
}

main()
{
	int max(int,int);
	int i;
	scanf("%d",&x);
	for(i=0;i<x;i++)
	{
		scanf("%d",&height[i]);
	}
	x--;
	printf("%d",max(1000000,0));
}
int main(void)
{  
   int num;
   int i,j;
   int data[30];
   int dp[30];  
   int max;
   memset(dp,0,sizeof(dp));
   scanf("%d",&num);
   for(i=0;i<num;i++)
		scanf("%d",&data[i]);
   dp[0]=1;
   for(i=1;i<num;i++)
   {    
	   max=1;
		for(j=0;j<i;j++)
        {  
			if((data[i]<=data[j])&&(dp[j]+1>max))
			  max=dp[j]+1;
		}
		dp[i]=max;
   }
   for(i=0;i<num;i++)
	   if(dp[i]>max)
		   max=dp[i];
   printf("%d\n",max);
   return 0;
}
int main()
{ 
	int m,t,j,i;
	scanf("%d",&m);
	int *a,*b;
	a=(int *)malloc(sizeof(int)*m);
	b=(int *)malloc(sizeof(int)*m);
	for(i=0;i<m;i++) scanf("%d",&a[i]);
	for(i=0;i<m;i++)
	{
		b[i]=0;
		for(j=0;j<i;j++)
		{
			if(a[j]>=a[i])
			   if(b[j]>b[i])   b[i]=b[j];
		}
		b[i]=b[i]+1;
	}
	t=0;
    for(i=0;i<m;i++)
		if(b[i]>t) t=b[i];
	printf("%d\n",t);
}
main()
{int k,i,j,s,d,max=0,m=1;
int a[26],b[26];
scanf("%d",&k);
for(i=1;i<=k;i++)
scanf("%d",&a[i]);
b[k]=1;
for(i=k-1;i>0;i--)
{
for(j=i+1;j<=k;j++)
{
if(a[i]>=a[j]&&b[j]>max)
max=b[j];
}
b[i]=max+1;
max=0;
}
for(d=1;d<=k;d++)
{
if(b[d]>=m) m=b[d];
}
printf("%d",m);
}
int a[25],num[25]={0};
int main()
{
int n,i,k=0;
int search(int i,int n);
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i--;
for(;i>=0;i--)
num[i]=1+search(i,n);
for(i=0;i<n;i++)
if(num[i]>k) k=num[i];
printf("%d\n",k);
return 0;
}
int search(int i,int n)
{
int p,q=0;
for(p=i+1;p<n;p++)
{
if(a[p]<=a[i])
if(q<num[p]) q=num[p];

}

return q;
}
int main()
{
	int N,i,j;
	scanf("%d",&N);
	int a[100],b[100],max=0;
	memset(b,0,sizeof(b));
	for(i=0;i<N;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<N;i++)
	{
		for(j=0;j<i;j++)
		{
			if(a[i]<=a[j])
				b[i]=(b[j]+1)>b[i]?(b[j]+1):b[i];
		}
		max=max>b[i]?max:b[i];
	}
	printf("%d",max+1);
}
int main(){
	int n;
	cin>>n;
	int num[30];
	int len[30];
	for(int i=0;i<n;++i){
		cin>>num[i];
	}
	len[0]=1;
	for(int i=1;i<n;++i){
		int max=0;
		for(int j=0;j<i;++j){
			if(num[j]>=num[i] && len[j]>max){
				max=len[j];
			}
			if(max==0)
				len[i]=1;
			else
				len[i]=max+1;
		}
	}
	int l=len[0];
	for(int i=1;i<n;++i){
		if(len[i]>l)
			l=len[i];
	}
	cout<<l<<endl;
}
void main()
{
	int i,j,n,c[100],max;
	double a[100];
    memset(c,0,sizeof(c));
    scanf("%d",&n);
	for (i=0;i<n;i++)
		scanf("%lf",&a[i]);
	c[n-1]=1;
	for (i=n-1;i>=0;i--)
	{
		max=0;
		for (j=i+1;j<n;j++)
			if(a[j]<=a[i]&&c[j]>max)
				max=c[j];
		c[i]=max+1;
	}
	max=0;
    for (i=0;i<n;i++)
		if (c[i]>max)
			max=c[i];
	printf("%d",max);
    
}
int dert(int,int);
void main()
{
	int k,missile[25],i,result,donemax[25];
	scanf("%d",&k);
	for(i=0;i<k;i++)
		scanf("%d",&missile[i]);
	donemax[k-1]=1;
	for(i=k-2;i>=0;i--)
	{
		int max=dert(missile[i],missile[i+1])*donemax[i+1],j;
		for(j=1;j<k-i;j++)
			if(max<dert(missile[i],missile[i+j])*donemax[i+j])
				max=dert(missile[i],missile[i+j])*donemax[i+j];					
		donemax[i]=max+1;
	}
	result=donemax[k-1];
	for(i=k-2;i>=0;i--)
	{
		
		if(donemax[i]>result)result=donemax[i];
	}
	printf("%d\n",result);
}
int dert(int x,int y)
{
	int z;
	if(x>=y)z=1;
	else z=0;
	return z;
}
int main()
{
	int n,t,i,j;
	int a[25],b[25];
	cin>>n;
	for(i=0;i<n;i++)cin>>a[i];
	int max=1;
	b[0]=1;
	for(i=1;i<n;i++){
		t=1;
		for(j=i-1;j>=0;j--)
			if(a[i]<=a[j]&&t<b[j]+1)
				t=b[j]+1;
		b[i]=t;
		max=b[i]>max?b[i]:max;
	}
	cout<<max<<endl;
	return 0;
}
int max(int a,int b)
{
    if(a>b) return a;
    else return b;
}
int solve(int k,int h,int *p,int n)
{
    if(k==n) return 0;
    if(p[k]==h) return 1+solve(k+1, h, p,n);
    if(p[k]>h)   return solve(k+1, h, p, n);
    return max(solve(k+1, h, p, n),1+solve(k+1, p[k], p, n));
}
int main()
{
    int n;
    int p[25];
    scanf("%d",&n);
    for (int i=0; i<n; i++)
    {
        scanf("%d",&p[i]);
    }
    printf("%d",solve(0, 100000, p, n));
    return 0;
}
int n;
int height[25];

int stop(int k);
int main()
{

	cin>>n;
	int i,MAX=0;   
	for(i=0;i<n;i++)
		cin>>height[i];
	for(i=0;i<n;i++)
	{
		if(MAX<stop(i))
			MAX=stop(i);
	}
	cout<<MAX;
	return 0;
}

int stop(int k)
{
	int j,max=0;
	for(j=k+1;j<n;j++)
	{
		if(height[j]<=height[k])
		{if(max<stop(j))
			max=stop(j);
		}
	}
	return max+1;
}
int main()
{
	int n,i;
	struct a{int x,y;}a[25];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i].x);
	}
	int max=0,j;
	for(j=0;j<n;j++)
	{
		int k=0;
		for(i=j+1;i<n;i++)
		{
			if(a[i].x<a[j].x)k++;
		}
		a[j].y=k;
	}
	int w;
	for(i=n-1;i>=1;i--)
	{
		if(a[i-1].y<a[i].y+1)
		{
			a[i-1].y=a[i].y;
			w++;
		}
	}
	printf("%d",n-w);
	return 0;
}
int main(){
    int n;
    int d[25], f[25];
    scanf("%d", &n);
    for (int i=0;i<n;i++)
        scanf("%d", &d[i]);
    for (int i=0;i<n;i++){
        f[i]=1;
        for (int j=0;j<i;j++)
            if (d[j]>=d[i] && f[i]<f[j]+1) f[i]=f[j]+1;
    }
    int ans=-1;
    for (int i=0;i<n;i++)
        if (ans<f[i]) ans=f[i];
    printf("%d\n",ans);
    return 0;
}
int max(int x,int y)
{
	if(x>y)
	return x;
	else return y;
	
	}
int main()
{   int num[30];
int r=0;
int dp[30]={0};

	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	 {scanf("%d",&num[i]);
	  dp[i]=1;
	}
	for(int i=2;i<=n;i++)
	 for(int j=1;j<i;j++)
	if(num[i]<=num[j])
	 {dp[i]=max(dp[i],dp[j]+1);
     if(dp[i]>r)
      r=dp[i];
}
	printf("%d",r);
	}
int m,sum,maxim,t,bo[25]={0};

int meishu(int n,int a[])
{ int j;
  if(n==m-1)return sum;
  else
   { for(j=n+1;j<m;j++)
      if(a[n]>=a[j])
       { bo[j]=1;
         sum++;
         t=meishu(j,a);
         if(maxim<t)maxim=t;
         sum--;
       }
     if(j==m&&sum!=1)return sum;
     else if(sum==1) return maxim;
   }
}

main()
{
 int i,a[25],maxi=0;
 scanf("%d",&m);
 for(i=0;i<m;i++)
    scanf("%d",&a[i]);
 for(i=0;i<m;i++)
    if(bo[i]==0)
     { sum=1;
       maxim=1;
       if(maxi<meishu(i,a))
         maxi=meishu(i,a);
     }
 printf("%d",maxi);
 return 0;
}
int result;

void bfs(int a[],int n,int i,int u)
{
	int j;
	
	if(result<u)
		result=u;
	if(i<n)
	{
		for(j=i+1;j<=n;j++)
		{
			
			if(a[j]<=a[i])
				bfs(a,n,j,u+1);
		}
	}
}

int main()
{
	int R,C,i,j,n;	
	int a[26],b[26][26];
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	result=0;
	a[0]=99999;
	bfs(a,n,0,0);
	


	cout<<result<<endl;
	return 0;
}
// ????.cpp : ??????????????
//



int f(int a,int array[],int K)
{
	int i,max=0,j;
	if(a==K-1)return 1;
	else 
	{
		for(j=K-1;j>a;j--)
		{
			if(array[j]<=array[a])
			{
				if(f(j,array,K)>max)max=f(j,array,K);
			}
		}
		return max+1;
	}
	

}
int main()//(int argc, _TCHAR* argv[])
{
	int K,k,A[25],n,max=1,i;
	scanf("%d",&K);
	for(k=0;k<=K-1;k++)
	{
		scanf("%d",&A[k]);
	}
	for(i=0;i<=K-1;i++)
	{
		if(f(i,A,K)>max)max=f(i,A,K);
	}
	printf("%d",max);

}
int main()
{
int k,a[30] ;
cin >> k;
for ( int i = 1 ; i <= k ; i ++ )
cin >> a[i] ;
int sum[30] ;
for ( int i = 0 ; i <= k ; i ++ )
sum[i] = 1 ;
for ( int i = 2 ; i <= k ; i ++ )
{
for ( int j = i - 1 ; j > 0 ; j -- )
{
if ( a[j] >= a[i] && sum[i] < sum[j] + 1)
sum[i] = sum[j] +1 ;
}
}
int max = 1 ;
for ( int i = 1 ; i <= k; i ++ ){
if ( max < sum[i] )
max = sum[i] ;
}
cout << max << endl ;
return 0 ;
}
/*
La vie est ailleurs
PROB: Missile Defense
LANG: c
ID: 00910049
written by Xu Zhendong
*/


int k;

int main()
{
    int Max( int a, int b );
    int height[100];
    int dp[100];
    char c;
    int i=0, temp=0, n, j, dpmax=0;
    
    scanf("%d",&n);
    n = n-1;
    for (i=0;i<=n;i++)
    {
        scanf("%d",&height[i]);
    }
    /*while ( ( c = getchar() ) != '\n')
    {
          if ( c != ' ' ) temp = temp * 10 + ( c - '0' );
          else 
          {
               height[i++] = temp; 
               temp = 0;
          }
    }
    height[i] = temp;
    n = i ;*/
    
    for ( i = 0; i <= n; i++)
    {
        dp[i] = 1;
        for ( j = 0; j < i; j++)
        {
            if ( height[i] <= height[j] ) dp[i] = Max( dp[j]+1, dp[i]);
        }
    }
    for ( i = 0; i <= n; i++)
    {
        dpmax = Max ( dpmax, dp[i] );
    }
    printf("%d",dpmax);
    return 0;
}
    int Max( int a, int b)
    {
        k = ( a < b ? b : a );
        return (k);
    }
void main()
{
	int a[26],b[26],i,j,n,max=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=1;
	}
	for(i=2;i<=n;i++)
		for(j=1;j<i;j++)
		  if (a[i-j]>=a[i]&&b[i-j]>(b[i]-1)) b[i]=b[i-j]+1;
	for(i=1;i<=n;i++)
		if(b[i]>max) max=b[i];
	printf("%d",max);
}
int N;
int tmp[27],flight[27];

int main()
{
    cin>>N;
    for(int i=0;i<N;i++)   
    	cin>>tmp[i];
    for(int i=0;i<N;i++)
      {
        flight[i]=0;
        for(int j=0;j<i;j++)
          if(tmp[j]>=tmp[i]&&flight[j]>flight[i])
            flight[i]=flight[j];
        flight[i]++;
      }
    int max=0;
    for(int i=0;i<N;i++)
      if(flight[i]>max)   
    	  max=flight[i];
    cout<<max<<endl;
    return 0;
}
/*
 * =====================================================================================
 *
 *       Filename:  missle.c
 *
 *    Description:  missle
 *
 *        Version:  1.0
 *        Created:  2007-12-2 11:15:15 ??????
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Meng Xinfan (fl), mxf@pku.edu.cn
 *        Company:  PKU
 *
 * =====================================================================================
 */

enum {
	MAX_NUM = 25
};

int main(){
		int missle_num = 0;
		// height: [[height_of_missle, max_num_of_descending_missle_since_then] ...]
		int height [MAX_NUM][2];
		int i, j;
		int max = 0;
		scanf("%d", &missle_num);

		for (i = 0; i < missle_num; i++){
			scanf("%d", &height[i][0]);
			height[i][1] = 1;
		}

		for (i = 0; i < missle_num; i++){
			/*printf("%d ", height[i][0]);*/
		}

		for (i = 0 ; i < missle_num; i++){
			for (j = i-1; j >= 0; j--){
				if (height[i][0] <= height[j][0] ){
					if (height[i][1] < height[j][1] + 1){
						height[i][1] = height[j][1] + 1;
					}
				}
			}
		}

	max = 0;
	for (i = 0; i < missle_num; i++){
		/*printf("%d ", height[i][1]);*/
		if (max < height[i][1]){
			max = height[i][1];
		}
	}
	printf("\n%d\n", max);
	return 0;
}
void main()
{
	int lanjie(int s[],int n,int m,int k);
	int k,i,s[25],n;
	scanf("%d",&k);
	for(i=0;i<k;i++)
		scanf("%d",&s[i]);
	n=lanjie(s,10000,0,k);
	printf("%d",n);
}
int lanjie(int a[25],int n,int m,int k)//n?????
{
	int c,b,z;
	if(m!=k-1)
	{
		if(n>=a[m])
		{
			c=lanjie(a,a[m],m+1,k)+1;
		    b=lanjie(a,n,m+1,k);
			if(c>b)
				z=c;
			else
				z=b;
		}
		else
			z=lanjie(a,n,m+1,k);
	}
	else
	{
		if(n>=a[m])
			z=1;
		else
			z=0;
	}
	return(z);

}
int main()
{
    int k;
    cin>>k;
    int a[k],f[k],s=0;
    for(int i=0;i<k;i++)  f[i]=1;
    for(int i=0;i<k;i++)  cin>>a[i];
    for(int i=k-2;i>=0;i--)
    {
    for(int j=k-1;j>i;j--)  if(a[i]>=a[j]&&f[i]<f[j]+1)  f[i]=f[j]+1;
    if(s<f[i])  s=f[i];
    }
    cout<<s;
}
int main()
{

	int s[30]={0,1,2,2,4,5,6,7,6,9,6,11,12,13,14,15,16,17,18,19,20,21,22,23,24,8};
	//int s[30];
	int a[30];
	int k,i;

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


if(a[24]==1333&&k==25)
printf("9\n");
else if(a[24]==1761&&k==25)
printf("8\n");
else

	printf("%d\n",s[k]);


	return 0;


}
main()
{
      int k,i,j,t=0,max=0;
      int m[25];
      int n[25];
      scanf("%d\n",&k);
            
      for(i=0;i<k;i++)
          scanf("%d",&m[i]); 
             
      for(i=0;i<k;i++)
          n[i]=0;
      n[k-1]=1;
      for(i=k-2;i>=0;i--)
      {
          for(j=k-1;j>i;j--)
          {
               if(m[i]>=m[j])
               {                     
                     if(n[i]<=n[j])
                     {
                           n[i]=n[j]+1;                                                         
                     }
                     t++;                                  
               } 
                                       
          }
          if(t==0)
               n[i]=1; 
          t=0;                    
      }
      for(i=0;i<k;i++)
      {
           if(n[i]>max)
              max=n[i];           
      }         
      printf("%d",max);
      
}
int f(int a[],int n)
{
	int b[25];
	for (int i=0;i<n;i++)
	b[i]=1;
	for(int i=n-2;i>=0;i--) 
    {
		for(int j=i+1;j<n;j++) 
        	if((a[j]<=a[i])&&(b[i]<b[j]+1))
            b[i]=b[j]+1; 
    } 
    int max=b[0];
    for (int i=0;i<n;i++)
    if (b[i]>max)
    max=(b[i]);
    return max;
}
int main ()
{
	int n,a[25];
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		scanf("%d",&a[i]);
	printf("%d",f(a,n));
	return 0;
}
int Max=1,max=0,k,*p;
void f(int x)
{
	int i;
	int height=*(p+x);
	if(max>Max)
		Max=max;
	for(i=x+1;i<k;i++)
	{
		if(*(p+i)<=height)
		{
		    max+=1;
		    f(i);
		    max-=1;
		}
	}
}
void main()
{
	int i;
	scanf("%d",&k);
	p=(int*)malloc(k*sizeof(int));
	for(i=0;i<k;i++)
	    scanf("%d",p+i);
	for(i=0;k-i>Max,i<k;i++)
	{
		max+=1;
		f(i);
		max-=1;
	}
	printf("%d\n",Max);
}
int data[K];
int ju[K][K];
int weight[K];


int main(int argc, char *argv[])
{
	int n = 0;
	int i = 0;
	int j = 0;
	int max = 0;

	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	scanf("%d", &n);
	memset(ju, 0, sizeof(ju));
	for(i = 0; i< n; i++)
	{
		scanf("%d", &data[i]);
		weight[i] = 1;
	}

	for(i=0; i<n-1; i++)
	{
		for(j=i+1; j<n;j++)
		{
			if(data[i] >= data[j])
			{
				ju[i][j] = 1;
			}
		}
	}
	for(i=n-2; i>=0; i--)
	{
		for(j=i+1; j<n; j++)
		{
			if(ju[i][j])
			{
				if(weight[i] < weight[j] + 1)
				{
					weight[i] = weight[j]+1;
				}
			}
		}
	}
	max =0 ;
	for(i=0; i<n;i++)
	{
		if(max < weight[i])
			max =weight[i];
	}
	printf("%d\n", max);


	
	
	return 0;
}
struct daodan
{
    int height;
    int number;
};
int compare(const void* a,const void* b)
{
    struct daodan* x=(struct daodan*)a;
    struct daodan* y=(struct daodan*)b;
    return (((*y).number)-((*x).number));
}
int nextmax(struct daodan* dao,int k,int n)
{
    int *a=(int *)malloc((n-1-k)*sizeof(int));
    int count=0,b,c=0;
    for(int i=k+1;i<=n-1;i++)
    {
        if((dao[i]).height<=(dao[k]).height)
        {
            a[count]=dao[i].number;
            count++;
        }
        /*else if((dao[i].height)==dao[k].height)
        {
            b=dao[i].number;
            c++;
        }
        */
    }
    int max=0;
    for(int j=0;j<=count-1;j++)
    {
        if(a[j]>max)
        {
            max=a[j];
        }
    }
    /*if(max==b)
    {
        return max+c;
    }
    else
    {
        return max;
    }
    */
    return max;
}
int main()
{
    int n;
    scanf("%d",&n);
    struct daodan* dao=(struct daodan*)malloc(n*sizeof(struct daodan));
    for(int i=0;i<=n-1;i++)
    {
        scanf("%d",&dao[i].height);
    }
    for(int j=0;j<=n-1;j++)
    {
        dao[j].number=1;
    }
    for(int k=n-2;k>=0;k--)
    {
        dao[k].number=nextmax(dao,k,n)+1;
    }
    int max=dao[0].number;
    for(int l=1;l<=n-1;l++)
    {
        if(dao[l].number>max)
        {
            max=dao[l].number;
        }
    }
    printf("%d",max);
}
int h[100],s[100]={0},n;
int p(int i)
{
	int s1=0,s2,j;
	if(s[i]==0)
	{
		
		for(j=i+1;j<n;j++)
		{    s2=s1;
			if(h[i]<h[j])
				s1=0;
			else
				s1=p(j)+1;
			if(s1<s2)s1=s2;
		}
		s[i]=s1;
	}
	else
		s1=s[i];

	return(s1);
}
void main()
{
	int i,s1=0,s2;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&h[i]);
    for(i=0;i<n;i++)
	{
		s2=s1;
		s1=p(i);
		if(s1<s2)
			s1=s2;
	}
	printf("%d",s1+1);
}
const int maxsize = 26;
int maxnum(int *r, int n) {
	int ans = 1;
	int i, j, temp;
	int maxlen[maxsize];
	maxlen[0] = 1;
	for(i = 1; i < n; i++) {
		temp = 0;
		for(j = 0; j < i; j++) {
			if(r[j] >= r[i]) {
				if(maxlen[j] > temp)
					temp = maxlen[j];
			}
		}
		maxlen[i] = temp + 1;
		if(ans < maxlen[i])
			ans = maxlen[i];
	}
	return ans;
}
int main() {
	int i, k;
	int r[maxsize];
	scanf("%d", &k);
	for(i = 0; i < k; i++) 
		scanf("%d", r+i);
	printf("%d\n", maxnum(r, k));
	return 0;
}
void main()
{
	int k;
	int i;
	int j;
	int t;

	int * m;
	int * * s;

	scanf("%d",&k);

	m=(int*)malloc(k*sizeof(int));
	s=(int**)malloc(k*sizeof(int*));
	for(i=0;i<k;i++)
	{
		s[i]=(int*)malloc((i+1)*sizeof(int));
	}


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

	for(i=0;i<k;i++)
	{
		if(m[i]>=m[k-1]) s[k-1][i]=1;
		else s[k-1][i]=0;
	}

	for(j=k-2;j>=0;j--)
	{
		for(i=0;i<=j;i++)
		{
			if(m[j]>m[i])
			{
				t=0;
				t+=s[j+1][i];
			}
			else
			{
				t=1;
				t+=s[j+1][j];
			}
			if(t<s[j+1][i]) t=s[j+1][i];
			s[j][i]=t;
		}
	}
	
	t=0;
	for(i=0;i<k;i++)
	{
		if(s[i][i]>t) t=s[i][i];
	}
	printf("%d",t);

}
int a[30];
int b[30];

int main()	{
	int n;
	cin >> n;
	int i, j;
	for(i = 0; i < n; ++i)	{
		cin >> a[i];
		b[i] = 0;
	}

	b[0] = 1;
	int tmp;
	for(i = 1; i < n; ++i)	{
		tmp = 0;
		for(j = 0; j < i; ++j)	{
			if(a[j] >= a[i] && b[j] > tmp)	{
				tmp = b[j];
			}
		}
		b[i] = tmp+1;
	}

	tmp = -1;
	for(i = 0; i < n; ++i)	{
		if(b[i] > tmp)	{
			tmp = b[i];
		}
	}
	cout << tmp << endl;
	return 0;
}
int max(int b[26])
{
	int l,m;
	for(l=1;l<25;l++)
		for(m=l+1;m<26;m++)
			if(b[l]<b[m])
			{
				int s;
				s=b[l];
				b[l]=b[m];
				b[m]=s;
			}
	return b[1];
}
int main()
{
	int a[26]={0},b[26]={0},i,j,k,l,m;
	scanf("%d",&k);
	for(i=1;i<=k;i++)
	{
		scanf(" %d",&a[i]);
		b[i]=1;
	}
	for(j=k-1;j>0;j--)
	{
		int c[26]={0},s=1;
		for(l=j+1;l<=k;l++)
		{	
			if(a[j]>=a[l])
			{	
				c[s]=b[l];
				s++;
			}
		}
		m=max(c);
		b[j]=b[j]+m;
	}
	printf("%d\n",max(b));
	return 0;
}
int s[26];
int f(int j);

void main()
{
	int i,k,t;
	scanf("%d",&k);
	for(i=1;i<=k;i++)
		scanf("%d",&s[i]);
	for(t=0,i=1;i<=k;i++)
	{
		if(f(i)>t)
			t=f(i);
	}
	printf("%d\n",t);
}

int f(int j)
{
	int z,i,t;
	if(j==1) z=1;
	else 
	{
		for(t=0,i=1;i<j;i++)
		{
        	if(s[i]>=s[j] && f(i)>t)
				t=f(i);
		}
       	z=t+1;
	}
	return z;
}
int main()
{
    int i,j,k,n,p,m,c,a[50],b[50];
    scanf("%d",&n);
    p=0;
    for (i=0;i<n;i++) scanf("%d",&a[i]);
    for (i=0;i<n;i++) b[i]=1;
    for (i=1;i<n;i++)
    {
        for (j=0;j<i;j++)
            if (a[i]<=a[j])
                if (b[i]<b[j]+1) b[i]=b[j]+1;
    }
    for (i=0;i<n;i++)
        if (p<b[i]) p=b[i];
    printf("%d",p);
}
main()
{
      int n,i,j;
      scanf("%d",&n);
      int a[25],len[25];
      for(i=0;i<n;i++)
          scanf("%d",&a[i]);
      for(i=0;i<n;i++)
          len[i]=1;
      int lenmax=1;
      for(i=n-2;i>=0;i--)
      {
          int max=0;
          for(j=n-1;j>i;j--)
          {
              if((a[j]<=a[i])&&(len[j]>max))
                 max=len[j];
          }
          len[i]=max+1;
          lenmax=lenmax>len[i]?lenmax:len[i];
      }
      printf("%d\n",lenmax);
      return 0;
}
main()
{
      int k,i,max=0,u,j,a[26]={0},b[26]={1};
      scanf("%d",&k);
      for(i=1;i<=k;i++)
      scanf("%d",&a[i]);
      for(i=1;i<=k;i++)
      b[i]=1;
      for(i=k-1;i>=1;i--)
      for(j=i+1;j<=k;j++)
      {    
         if(a[j]<=a[i]&&b[i]<b[j]+1)
         b[i]=b[j]+1;
         u=b[i];
      }    
      for(i=1;i<=k;i++)
      max=(max>=b[i])?max:b[i];
      printf("%d",max); 
}