int n;
static int c[25];
int max(int a,int b)
{
	if(a>=b)
	return (a);
	else return (b);
}
int f(int mx,int st)
{
	for(;st<n;st++)
	if(c[st]<=mx)
	return (max(f(c[st],st+1)+1,f(mx,st+1)));
	return  0;
}
int main()
{
	int i,s;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&c[i]);
	s=f(4000,0);
	printf("%d",s);
}


main()
{
     int n;
     scanf("%d",&n);
     int *p=(int*)malloc(n*sizeof(int));
     int *q=(int*)malloc(n*sizeof(int));
     q[n-1]=1;
     int best=q[n-1];
     for(int i=0;i<n;i++) scanf("%d",&p[i]);
     for(int i=n-2;i>=0;i--)
     {
          int a=0;
          for(int k=n-1;k>i;k--)
          {
               if (p[i]>=p[k]&&q[k]>=a) a=q[k];
          }
          q[i]=a+1;
          if(q[i]>best) best=q[i];
     }
     printf("%d\n",best);
}


int bomb[25],p=0,k,antibomb[25],j=0,answer[2]={0,0};
void makeanti(int a[]);
void main()
{
	int i;
	scanf("%d",&k);
	for(i=0;i<k;i++) scanf("%d",&bomb[i]);
	makeanti(bomb);
	printf("%d",answer[0]);
	getchar();
	getchar();
}
void makeanti(int bomb[])
{
	int i,l,r=0,aa;
	if(k==0)
	{
		answer[1]=j;
		answer[0]=answer[0]>answer[1]?answer[0]:answer[1];
	}
	else
		for(i=0;i<k;i++)
		{
			if(j==0) antibomb[j++]=bomb[i];
			else if(bomb[i]<=antibomb[j-1])
			{
				antibomb[j++]=bomb[i];
				r=1;
			}
			else if(r==0&&i==k-1)
			{
				answer[1]=j;
			 answer[0]=answer[0]>answer[1]?answer[0]:answer[1];
				continue;
			}
			else continue;
			k-=(i+1);
			for(l=0;l<=i;l++) bomb++;
			makeanti(bomb);
			j--;
			k+=(i+1);
			for(l=0;l<=i;l++) bomb--;
		}
}


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 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;

}


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);
    }
}


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 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 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;
	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;
}


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 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 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);
    }


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;
}


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 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);
}


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;
}


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;
}


int maxii(int n,int *a)
{
    int k,i,s;
    k=1;
    for(i=1;i<n;i++)
    {
        if ((a[i]<=a[0])&&(maxii(n-i,a+i)>(k-1)))
        k=maxii(n-i,a+i)+1;
    }
    return k;
}

main()
{
      int n,*k,i,j,c;
      int a[25];
      scanf("%d",&n);
      for (i=0;i<n;i++)
      scanf("%d",&a[i]);
      k=(int*)malloc(n*sizeof(int));
      c=1;
      for(j=0;j<n;j++)
      {
          if (c<maxii(n-j,a+j))
          c=maxii(n-j,a+j);
      }
      printf("%d",c);
}


int pfC(const void *x ,const void *y)
{
    int t;
    t=*((int*)x)-*((int*)y);
    return -t;
}
main()
{
	int n,t,i,j,a[25],b[25];
	scanf("%d",&n);
	//int*a=(int*)malloc(n*sizeof(int));
	//int*b=(int*)malloc(n*sizeof(int));

	for(int k=0;k<n;k++)
	{
		scanf("%d",&a[k]);
		b[k]=0;
	}
	b[n-1]=1;
	for(i=n-2;i>=0;i--)
	{
		for(j=i+1;j<n;j++)
		{
			if(a[i]>=a[j])
			{
				if(b[i]<b[j])
				{
					b[i]=b[j];
				}
			}
		}
		b[i]++;
	}
    qsort(b,n,sizeof(int),pfC);
	printf("%d",b[0]);
}


int main()
{
    int N;
    scanf("%d",&N);
    int *h=(int*)malloc((N+1)*sizeof(int));
    for(int i=1;i<=N;i++)
        scanf("%d",&h[i]);
    int *f=(int*)malloc((N+1)*sizeof(int));
    f[1]=1;
    for(int i=2;i<=N;i++)
       {
       int tem=0;
       for(int j=1;j<i;j++)
           {
           if(h[j]>=h[i])
              {
              if(f[j]>tem)
                 tem=f[j];
              }
           }
       f[i]=tem+1;
       }
    int max=-1;
    for(int i=1;i<=N;i++)
       {
       if(f[i]>max)
          max=f[i];
       }
    printf("%d",max);
}


void main()
{
	int k,data[25],ans[25],max;
	int i,j;
	scanf("%d",&k);
	for(i=0;i<25;i++)
		ans[i]=1;
	for(i=1;i<k;i++)
		scanf("%d ",&data[i-1]);
	scanf("%d",&data[k-1]);
	ans[0]=1;
	max=1;
	for(j=1;j<k;j++)
	{
		for(i=0;i<j;i++)
		{
			if(data[j]<=data[i])
			{
				if(ans[i]+1>ans[j])
					ans[j]=ans[i]+1;
			}
		}
		if(ans[j]>max)
			max=ans[j];
	}
	printf("%d",max);
}


int max(int a[],int k,int n,int z);
void main()
{
	int k,a[25],i,t;
	scanf("%d",&k);
	for(i=0;i<k;i++)
		scanf("%d",&a[i]);
	t=max(a,k,0,999999);
	printf("%d\n",t);
}
int max(int a[],int k,int n,int z)
{
	int b=0,c,m=a[n],t;
	if(n==k-1)
		if(a[n]<=z)
			t=1;
		else
			t=0;
	else
	{
		if(a[n]<=z)
		{
			c=max(a,k,n+1,z);
			z=a[n];
			b=1+max(a,k,n+1,z);
			if(b>c)
				t=b;
			else
				t=c;
		}
	   else
		 t=max(a,k,n+1,z);
	}
		return(t);
}


void main()
{
	int h[25], num[25], k, n, i, j, max, flag;
	scanf("%d",&n);
	for (i=0; i<n; i++)
	{
		scanf("%d",&h[i]);
		num[i]=0;
	}
	for (i=0; i<n; i++)
	{
		k=0;
		flag=0;
		for (j=0; j<i; j++)
			if (h[j]>=h[i])
			{
				if (!flag) {k=j;flag=1;}
				else if(num[j]>num[k]) k=j;
			}
		if (flag) num[i]=num[k]+1;
		else num[i]=1;
	}
	max=0;
	for (i=0; i<n; i++)
		if (num[i]>max) max=num[i];
	printf("%d\n",max);
}


int main()
{
int j,k,i,max=0;
scanf("%d",&k);
int *p=(int *)malloc(k*sizeof(int));
int *q=(int *)malloc(k*sizeof(int));
scanf("%d",&p[0]);
for(i=1;i<k;i++)
scanf(" %d",&p[i]);
for(i=0;i<k;i++)
q[i]=1;
for(i=k-2;i>=0;i--)
  for(j=i+1;j<k;j++)
	  if(p[i]>=p[j]&&q[j]>=q[i])
	  		  q[i]=q[j]+1;
for(i=0;i<k;i++)
 if(q[i]>max)
	 max=q[i];
printf("%d",max);

}


struct missile
{
    int num;
    int high;
};
struct missile a[25];
void f(int n,int sum);
int main()
{
    int i=0,j=0,sum=0,max=0;
    scanf("%d",&sum);
    //a=(struct missile*)malloc(sum*sizeof(struct missile));
    for(i=0;i<=sum-1;i++)       //read in
    {
        scanf("%d",&a[i].high);
    }
    for(i=sum-1;i>=0;i--)       //find num
    {
        f(i,sum);
    }
    for(i=0;i<=sum-1;i++)       //find max
    {
        if(a[i].num>max){max=a[i].num;}
    }
    printf("%d",max);
}
void f(int n,int sum)
{
    int i=0,t=1;//a[n].num???1?
    if(n==sum-1)
    {a[n].num=1;}
    else
    {
        a[n].num=1;
        for(i=n+1;i<=sum-1;i++)
        {
            if(a[n].high>=a[i].high)
            {
                if(a[i].num+1>a[n].num)
                {a[n].num=a[i].num+1;}      //??????  .XXX
            }
        }
    }
}


main()
{
      int i,j,n;
      scanf("%d",&n);
      int high[100],count[100];
      for(i=0;i<n;i++)
      {
             count[i]=0;
             scanf("%d",&high[i]);
      }
       high[n]=0,count[n]=0;
      for(i=n-1;i>=0;i--)
      {
             int step=0;
            for(j=i+1;j<=n;j++)
            {
                     if(count[j]>step)
                     {   if(high[j]<=high[i])
                         step=count[j];
                         }
            }
            count[i]=step+1;

      }
      int max=0;
      for(i=0;i<n;i++)
      if(count[i]>max)
      max=count[i];
      printf("%d",max);
      getchar();getchar();getchar(); getchar();getchar();getchar();
}


int main()
{

	int k,j,i,a[26]={0},length[26]={0},max=0;
	scanf("%d",&k);
	for(i=0;i<k;i++)
		scanf("%d",&a[i]);
	length[0]=1;

	for(i=1;i<k;i++)
	{
		length[i]=1;
		for(j=0;j<i;j++)
		{

			if(a[i]<=a[j] && length[i]<length[j]+1)
				length[i]=length[j]+1;
		}
	}

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

		if(length[i]>max)
			max=length[i];
	}

	printf("%d",max);

	return 0;
}


int LanJieShu( int x, int y, int c[])
{
	int j, t;
	if( x == y - 1)
		return 1;
	t = 0;
    for(j = x + 1; j < y; j ++)
	{
		if((c[j] <= c[x]) && (LanJieShu(j, y, c) > t))
			t = LanJieShu(j, y, c);
	}
	return(t + 1);
}
void main()
{
	int n, i, u;
	int a[26], b[26];
	scanf("%d", &n);
	for(i = 0; i < n; i ++)
		scanf("%d", &a[i]);
    for(i = 0; i < n; i ++)
        b[i] = LanJieShu( i, n, a);
    u = 0;
	for(i = 0; i < n; i ++)
	{
		if(b[i] >= u)
			u = b[i];
	}
	printf("%d\n", u);
}


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


main()
{
	int k=0,max=0;
	scanf("%d",&k);
	int *h=(int *)malloc(k*sizeof(int));
	int *p=(int *)malloc(k*sizeof(int));
	for(int i=0;i<k;i++)
	    scanf("%d",&h[i]);
	p[k-1]=1;
	for(int i=0;i<k-1;i++)
	{
	    for(int j=1;k-2-i+j<=k-1;j++)
		{
			if(h[k-2-i]>=h[k-2-i+j])
		    {
			    if(max<=p[k-2-i+j])
				max=p[k-2-i+j];
		    }
        }
		p[k-2-i]=max+1;
		max=0;
	}
		max=p[0];
		for(int i=0;i<k;i++)
		    if(max<p[i])
			   max=p[i];
	    printf("%d",max);
		free(h);
		free(p);
}


int main(void)
{
 int num,max=0;
 scanf("%d",&num);
 int a[num],flag[num];
 for (int i = 0; i < num; i ++)
 {
  scanf("%d",&a[i]);
  flag[i] = 1;
 }
 for (int i = 0; i < num; i ++)
 {
  for (int j = 0; j < i; j ++)
  {
   if (a[j] >= a[i])
   {
    flag[i] = flag[j] + 1 > flag[i] ? flag[j] + 1 : flag[i];
   }
  }
  if(flag[i]>max) max = flag[i];
 }
 printf("%d\n",max);
 return 0;
}


/*
 * lee2.cpp
 *
 *  Created on: 2011-6-8
 *      Author: 09143
 */
int kMis;
int Mis[30];
int Array[30];
void Lanjie(int iM)
{
	for(int i = iM; i < kMis; i ++)
	{
		if(Mis[iM - 1] >= Mis[i] && Array[iM - 1] <= Array[i])
			Array[iM - 1] = Array[i] + 1;
	}
	if(iM > 1) Lanjie(iM - 1);
	return;
}
int main()
{

	cin >> kMis;
	for(int i = 0; i < kMis; i ++)
		cin >> Mis[i];
	for(int i = 0; i < kMis; i ++)
	{
		Array[i] = 1;
	}
	Lanjie(kMis);
	int MaxLen = -1;
	for(int i = 0; i < kMis; i ++)
		if(MaxLen < Array[i]) MaxLen = Array[i];
	cout << MaxLen << endl;

}


int main()
{
 int high[26],n,maxnum[26],temp[26];//????i?????????????  ????
 scanf("%d",&n);
 int i,j,k;
 for(i=0;i<n;i++)
 scanf("%d",&high[i]);
 maxnum[n-1]=1;
 for(i=n-2;i>=0;i--)
 {
  int len=0;
  for(j=i+1;j<n;j++)
   {
    if(high[i]>=high[j])
     {temp[len++]=1+maxnum[j];}

   }
   int mark1=1;
  for(k=0;k<len;k++)
  {if(temp[k]>=mark1) mark1=temp[k];}
  maxnum[i]=mark1;
 }
 int mark2=0;
 for(i=0;i<n;i++)
 {if(maxnum[i]>=mark2) mark2=maxnum[i];}
 printf("%d",mark2);
 return 0;
}


const int N = 25 + 10;
int h[N];
int dp[N];

int main(void) {
	int ans, cnt, i, j;
	while (scanf("%d", &cnt) != EOF) {
		for (i = 0; i < cnt; ++i) {
			scanf("%d", h + i);
		}
		dp[0] = 1;
		for (i = 1; i < cnt; ++i) {
			dp[i] = 1;
			for (j = 0; j < i; ++j) {
				if (h[i] <= h[j]) {
					dp[i] = max(dp[i], dp[j] + 1);
				}
			}
		}
		ans = 0;
		for (i = 0; i < cnt; ++i) {
			ans = max(ans, dp[i]);
		}
		printf("%d\n", ans);
	}

	return 0;
}


int p(int n,int heightLimit,int *missileHeight,int missileNum)
{
	int a;
	int b;

	//???????????????
	if (n==missileNum-1)
		if (missileHeight[n]<=heightLimit)
			return 1;
		else
			return 0;
	else
		if (missileHeight[n]<=heightLimit)
		{
			a=1+p(n+1,missileHeight[n],missileHeight,missileNum);
		    b=p(n+1,heightLimit,missileHeight,missileNum);
			return a>b?a:b;
		}
		else
			return p(n+1,heightLimit,missileHeight,missileNum);
}

void main()
{
		int n,i,j;
		int *missileHeight;

		int highest=-1;

		scanf("%d",&n);
missileHeight=(int*)malloc(sizeof(int)*n);

for(i=0;i<n;i++)
{
	scanf("%d",&(missileHeight[i]));
	if (missileHeight[i]>highest) highest=missileHeight[i];
}
	printf("%d",p(0,highest,missileHeight,n));
}


const int MAXN=25+2;
int n;
int a[MAXN],f[MAXN];

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    	cin>>a[i];
    for(int i=0;i<n;i++)
      {
        f[i]=0;
        for(int j=0;j<i;j++)
          if(a[j]>=a[i]&&f[j]>f[i])
            f[i]=f[j];
        f[i]++;
      }
    int max=0;
    for(int i=0;i<n;i++)
      if(f[i]>max)
    	  max=f[i];
    cout<<max<<endl;
    return 0;
}


int k;
int h[30],f[30],l;

int main(){
	int i;
	scanf("%d",&k);
	for(i=0;i<k;i++){
		scanf("%d",h+i);
	}
	l=0;
	for(i=k-1;i>=0;i--){
		if(l==0||f[l-1]<=h[i])
			f[l++]=h[i];
		else{
			int mid,left=0,right=l-1;
			while(left<right){
				mid = (left+right)/2;
				if(h[i]>=f[mid]){
					left = mid+1;
				}
				else if(h[i]<f[mid]){
					right = mid-1;
				}
			}
			if(f[left]>h[i])
				f[left] = h[i];
			else
				f[left+1] = h[i];
		}
	}
	printf("%d\n",l);
}


int a[36],f[36];
int max(int a,int b)
{
	if(a>b)return a;else return b;
}
int main()
{
	int k,i,j;
	int ans=0;
	scanf("%d",&k);
	for(i=1;i<=k;i++)scanf("%d",&a[i]);
	f[0]=0;
	for(i=1;i<=k;i++)
	{
		f[i]=1;
		for(j=1;j<i;j++)
			if(a[i]<=a[j])
				f[i]=max(f[i],f[j]+1);
		ans=max(ans,f[i]);
	}
	cout<<ans<<endl;
	return 0;
}


int max(int x,int y)
{
    if(x>=y) return x;
    else return y;
}
int haha(int a[],int b[],int k)
{
    int i,j,c=0;
    b[k-1]=1;
    for(i=k-2;i>=0;i--)
    {
         for(j=i+1;j<k;j++)
         {
              if(a[i]>=a[j]) c=max(c,b[j]);
         }
         b[i]=c+1;
         c=0;
    }
    for(i=k-1;i>-1;i--) c=max(c,b[i]);
    return c;
}
int main()
{
    int a[25],b[25]={0},k,i;
    scanf("%d",&k);
    for(i=0;i<k;i++) scanf("%d",&a[i]);
    printf("%d",haha(a,b,k));

}


int main()
{
	int n,mm,maxj,i,j,k,max;
	scanf("%d",&n);
	int * height=(int*)malloc(sizeof(int)*n);
	int * amount=(int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&height[i]);
		amount[i]=1;
	}
	max=1;
		for(j=n-1;j>=0;j--)
		{
			maxj=1;
			for(k=j+1;k<n;k++)
			{

				if(height[j]>=height[k])
				{
					amount[j]=amount[k]+1;
					if(amount[j]>=maxj)
					{
						maxj=amount[j];
					}
				}
			}
			amount[j]=maxj;
			if(maxj>=max)
			{
				max=maxj;
			}
	}
	printf("%d",max);
	return 0;
}


int main()
{
	int length[500]={0},a[500];												//????
	int temp=0;
	int n;
	cin>>n;
	int i=0,j=0;
	for(i=1;i<=n;i++)
		cin>>a[i];
	length[1]=1;
	for(i=2;i<=n;i++)														//?????????
	{
		temp=0;
		for(j=1;j<i;j++)
		{
			if(a[i]<=a[j])
			{
				if(temp<length[j])
					temp=length[j];
			}
		}
		length[i]=temp+1;
	}
	int max=0;
	for(i=1;i<=n;i++)														//?????
		if(max<length[i])
			max=length[i];
	cout<<max<<endl;
	return 0;
}


void make(int a[], int n);

int main()
{
	int n = 0;
	int hight[26];
	int i = 0;

	cin >> n;
	for (i = 1; i <= n ; i++)
		cin >> hight[i];

	make(hight, n);

	return 0;
}

void make(int hight[], int n)
{
	int i = 0;
	int j = 0;
	int a[26];
	int max = 0;
	a[1] = 1;
	for (i = 2; i <= n; i++)
	{
		a[i] = 1;
		for (j = 1; j < i; j++)
			if ((hight[j] >= hight[i]) && (a[j] + 1 > a[i]))
				a[i] = a[j] + 1;
	}
	for (i = 1; i <= n; i++)
		max = (max > a[i] ? max : a[i]);
	cout << max;
}


int main()
{
	int dp[50];
	int m[50];
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>m[i];
	for(int i=0;i<n;i++)
	dp[i]=1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<i;j++)
		{
			if(m[i]<=m[j])
			{
				dp[i]=max(dp[j]+1,dp[i]);
			}
		}
	}
	int maxl=0;
	for(int i=0;i<n;i++)
	if(dp[i]>maxl)
	maxl=dp[i];
	cout<<maxl;
	}


int a[25];
int main()
{   int max(int k,int n);
    int i,n,m=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);}
    for(i=0;i<n;i++){
        if(max(i,n)>m)
        m=max(i,n);
        }
    printf("%d",m);
}
int max(int k,int n)
{
    int l=0,j;
    if (k==n-1)
    l=0;
    for(j=k+1;j<n;j++){
        if(a[j]<=a[k]){
           if(max(j,n)>l)
           l=max(j,n);
           }
           }
    return l+1;
}


int l,n;
int a[30];
void measure( int k,int s,int m)
{
	int i;
	if (k==n){if (s>l)l=s;}
	else {
			for (i=k+1;i<=n;i++)
				if (a[i-1]<=m)
					measure(i,s+1,a[i-1]);
			measure(n,s,m);
		}
}

void main()
{
	int i;
	scanf("%d",&n);
	for (i=0;i<n;i++)
		scanf("%d",&a[i]);
	measure(0,0,10000);
	printf("%d\n",l);
}


inline int max(int a,int b)
{return a>b?a:b;}
int n,a[30];
int after(int i,int fin,int n);
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	a[0]=1000000;
	cout<<after(1,0,n)<<endl;
	return 0;
}

 int after(int i,int fin,int n)
 {
	 if(i==n)
	 {
		if(a[n]<=a[fin])
		 return 1;
		else
			return 0;

	 }
	 else
	 {
		 int z;
		 if(a[i]<=a[fin])	z=max(1+after(i+1,i,n),after(i+1,fin,n));
		 else				z=after(i+1,fin,n);
		 return z;
	 }
 }


main()
{
    int k;
    scanf("%d",&k);
    int*a=(int*)malloc(k*sizeof(int));
    int i;
    for(i=0;i<k;i++)
    {
                    scanf("%d",&a[i]);
    }
    int*b=(int*)malloc(k*sizeof(int));
    for (i=0; i<k; i++)
		{b[i]=1;}
	for (int i=1; i<k; i++)
	{
	    for (int t=0; t<i; t++)
		if (a[t]>=a[i] && b[t]+1>=b[i])
	             b[i] = b[t]+1;
    }
 //   ????
   int max=b[0];
   for (int i=1; i<k; i++)
	 {if (b[i] > max) max=b[i]; }

    printf("%d",max);
}


int k[25],n;
int f(int max,int i,int sum)
{
	int p,q=0;
	if(i==n)return sum;
	else
	{
		p=f(max,i+1,sum);
		if(max>k[i+1])q=f(k[i+1],i+1,sum+1);
		return p>q?p:q;
	}
}
void main()
{
	int i;scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&k[i]);
	printf("%d",f(2147483647,0,0));
}


const int maxn=100;
int a[maxn],n,f[maxn],ans;
void init()
{
     cin >>n;
     for (int i=0;i<n;i++)
         cin >>a[i];
 }
void solve()
{
     ans=0;
     for (int i=0;i<n;i++)
     {
         f[i]=1;
         for (int j=0;j<i;j++)
             if (a[j]>=a[i] && f[j]>=f[i])
                f[i]=f[j]+1;
         if (f[i]>ans)
            ans=f[i];
     }
 }
int main()
{
    init();
    solve();
    cout <<ans<<endl;
    return 0;
}


int main()
{
	int k,i,j;
	int h[26];
	int ans[200];
	memset(ans,0,sizeof(ans));
	cin>>k;
	for(i=0;i<k;++i)
	{
		cin>>h[i];
		ans[i]=1;
	}
	for(i=1;i<k;++i)
		for(j=i-1;j>=0;--j)
			if(h[j]>=h[i] && ans[j]+1>ans[i])
				ans[i]=ans[j]+1;
			int max=0;
	for(i=0;i<k;++i)
		if(ans[i]>max)
			max=ans[i];
	cout<<max<<endl;
	return 0;
}


int com(const void *a,const void *b)
{
    return(*(int *)a-*(int *)b);
}
int main()
{
   int n,i;
   int a[30];
   int s[30]={1};
   scanf("%d",&n);
   for(int i=0;i<n;i++)
   scanf("%d",&a[i]);
   for(int i=n-2;i>=0;i--)
   {
    for(int j=n-1;j>i;j--)
    {
     if(a[i]>=a[j])
     {
      s[i]=max(s[j]+1,s[i]);
     }
    }
   }
   qsort(s,30,sizeof(int),com);
   printf("%d",s[29]+1);
   getchar();
   getchar();
}


int main()
{
	int m[26],x;
	int cmp(int i,int k,int h[]);
	int max(int m[],int k);
	int k,i,h[26];
	scanf("%d",&k);
	for(i=1;i<=k;i++)
		scanf("%d",&h[i]);
	for(i=1;i<=k;i++)
		m[i]=cmp(i,k,h);
	x=max(m,k);
	printf("%d\n",x);
	return 0;
}
int max(int m[],int k)
{
	int big,i;
	big=m[1];
	for(i=1;i<=k;i++)
		if(big<m[i]) big=m[i];
	return big;
}
int cmp(int i,int k,int h[])
{
	int b[26],j,t=1;
	if(i==k) return 1;
	for(j=i+1;j<=k;j++)
		if(h[i]>=h[j])
		{
			b[t]=cmp(j,k,h);
			t++;
		}
	if(t==1) return 1;
	return max(b,t-1)+1;
}


int main()
{
	int height[25],amount[25]={0};
	int n,i,j,max;
	scanf("%d",&n);
	for(i=0;i<n-1;i++)
	{
		scanf("%d ",&height[i]);
	}
	scanf("%d",&height[n-1]);
	amount[n-1]=1;
	for(i=n-2;i>=0;i--)
	{
		max=0;
		for(j=i;j<n;j++)
		{
			if(amount[j]>max&&height[j]<=height[i])
			{
				max=amount[j];
			}
		}
		amount[i]=max+1;
	}
	for(i=0;i<n;i++)
	{
		if(amount[i]>max)
		{
			max=amount[i];
		}
	}
	printf("%d\n",max);
	return 0;
}


const int N = 1010 ;

int n, m, k ;
int q[N] ;
int f[N] ;

int main ()
{
	scanf ("%d", &n) ;
	for (int i = 1; i <= n; i ++ ) scanf ("%d", &q[i]) ;
	q[0] = 1000000000 ;
	for (int i =1; i <= n; i ++ )
		for (int j = 0; j < i; j++ )
			if (q[j] >= q[i])
				f[i] = max (f[i], f[j] + 1) ;
	int res = 0 ;
	for(int i = 1; i <= n ;i ++ ) res = max (res, f[i]) ;
	printf ("%d\n", res) ;
	return 0 ;
}


int max(int x,int y)
{
      if(x>=y)
      return x;
      else
      return y;
}

main()
{
      int i,j,k,p[25],result,a[25],b[25],sum;
      for(i=0;i<25;i++) a[i]=b[i]=p[i]=0;
      scanf("%d",&k);
      for(i=0;i<k;i++) scanf("%d",&p[i]);
      b[k-1]=1;
      for(i=k-2;i>=0;i--)
      {
                         sum=0;
                         for(int m=0;m<25;m++) a[m]=0;
                         for(j=k-1;j>i;j--)
                         {
                                            if(p[j]<=p[i]) a[j]=b[j];
                                            sum=max(sum,a[j]);
                         }
                         b[i]=sum+1;
      }
      result=0;
      for(i=0;i<k;i++) result=max(result,b[i]);
      printf("%d",result);

}


int main()
{
	int k;
	cin>>k;
	int a[30];
	int num[30];
	int i;
	for(i=1;i<=k;i++)
	{
		cin>>a[i];
		num[i]=0;
	}
	int max=0;
	for(i=k;i>=1;i--)
	{
		int m=0;
		for(int j=i+1;j<=k;j++)
		{
			if(a[i]>=a[j]&&num[j]>m)
			    m=num[j];
		}
		num[i]=1+m;
		if(num[i]>max)
			max=num[i];
	}
	cout<<max;

}


int main()
{
	int k;
	int a[30] = {0};
	int m[30] = {0};
	cin >> k;
	cin >> a[0];
	m[0] = 1;
	int temp = 1;
	for (int i = 1; i < k; i++)
	{
		cin >> a[i];
		int tempmax = 0;
		for (int j = i-1; j >= 0; j--)
			if (a[i] <= a[j] && m[j] > tempmax) tempmax = m[j];
		m[i] = tempmax + 1;
		if (m[i] > temp) temp = m[i];
	}
	cout << temp << endl;
	return 0;
}


int max(int a[],int n)
{
	int z,i,j,t,temp,r;
	int b[25];
	if(n==1)z=1;
	else if(n==0)z=0;
	else
	{
		for(i=0,r=0;i<n;i++)
	{
		for(j=i+1,t=0;j<n;j++)
			if(a[j]<=a[i])
			{
				b[t]=a[j];
				t++;
			}
		temp=max(b,t)+1;
		if(temp>r)r=temp;
	}
	z=r;
	}
	return z;
}

int main()
{
	int k,t,i;
	int bomb[25];
	scanf("%d\n",&k);
	for(i=0;i<k;i++)scanf("%d",&bomb[i]);
	t=max(bomb,k);
	printf("%d\n",t);
}


int max(int x,int y)
{  if(x>y) return x;
   else return y;
}

main()
{  int a[30];
   int b[30];
   int i,j,n,t;
   scanf("%d",&n);
   for(i=1;i<=n;i++)
   scanf("%d",&a[i]);
   for(i=1;i<=n;i++)
   b[i]=1;

   for(i=n-1;i>=1;i--)
{   for(j=i+1;j<=n;j++)
      if(a[i]>=a[j])
      b[i]=max(b[i],b[j]+1) ;

}
t=b[1];
for(i=2;i<=n;i++)
t=max(t,b[i]);
printf("%d",t);
getchar();
getchar();
}


int main()
{
	int h[40];
	int num[40];
	int n;
	cin>>n;
	for(int i=0;i!=n;++i)
		cin>>h[i];
	memset(num,0,sizeof(num));
	num[0]=1;
	for(int i=1;i<n;++i)
	{
		int maxi=1;
		for(int j=i-1;j>=0;--j)
		{
			if(maxi<num[j]+1 && h[j]>=h[i])
				maxi=num[j]+1;
		}
		num[i]=maxi;
	}
	int temp=0;
	for(int i=0;i!=n;++i)
	{
		if(num[i]>temp)
			temp=num[i];
	}
	cout<<temp<<endl;
	return 0;
}


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


int n;
int h[30];
int len[30];

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&h[i]);
	}
	len[0]=1;
	for(int i=1;i<n;i++)
	{
		len[i]=1;
		for(int j=0;j<i;j++)
		{
			if(h[j]>=h[i] && len[j]+1>len[i])
				len[i]=len[j]+1;
		}
	}
	int maxi=0;
	for(int i=0;i<n;i++)
		if(len[i]>maxi)
			maxi=len[i];
	printf("%d\n",maxi);
}


int main()
{
	int m[100]={0};
	int min=0;
	int ans[100]={0};
	int k=0;
	cin>>k;
	for(int i=0;i<=k-1;i++)
	{
		cin>>m[i];
	}
	ans[0]=1;
	int temp=0;
	for(int i=1;i<=k-1;i++)
	{
		temp=0;
		for(int j=i-1;j>=0;j--)
		{
			if(m[j]>=m[i])
			{
				if(temp<ans[j])
					temp=ans[j];
			}
		}
		ans[i]=temp+1;
	}
	int max=0;
	for(int i=0;i<=k-1;i++)
	{
		if(max<ans[i])
			max=ans[i];
	}
	cout<<max<<endl;
}


int main()
{
	int n, i,j,max,final;
	int tomb[26];
	int num[26];
	cin >> n;
	for (i =0; i<n;i++)
		cin >> tomb[i];
	memset(num,0,sizeof(num));
	num[n-1]=1;
	final = 0;
	for(i=n-2;i>=0;i--)
	{
		j = i+1;
		max = 0;
		while (j < n)
		{
			if (tomb[j] <= tomb[i] && num[j] > max)
				max = num[j];
			j ++;
		}
		num[i] = max + 1;
		if (num[i] > final)
			final = num[i];
	}
	cout << final << endl;
	return 0;
}


main()
{
      int k,i,x;
      scanf("%d",&k);
      int h[k];
      int a[k];
      for(i=0;i<k;i++)
      {
                       scanf("%d",&h[i]);
      }
      for(x=0;x<k;x++)
      {
                      a[x]=1;
      }
      int c,d;
      for(c=k-2;c>=0;c--)
      {
                         for(d=c+1;d<k;d++)
                         {

                                           if((h[c]>=h[d])&&(a[d]>=a[c]))
                                           a[c]=a[d]+1;
                         }
      }
      int y=1;
      int m;
      for(m=0;m<k;m++)
      {
                      if(a[m]>y)
                      y=a[m];
      }
      printf("%d",y);

      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();
      getchar();

}


int n;
int a[MAXN];
int f[MAXN];

void input()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

int main()
{
	input();
	for (int i = 0; i < n; i++)
		f[i] = 1;
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < i; j++)
			if (a[j] >= a[i] && f[j]+1 > f[i])
				f[i] = f[j]+1;
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
		if (f[i] > ans)
			ans = f[i];
	cout << ans << endl;
}


int max=0,n=0;
int a[30],line=0,f[30]={0},b[30]={0};
void main()
{
	int k,i,n=0;

	void missile(int i,int k);
	scanf("%d",&k);
	for(i=0;i<k;i++)
	{
		scanf("%d",&a[i]);
		if(line<a[i])
			line=a[i];
	}
	missile(0,k);
	printf("%d",max);
}
void missile(int i,int k)
{
	int j;
	for(j=0;j<2;j++)
	{
		if(j==0&&i!=k-1)
		{
			missile(i+1,k);
		}
		else
		{
		    if(a[i]<=line||i==k-1)
			{
				if(a[i]<=line)
				{
				b[i]=line;
				line=a[i];
		        n++;
				f[i]=1;
				}
		        if(i==k-1)
				{
			        if(max<n)
				        max=n;
					printf("\n");
				}
		        else
		            missile(i+1,k);
				if(f[i]==1)
				{
				n--;
				line=b[i];
				f[i]=0;
				}
			}
		}
	}
}


int n,i;
int h[26];
int max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}

int f(int t,int l)
{
	if(t==1)
	{
		if(h[1]>=l)
			return 1;
		else
			return 0;
	}

    else if(h[t]<l)
		return f(t-1,l);
	else
		return max(f(t-1,l),f(t-1,h[t])+1);

}

	void main()
{
		scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&h[i]);

	printf("%d",f(n,0));
}


int main()
{
    int k=0,count=0;
    int count1=0,count2=0;
    int max=0;
    int num[25][2];

    scanf("%d",&k);
    for(count=0;count<k;++count)
    {
        scanf("%d",&num[count][0]);
        num[count][1]=0;
    }
    for(count1=0;count1<k;++count1)
    {
        max=0;
        for(count2=0;count2<count1;++count2)
        {
            if(num[count2][1]>= max && num[count2][0]>=num[count1][0])
            {
                max = num[count2][1];
                num[count1][1]=max+1;
            }
        }
    }
    max = 0;
    for(count=0;count<k;++count)
    {
        if(num[count][1]>=max)
        {
            max = num[count][1];
        }
    }
    printf("%d",max+1);
}


int maxnum(int*a,int n,int up){
	if(n==0)return 0;
	int i,max=-1,t;
	for(i=0;i<n;i++){
		t=up;
		if(a[i]<=up||up==-1)t=a[i];
		else continue;
		if(maxnum(a+i+1,n-1-i,t)>max)max=maxnum(a+i+1,n-i-1,t);
	}
	return max+1;
}

int main(){
	int i,n,a[25];
	cin>>n;
	for(i=0;i<n;i++)cin>>a[i];
	cout<<maxnum(a,n,-1);
}


//?????????????(?????)
int result[40];//result[i]???a[i]????????????????
int max(int a,int b)
{
    if(a>b) return a;
    else return b;
}
void f(int a[],int n)
{
    /*??a[i]??????result?????result[j]???result[i]=1+result[j]*/
    int i,j,maxmium;
    result[1]=1;
    for(i=2;i<=n;i++)
    {
                     maxmium=0;
                     for(j=1;j<i;j++)
                     {
                                     if(a[j]>=a[i]) maxmium=max(result[j],maxmium);
                     }
                     result[i]=1+maxmium;
    }
}

main()
{
      int n,i,outcome=0;
      scanf("%d",&n);
      int a[40];
      for(i=1;i<=n;i++)
      {
                       scanf("%d",&a[i]);
      }
      f(a,n);
      for(i=1;i<=n;i++)
      outcome=max(outcome,result[i]);
      printf("%d\n",outcome);
}


int analyse(int *,int *,int,int);
int main()
{
	int k;
	int height[25],numbers[25]={0};
	int i,max,temp;
	scanf("%d",&k);
	for(i=0;i<k;i++)
		scanf("%d",height+i);
	max=numbers[24]=1;
	for(i=23;i>=0;i--)
	{
		temp=analyse(height,numbers,i,k);
		if(temp>max)	max=temp;
	}
	printf("%d\n",max);
	return 0;
}
int analyse(int *height,int *numbers,int seq,int k)
{
	int max=0,temp,i;
	for(i=k-1;i>seq;i--)
	{
		if(height[seq]>=height[i])
		{
			temp=numbers[i];
			if(temp>max) max=temp;
		}
	}
	max++;
	numbers[seq]=max;
	return max;
}


int main(){
	int k;
	int temp=0;
	int max=1;
	int z=0;
	cin>>k;
	int a[30];
	int b[30]={0};
	for (int i=0;i<k;i++){
		cin>>a[i];
	}
	b[0]=1;
	for (int i=1;i<k;i++){
		for(int j=0;j<i;j++){
			if(a[j]>=a[i]){
				temp=b[j]+1;
				if(max<temp){
					max=temp;
				}
			}
		}
		b[i]=max;
		if(max>z){
			z=max;
		}
		max=1;
	}
	cout<<z;
	return 0;
}


int*p;
int n;
int max(int t,int k)
{
    if(t>k) return t;
    else return k;
    }
int pd(int i,int h)
{   if(i==n)   return 0;
    if(p[i]>h) return pd(i+1,h);
    if(p[i]==h) return pd(i+1,h)+1;
   return max(pd(i+1,p[i])+1,pd(i+1,h));
    }
int main()
{
    int i,j,k;
    scanf("%d",&n);
    p=(int*)malloc(n*sizeof(int));
    for(i=0;i<n;i++)
    scanf("%d",&p[i]);
    k=pd(0,800000);
    printf("%d",k);
    free(p);
}


int main()
{
	int n,i,j,num;
	int hei[30],max[30];
	cin >> n;
	for(i = 0; i < n;i ++)
	{
		cin >> hei[i];
		max[i] = 1;
	}
	for(i = 0; i < n;i++)
	{
		num = 0;
		for(j = 0; j < i ;j++)
		{
			if(hei[j] >= hei[i])
			{
				if(max[j] > num)
					num = max[j];
			}
		}
		max[i] = num + 1;
	}
	num = 0;
	for(i = 0;i < n;i++)
	{
		if(max[i] > num)
			num = max[i];
	}
	cout << num << endl;
	return 0;
}


int num[30];
int dst[30];

int main()
{
	memset(dst, 0, sizeof(dst));
	int n;
	int ans;
	cin>>n;
	for(int i = 0; i < n ; i++)
	{
		cin>>num[i];
	}
	dst[0] = 1;
	int temp, max;
	for(int i = 1; i < n; i++)
	{
		max = 1;
		for(int j = 0; j < i; j++)
		{

			if(num[i] <= num[j] )
			{
				temp = dst[j] + 1;
				if(max < temp)
					max = temp;
			}
		}
		dst[i] = max;
	}
	max = 0;
	for(int i= 0; i < n; i++)
	{
		//cout<<dst[i]<<" ";
		if(max < dst[i])
			max = dst[i];
	}

	cout<<max;
	return 0;
}


int main()
{
	int n,i,height[30],num[30],j,max = -1;
	cin>>n;
	for (i = 0;i < n;i++)
		cin>>height[i];
	for (i = 0;i < n;i++)
		num[i] = 1;

	for (i = 1;i < n;i++)
		for (j = i-1;j >=0 ;j--)
		{
			if (height[j]>=height[i]&& num[j]+1 > num[i])
				num[i] = num[j] + 1;

		}
	for (i = 1;i < n;i++)
		if(num[i]>max)
			max = num[i];
	cout<<max<<endl;

}


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


int main()
{
	int a[30],count=0,n,temp,i;
	cin>>n;
	while(n--)
	{
		cin>>temp;
		for(i=0;i<count;i++)if(temp>a[i]){a[i]=temp;break;}
		if(i>=count){a[i]=temp;count++;}
	}
	cout<<count<<endl;
	return 0;
}


void main()
{
	int n,high[30],point,m,sum1,sum2,check;
	scanf("%d",&n);
	for (m=0;m<n;m++)
		scanf("%d",&high[m]);
	for(check=1;check==1;)
	{
		check=0;
		for(point=0;point<n-1;point++)
		{
		if(high[point]<high[point+1])
		{
			check=1;
			for(m=0,sum1=0;m<point;m++)
				if(high[m]<high[point+1]) sum1++;
			for(m=point+2,sum2=0;m<n;m++)
				if(high[m]>high[point]) sum2++;
			if(sum1>sum2)
			{
				for (m=point+1;m<n-1;m++)
				{
					high[m]=high[m+1];
				}
			}
			else
			{
				for (m=point;m<n-1;m++)
				{
					high[m]=high[m+1];
				}
				point--;
			}
			n--;
		}
		}
	}
	printf("%d\n",n);
}


int c[25], d[25], k;
int D(int a)
{
	int m = 1;
	for (int i = a + 1; i <= k - 1; i ++)
		if (c[i] <= c[a] && m < D(i) + 1)
			m = D(i) + 1;
	return m;
}

int main()
{
	int max = 0;
	cin >> k;
	for (int i = 0; i < k; i ++)
		cin >> c[i];
	for (int i = k - 1; i >= 0; i --)
	{
		d[i] = D(i);
		if (d[i] > max)
			max = d[i];
	}
	cout << max;
	return 0;
}


int missle[25];
int n;
int Intercept(int i,int j){
	int k,max=1,sum=1;
	for(k=i+1;k<j;k++){
		if(missle[k]<=missle[i]&&missle[k]>=missle[j])
			sum=Intercept(k,j)+1;
		else continue;
		if(sum>max)max=sum;
		sum=1;
	}
	return max;
}
void main()
{
	int i,j,max=1,sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&missle[i]);
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(missle[j]<=missle[i]){
				sum=Intercept(i,j)+1;
			}
			else continue;
		    if(sum>max)max=sum;
		    sum=0;
		}
	}
	printf("%d\n",max);
}


struct DP
{
	int height;
	int num;
}dp[26];

int main()
{
	int k,i,j;
	int h[26];
	int  Max;
	cin>>k;
	for(i=1;i<=k;i++)
	{
		cin>>h[i];
	}
	dp[0].height=INT_MAX;
	dp[0].num=0;
	for(i=1;i<=k;i++)
	{
		dp[i].height=h[i];
		Max=INT_MIN;
		for(j=0;j<i;j++)
		{
			if(Max<dp[j].num && dp[j].height>=dp[i].height)
				Max=dp[j].num;
		}
		dp[i].num=Max+1;
	}
	Max=INT_MIN;
	for(i=0;i<=k;i++)
		if(Max<dp[i].num) Max=dp[i].num;
	cout<<Max<<endl;

	return 0;
}


int cal(int *p,int N,int M){//NÎa¿aê¼±è½Ï?Äêy?ÄÎ»ÖÃ?¬MÎaê?ÏÂ?Äêy?Ä¸öêy?¬N+M=×ü?Äêy¸öêy
	int i,max,sub;
	max=0;
	if(M==0){
		return 1;
	}
	for(i=N+1;i<=N+M;i++){
		if(*(p+N)>=*(p+i)){
			sub=cal(p,i,N+M-i);
			if(sub>=max){
				max=sub;
			}
		}
	}
	return max+1;
}

int main()
{
	int k,i;
	scanf("%d\n",&k);
	int height[26];
	height[0]=10000000;
	scanf("%d",&height[1]);
	for(i=1;i<=k-1;i++){
		scanf(" %d",&height[i+1]);
	}

	printf("%d",cal(height,0,k+1)-2);

	return 0;
 }


int Max(int n,int a[])
{
   int x=0;
   for(int i=0;i<n;i++)
   {
       if(x<a[i])
       x=a[i];
   }
   return x;
}
main()
{
   int x,n,i,j,b=1;
   int *p;
   int *q;
   scanf("%d",&n);
   p=(int *)malloc(n*sizeof(int));
   q=(int *)malloc(n*sizeof(int));
   for(i=0;i<n;i++)
       scanf("%d",p+i);
   for(i=n-1;i>=0;i--)
   {

      {   x=0;
          for(j=i+1;j<n;j++)
          {
             if((p[i]>=p[j])&&(x<q[j]))
                 x=q[j];
          }
          q[i]=x+1;
      }
   }
   printf("%d",Max(n,q));
}


int main()
{
	int k, h[25];
	int len[25];
	int i, j;
	cin >> k;
	for(i = 0; i < k; i ++)
		cin >> h[i];
	len[0] = 1;
	int ans = 1;
	for(i = 1; i < k; i ++)
	{
		/*if(h[i] <= h[i - 1])
			len[i] = len[i - 1] + 1;
		else
			len[i] = 1;
		if(len[i] > ans)
			ans = len[i];*/
		int temp = -1, tIndex = -1;
		for(j = 0; j < i; j ++)
		{
			if(h[j] >= h[i])
			{
				if(len[j] > temp)
				{
					temp = len[j];
					tIndex = j;
				}
			}
		}
		if(temp == -1)
			len[i] = 1;
		else
			len[i] = len[tIndex] + 1;
		if(len[i] > ans)
			ans = len[i];
	}
	cout << ans << endl;
	return 0;
}


int n,a[99];
void main()
{
	int f(int,int,int);
	int i,max;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	max=f(99999,0,0);
	printf("%d\n",max);
}
int f(int hi,int num,int i)
{
	int t1,t2;
	while(a[i]>hi)
		i++;
	if(i>=n)
		return num;
	t1=f(hi,num,i+1);
	t2=f(a[i],num+1,i+1);
	return t1>t2?t1:t2;
}


char max(char a[],char i)
{
	char j,m=a[0];
	for(j=1;j<i;j++)
		if(m<a[j])
			m=a[j];
	return(m);
}

void main()
{
	int h[N]={0};
	char n,i,j;
	scanf("%d",&n);
	for(i=n;i>=1;i--)//nixu!!
		scanf("%d",&h[i]);//h[0]=0
	char mis[N]={0},temp[N]={0};
	mis[0]=0;
	for(i=1;i<=n;i++)
	{
		for(j=0;j<=i-1;j++)//the most that is below h[i]
		{
			if(h[i]>=h[j])
				temp[j]=mis[j]+1;
			else
				temp[j]=0;//
		}
		mis[i]=max(temp,i);
	}
	for(i=0;i<=n;i++)
		printf("%d ",mis[i]);
	printf("%d",max(mis,n+1));

}


int sta[20002];
int mycmp(const void *a,const void *b)
{
	return *(int*)a-*(int*)b;
}
int main()
{
	int input[30]={0};
	int cnt[30]={0};
	int n;
	cin>>n;
	int i;
	for(i=0;i<n;i++)
		cin>>input[i];
	cnt[0]=1;
	for(i=1;i<n;i++)
	{
		int max=0;
		for(int k=i-1;k>=0;k--)
		{
			if(cnt[k]>max&&input[k]>=input[i])
				max=cnt[k];
		}
		cnt[i]=max+1;
	}
	int m=0;
	for(i=0;i<n;i++)
		if(m<cnt[i])
			m=cnt[i];
	cout<<m<<endl;
	return 0;
}


void Qsort(int a[],int low,int up)//????????
{
    int i,j,k,x;
    if (low>=up) return;
    else
    {
        k=a[low];
        j=low;
        for (i=low;i<=up;i++)
        {
            if (a[i]>k)
            {
                j++;
                x=a[i];
                a[i]=a[j];
                a[j]=x;
            }
        }
    }
    x=k;
    a[low]=a[j];
    a[j]=x;
    Qsort(a,low,j-1);
    Qsort(a,j+1,up);

}
int num(int a[],int low,int up)
{
    if(low>=up)
    {return 1;}
    int i,j,b[26]={0};
    j=0;
    for(i=low+1;i<=up;i++)
     {if(a[i]<=a[low])
     {b[j]=num(a,i,up);j++;}}
    Qsort(b,0,25);
    return b[0]+1;
}
int main(void)
{
    int i,j,m,n,c,d;
    scanf("%d",&n);
    int a[n],b[n];
    for(i=0;i<n;i++)
    {scanf("%d",&a[i]);}
    for(i=0;i<n;i++)
    {b[i]=num(a,i,n-1);}
    Qsort(b,0,n-1);
    printf("%d\n",b[0]);

}


//?? - ????-???????????

int main()
{
    int num(int n,int*p);
    int n;
    int i=0;
    int*p;
    scanf("%d",&n);
    p=(int*)malloc(sizeof(int)*n);
    for(i=0;i<n;i++) scanf("%d",p+i);
    printf("%d",num(n,p));
    getchar();
    getchar();
    getchar();

}
int num(int n,int*p)//????????
{
    int i,j,tem=0,a=0;
    int *max=(int*)malloc(sizeof(int)*n);
    max[n-1]=1;
    for(i=n-2;i>=0;i--)
    {
                       tem=0;
                       for(j=n-1;j>i;j--)
                       {
                                         if(p[i]>=p[j])
                                         {
                                                      if(tem<max[j])
                                                      tem=max[j];
                                         }
                       }
                       max[i]=tem+1;
    }
    a=0;
    for(i=0;i<n;i++)
    if(max[i]>a)a=max[i];
    return a;

}


main()
{
      int n;
      scanf("%d",&n);
      int d[n];
      for(int i=0;i<n;i++)
      {
              scanf("%d",d+i);
      }
      int opt[n];
      for(int i=0;i<n;i++)
      {
              opt[i]=0;
      }
      for(int i=n;i>=0;i--)
      for(int j=i;j<n;j++)
      {
              if((d[i]>=d[j])&&(opt[i]<=opt[j]+1))
              opt[i]=opt[j]+1;
      }
      int max=1;
      for(int i=0;i<n;i++)
      {
              if(opt[i]>max)
              max=opt[i];
      }
      printf("%d",max);
}


int num=0;
int input[26];
int state[26];
int main()
{
	int n;
	int i,j;
	scanf("%d",&n);
	for(i=1;i<n;i++)
		state[i]=1;
	for(i=0;i<n;i++)
		scanf("%d",&input[i]);
	state[0]=1;
	for(j=1;j<n;j++)
	{
		int min=1;
		for(i=0;i<j;i++)
		{
			if(input[i]>=input[j])
			{
				if(state[i]+1>min)
					min=state[i]+1;
			}
		}
		state[j]=min;
	}
	int sum=0;
	for(i=0;i<n;i++)
	{
		if(state[i]>sum)
			sum=state[i];
	}
	printf("%d\n",sum);
	return 0;
}


int a[MAXN], f[MAXN] = {0},n,longest_index=-1,longest_f = -1;

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

	{
		int i,j;
		for (i=0; i<n;++i)
		  f[i] = 1;
		for (i=n-2; i >= 0; --i)
		{
		  for (j=i+1;j<n;++j)
		  {
			if ((f[i]<f[j]+1 )&& (a[i] >= a[j]))
			{
				f[i]=f[j]+1;
				if (longest_f<f[i])
				{
				  longest_f=f[i];
				  longest_index=i;
				}
			}
		  }
		}
	}

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

}


const int maxn=30;
int h[maxn];
int f[maxn];
int main()
{
	int n;
//	freopen("readin","r",stdin);
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++)scanf("%d",h+i);
	f[1]=1;
	int j;
	int max=0;
	for(i=2;i<=n;i++)
	{max=0;
		for(j=1;j<=i-1;j++)if(h[i]<=h[j])
		{
			if(max<f[j])
				max=f[j];
		}
		f[i]=max+1;
	}
	max=0;
	for(i=1;i<=n;i++)if(max<f[i])
		max=f[i];
	printf("%d\n",max);
	return 0;
}


int main()
{
	int n;
	int num[30];
	int count[30];
	cin >> n;
	int i;
	int j;
	for(i = 0; i < n; i ++)
	{
		cin >> num[i];
		count [i] = 1;
	}
	for(i = 0; i < n; i ++)
	{
		for(j = 0; j < i; j ++)
		{
			if(num[i] <= num[j])
			{
				if(count[i] < count[j] + 1)
				{
					count[i] = count[j] + 1;
				}
			}
		}
	}
	int max = 1;
	for(i = 0; i < n; i ++)
	{
		if(count[i] > max)
		{
			max = count[i];
		}
	}
	cout << max << endl;
	return 0;
}


main()
{
      int k;
      int j=0;
      int max=0;
      int i,m;
      scanf("%d",&k);
      int height[k],b[k];
      while(j<k){
                 scanf("%d",&height[j]);
                 j++;
                 }
      j=j-1;
      while(j>=0){
                  for(i=j+1;i<k;i++){
                                     if(height[i]<=height[j]&&b[i]>max)
                                        max=b[i];
                                     }
                  b[j]=max+1;
                  max=0;
                  j--;
                  }
      for(i=0;i<k;i++){
                       if(b[i]>max)
                          max=b[i];
                       }
      printf("%d",max);
}


int MAX(int a,int b)
{
    return (a>b?a:b);
}
int FIRE(int *h,int m,int i,int j)
{
    if(i==j) return m>=h[j];
    else if(m>=h[i]) return MAX(FIRE(h,m,i+1,j),FIRE(h,h[i],i+1,j)+1);
    else if(m<h[i]) return FIRE(h,m,i+1,j);
}
main()
{
      int n,i,j,h[26];
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      scanf("%d",h+i);
      printf("%d",FIRE(h,65530,1,n));//????????65530?
}


int main()
{
	int n,i,a[1000],*p,min=31999;
	cin>>n;
	for(i=0;i<n;i++) cin>>a[i];
	p=a;
	int daodan(int i,int min,int *p,int n);
	cout<<daodan(0,min,p,n);
	return 0;
}
int max(int a,int b)
{
	if(a>b) return a;
	else return b;
}
int daodan(int i,int min,int *p,int n)
{
	if(i==n) return 0;
	if(*(p+i)<=min) return max(daodan(i+1,*(p+i),p,n)+1,daodan(i+1,min,p,n));
	else return daodan(i+1,min,p,n);
}


const int N=30;

int a[N];
int len[N];

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


int a[1000],n,f[999][999];
int max(int a,int b) {if(a>b) return a;else return b;}
int daodan(int s,int h)
{
	if(s==n) return 0;
	if(h>=a[s]) return max(daodan(s+1,a[s])+1,daodan(s+1,h));
	else return daodan(s+1,h);
}

int main()
{
	int i;
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i];
	cout<<daodan(0,31999);
	return 0;
}


int dd(int no,float h);
int n,a[25];
int main()
{
	int i;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cout<<dd(1,10000)<<endl;
	return 0;
}
int dd(int no,float h)
{
	while(h<a[no-1])
	{	if(no==n)
			break;
	     no++;
	}
	if(no==n)
	{
		if(h>=a[n-1])
		{return 1;}
	    else
		{return 0;}
	}
	else
	{
		int b=dd(no+1,a[no-1]);int c=dd(no+1,h);
		if (b>=c)
		{	return b+1;}
		else
		{	return c;}
	}
}


int max(int a,int b)
{
    if(a>b) return a;
    else return b;
}
int main()
{
    int k,i,j,h[25],dp[25];
    scanf("%d",&k);
    for(i=0;i<k;i++) scanf("%d",&h[i]);
    for(i=0;i<k;i++) dp[i]=1;
    for(i=1;i<k;i++)
        for(j=0;j<i;j++)
            if(h[j]>=h[i]) dp[i]=max(dp[i],dp[j]+1);
    int m=0;
    for(i=0;i<k;i++) m=max(m,dp[i]);
    printf("%d\n",m);
}


int height[26];
int max[26];
void cha(int n)
{
	int premax,i,j;
	for(i=1;i<=25;i++)
	max[i]=0;
	for(i=1;i<=n;i++)
	{   max[i]=1;
		for(j=1;j<i;j++)
		{
		if(height[i]<=height[j])
		{
		premax=max[j]+1;
		if (premax>max[i])
		max[i]=premax;
	    }
	    }
	}
}
int main()
{
	int n,num,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	scanf("%d",&height[i]);
	cha(n);
	num=-1;
	for(i=1;i<=n;i++)
	{
		if(num<max[i])
		num=max[i];
	}
	printf("%d",num);
}


int compare(int x,int y)
{
    if(x<=y)
    x=y+1;
    return x;
}
main()
{
      int i,n,r,a,j;
      scanf("%d",&n);
      int *p=(int *)malloc(n*sizeof(int));
      for(i=0;i<n;i++)
      scanf("%d",&p[i]);
      int *q=(int *)malloc(n*sizeof(int));
      //int q[25];
      for(j=n-1;j>=0;j--)
       {
         q[j]=1;
         for(r=n-1;r!=j;r--)
         {
           if(p[j]>=p[r])
           q[j]=compare(q[j],q[r]);
         }
         //q[j]=q[j]+1;
       }
       int max;
       max=q[0];
      for(a=1;a<n;a++)
      {
        if(q[a]>max)
        max=q[a];
      }
      printf("%d",max);
      return 0;
}


int main(int argc, char* argv[])
{
	int k;
	scanf("%d",&k);
	int a[25];
	int i,j,temp=0;
	for(i=0;i<k;i++){
	scanf("%d",&a[i]);
	}
	int max[25];
	for(i=0;i<k;i++){
		max[i]=1;}

	for(i=k-2;i>=0;i--){

		for(j=i+1;j<k;j++){
		if(a[i]>=a[j]) temp=max[j]+1;
		if(temp>max[i]) max[i]=temp;
		}

	}
	int nmax=0;
	for(i=0;i<k;i++){
	if(max[i]>nmax) nmax=max[i];}
	printf("%d\n",nmax);

	return 0;
}


int num(int k,int i,int *p,int height){
	if(i==k)return 0;
	if(*(p+i)>height)return(num(k,i+1,p,height));
	if(*(p+i)==height)return(num(k,i+1,p,height)+1);
	int a=num(k,i+1,p,height);
	int b=num(k,i+1,p,*(p+i))+1;
	return a>b?a:b;
}
int main(){
	int k,h[25],i;
	scanf("%d",&k);
	for(i=0;i<k;i++)scanf("%d",&h[i]);
	printf("%d",num(k,0,h,1000000000));
	return 0;
}


int main(void)
{
 int num ;
 scanf("%d",&num);
 int a[num],flag[num];
 for (int i = 0; i < num; i ++)
 {
  scanf("%d",&a[i]);
  flag[i] = 1;
 }
 for (int i = 0; i < num; i ++)
 {
  for (int j = 0; j < i; j ++)
  {
   if (a[j] >= a[i])
   {
    flag[i] = flag[j] + 1 > flag[i] ? flag[j] + 1 : flag[i];
   }
  }
 }
 int max = flag[0];
 for (int i = 1; i < num; i ++)
 {
  if (flag[i] > max)
   max = flag[i];
 }
 printf("%d\n",max);
 return 0;
}


int k=0,n,a[26]={0};
const int y=1000000;
void lanjie(int i, int m,int h)
{
    if(i==n+1)
	{
		if(m>k) k=m;
		return ;
	}
	if(m+n-i<k) return ;
	if(h>=a[i])
	    lanjie(i+1,m+1,a[i]);
	lanjie(i+1,m,h);
	return;
}

int main()
{
    int i;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	lanjie(1,0,y);
	cout<<k<<endl;

	return 0;
}


int a[29],max[29]={0},count[29]={0};
int N;
int select(int x)
{    if(count[x]==0)
    {

     int i;
 for (i=x+1;i<=N;i++)
     {if (a[x]>=a[i])
       {if(max[x]<=select(i)){max[x] = select(i)+1;}
       }
       }
        if(max[x]==0)
                     {max[x]=1;}
        count[x]=1;
 }
 /*printf("%d ?  ?  %d?    ",x,max[x]);*/
return max[x];}

main()
{   int maxm;
    scanf("%d",&N);
    for(int j=1;j<=N;j++)
    {scanf("%d",&a[j]);
    }
    maxm=select(1);
    for(int k=2;k<=N;k++)
    {if(maxm<select(k))
                       {maxm=select(k);}
    }
     /*for(int j=1;j<=N;j++)
    {printf("%d ?  ?  %d?   \n",j,select(j));
    } */
      printf("%d",maxm);
      }


int a[25],num[25]={0};
int main()
{
	int k=0,i,n;
	int search(int i,int n);
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=n-1;i>=0;i--)
	{
		num[i]=1+search(i,n);
	}
	for(i=0;i<n;i++)
	{
  		if(k<num[i])  k=num[i];
	}
	printf("%d",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 left(int *h,int i);

void main()
{
	int n,i,h[MAX],num,max;

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",h+i);

	for(i=n-1;i>=0;i--){
		num=left(h,i);
		if(i==n-1)
			max=num;
		else if(num>max)
			max=num;
	}

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

int left(int *h,int i)
{
	int j,flag=0,num,max;

	if(i==0)
		return 1;
	else{
		for(j=i-1;j>=0;j--){
			if(*(h+j)>=*(h+i)){
				num=left(h,j)+1;
				if(flag==0){
					max=num;
					flag=1;
				}
				else if(num>max)
					max=num;
			}
		}
		if(flag==0)
			return 1;
		else
			return max;
	}
}


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

//	memset(h,0,sizeof(h));
//	memset(r,0,sizeof(r));

	r[k-1]=1;
	for(i=k-2;i>=0;i--)
	{
		if(r[i]>=r[i+1]){
			cout<<"first way taken"<<endl;
			r[i]=r[i+1]+1;
		}
		else
		{
			int max=0;
			for(j=i+1;j<k;j++)
			{
				if(h[j]<=h[i]&&r[j]>max)
					max=r[j];
			}
			r[i]=max+1;
		}
	}
	int ans=0;
	for(i=0;i<k;i++)
	{
		//cout<<r[i]<<endl;
		if(r[i]>ans) ans=r[i];
	}
	cout<<ans;

}


int a[25];
int n;
int changdu(int i)
{
	int j,max;
	max=0;
	if(i==n-1)
	max=0;
	for(j=i+1;j<n;j++)
	{
		if(a[j]<=a[i])
	{
		if(changdu(j)>max)
		max=changdu(j);
	}
	}
	return(max+1);

}
int main()
{
	int max,i;
	max=0;

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

}


int k,a[26]={0},b[26]={0},max=0;

void num(int site,int height)
{
	int i,amount=0,h;
	if(site==k)
	{
		for(i=0;i<k;i++)
		{
			if(b[i]==1)
			{
				amount++;
			}
		}
		if(max<amount) {max=amount;}

	}
	else
	{
		if(height<a[site])
		{
			num(site=site+1,height);
			site--;
		}//site++?????site??????????
		else
		{
			num(site=site+1,height);
			site--;
		    b[site]=1;h=height;
            height=a[site];
	    	num(site=site+1,height);
			site--;
			b[site]=0;height=h;
		}

	}
}

void main()
{
   int i;
   scanf("%d",&k);
   for(i=0;i<k;i++)
   {
	   scanf("%d",&a[i]);
   }
   num(0,30000);
printf("%d",max);

}


int a[30],n;
int max(int p,int q){
	if (p>=q) return p;
	else return q;
}
int shot(int x,int y){
	if (x==n){
		if (a[x]<=y)  return 1;
		else return 0;
	}
	else {
		if (a[x]>y) return (shot(x+1,y));
		else return (max(shot(x+1,y),shot(x+1,a[x])+1));
	}
}
int main(){
	int i,m=0;
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	m=shot(1,9999);
	printf("%d",m);
	return 0;
}


int dd[25];
int k;
int maxnum = 0;

void fun(int p, int num,int hight)
{
	if(p > k)
	{
		if(num > maxnum)
			maxnum = num;
		return;
	}
	if(dd[p] <= hight)
	{
		fun(p + 1,num + 1,dd[p]);
		fun(p + 1,num,hight);
	}
	else
		fun(p + 1,num,hight);
	return;
}

int main()
{
	cin >> k;
	for(int i = 0;i < k;i++)
		cin >> dd[i];
	fun(0,0,65535);
	cout << maxnum - 1<< endl;
}


int count[30],hgt[30],n,i,j,max,temp;
void m(int s,int t);
void main()
{
	for(i=1;i<=25;i++){
		count[i]=0;
	}
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&hgt[i]);
		count[1]=1;
	}
	for(i=2;i<=n;i++){
		temp=0;
		for(j=1;j<i;j++){
			if(hgt[i]<=hgt[j]){
				if(temp<count[j]){
					temp=count[j];
				}
			}
		}
		count[i]=temp+1;
	}
	max=0;
	for(i=1;i<=n;i++){
		if(max<count[i]){
			max=count[i];
		}
	}
	printf("%d\n",max);
}


int main()
{
   int n,i,j,*b,max,maxn=0,*a;
   scanf("%d",&n);
   a=(int *)malloc(sizeof(int)*n);
   b=(int *)malloc(sizeof(int)*n);
   for (i=0;i<n;i++)
     {
         scanf("%d",a+i);
         b[i]=0;
     }
   for (i=n-1;i>-1;i--)
   {
       max=0;
       for (j=n-1;j>i;j--)
         if (a[j]<=a[i]&&b[j]>=max)
           max=b[j];
       b[i]=max+1;
       if (b[i]>maxn)
         maxn=b[i];
   }
   printf("%d\n",maxn);
}


int aMaxLen[35];
int nTmp;
int main()
{
	int k,i;
	cin>>k;
	int b[25];
	for(i=0;i<k;i++)
		cin>>b[i];
		aMaxLen[1]=1;
	for(i=2;i<=k;i++)
	{
		int nTmp=0;
		for(int j=1;j<i;j++)
		{
			if(b[i]<b[j])
			{
				if(nTmp<aMaxLen[j])
					nTmp=aMaxLen[j];
			}
		}
		aMaxLen[i]=nTmp+1;
	}
	int nMax=-1;
	for(i=1;i<=k;i++)
		if(nMax<aMaxLen[i])
			nMax=aMaxLen[i];
	cout<<nMax<<endl;

	return 0;
}


int num(int m[],int i,int k);
void main()
{
    int k,i,t,ans=0;
    int m[25];
    scanf("%d",&k);
    for(i=0;i<k;i++)
        scanf("%d",&m[i]);
    for(i=0;i<=k;i++){
        t=num(m,i,k);
        if(t>ans) ans=t;
    }
    printf("%d",ans);
}
int num(int m[],int i,int k)
{
    int re=0,j,t;
    if(i==k) return(0);
    for(j=i+1;j<=k;j++)
        if(m[j]<=m[i])
        {
            t=num(m,j,k);
            if(t>re) re=t;
        }
    re++;
    return(re);
}


int main()
{
	//freopen("in.txt","r",stdin);
	int i,j,N,anNum[MAX],anFlag[MAX];
	scanf("%d",&N);
	memset(anFlag,1,sizeof(anFlag));
	for (i=0;i<N;i++)
	{
		scanf("%d",&anNum[i]);
		anFlag[i]=1;
	}
	for (i=N-2;i>=0;i--)
	{
		int Max=0;
		for (j=i+1;j<N;j++)
		{
			if (anNum[i]>=anNum[j])
			{
				if (anFlag[j]>Max)
					Max=anFlag[j];
			}
		}
		anFlag[i]=Max+1;
	}
	int Max=0;
	for (i=0;i<N;i++)
		if (anFlag[i]>Max)
			Max=anFlag[i];
	printf("%d\n",Max);
	return 0;
}


int N,input[26],i,j,k,ans[26],Max;
int cons(int i){
   int a=0;
   if(ans[i]!=0)
     return ans[i];
   for(int j=i+1;j<N;j++){
     if(input[j]<=input[i])
        if(a<cons(j))
           a=ans[j];
   }
   ans[i]=a+1;
   return ans[i];
}
int main(){
    Max=0;
    scanf("%d",&N);
    for(i=0;i<N;i++){
       scanf("%d",&input[i]);
       ans[i]=0;
    }
    for(i=N-1;i>=0;i--){
        if(Max<cons(i))
           Max=ans[i];
    }
    printf("%d\n",Max);
    return 0;
}


int main()
{
	int k;
	int d[25];
	int f[25];
	int max=0;

	scanf("%d",&k);

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

	while(1)
	{
		int tmp=0;
		int x=0;
		int y=0;

		int ci;
		for(ci=0;ci<k;ci++)
		{
			if(f[ci]==1)
			{
				y++;
				if(x==0)
				{
					tmp=d[ci];
					x++;
				}
				else
				{
					if(d[ci]<=tmp)
					{
						tmp=d[ci];
						x++;
					}
					else
						break;
				}
			}
		}

		if(x==y)
			if(x>max)
				max=x;

		int cnt;
		for(cnt=0;cnt<k;cnt++)
		{
			if(f[cnt]!=0) break;
		}
		if(cnt==k) break;

		f[k-1]--;
		for(int i=k-1;i>0;i--)
		{
			if(f[i]==-1)
			{
				f[i]=1;
				f[i-1]--;
			}
		}

	}

	printf("%d",max);

		return 0;
}


int main()
{
	int k, most;
	int a[25], f[25];
	cin >> k;
	for(int i = 0 ; i < k ; i++)
	{
		cin >> a[i];
	}
	f[0] = 1;
	for(int i = 1; i < k; i++)
	{
		most = 0;
		for(int j = 0; j < i; j++)
		{
			if(a[j] >= a[i])
			{
				if(f[j] > most)
				{
					most = f[j];
				}
			}
		}
		f[i] = most+1;
	}
	most = 0;
	for(int i = 0; i < k; i++)
	{
		if(f[i] > most)
			most = f[i];
	}
	cout << most << endl;
	return 0;
}


int k,n[25],h[25];

int main()
{
    cin>>k;
	int i,j;
	for(i=0;i<k;i++)
		cin>>h[i];
	memset(n,sizeof(n),0);
	int tem=0;
	for(i=0;i<k;i++)
	{
		tem=0;
       for(j=0;j<i;j++)
	   {
		   if(h[j]>=h[i])
		   {
			   if(n[j]>tem)
				   tem=n[j];
		   }
	   }
	   n[i]=1+tem;
	}
	tem=0;
	for(i=0;i<k;i++)
	{
		if(n[i]>tem)
			tem=n[i];
	}
	cout<<tem<<endl;
	return 0;
}


int main(int argc, char* argv[])
{
	int min[26];
	int data[26];
	int N;
	int i , j;
	int minLength;
	scanf("%d" , &N);
	for(i = 0 ; i < N ; i++)
	{
		scanf("%d" , &data[i]);
	}
	min[0] = 1;
	for (i = 1 ; i < N ; i++)
	{
		minLength = 0;
		for (j = 0 ; j < i ; j++)
		{
			if (data[i] <= data[j])
			{
				if (min[j] > minLength)
				{
					minLength = min[j];
				}
			}
		}
		min[i] = minLength + 1;
	}
	//zhaozuixiao
	minLength = 0;
	for (i = 0 ; i < N ; i++)
	{
		if (min[i] > minLength)
		{
			minLength = min[i];
		}
	}

	printf("%d\n" , minLength);
	return 0;
}


int main()
{
	int i, j, n, num[100], mark[100] = {0}, max;
	cin >> n;
	for (i = 0; i < n; i ++)
	{
		cin >> num[i];
	}
	mark[n - 1] = 1;
	for (i = n - 2; i >= 0; i --)
	{
		max = 0;
		for (j = i + 1; j < n; j ++)
		{
			if (num[j] <= num[i] && mark[j] > max)
			{
				max = mark[j];
			}
		}
		mark[i] = max + 1;
	}
	max = 0;
	for (i = 0; i < n; i ++)
	{
		if (mark[i] > max)
		{
			max = mark[i];
		}
	}
	cout << max << endl;
	return 0;
}


int main()
{
	int i,j,k;
	int max=0;
	int maxall=1;
	int num[10000];
	int hight[10000];
	cin>>k;
	for(i=0;i<k;i++)
	{
		cin>>hight[i];
		num[i]=0;
	}
	num[0]=1;
	for(i=1;i<k;i++)
	{
	  max=1;
      for(j=0;j<i;j++)
	  {
		  if( hight[j]>=hight[i] && max<num[j]+1 )
			  max= num[j]+1;
	  }
	  num[i]= max;
	  if( num[i]>maxall ) maxall = num[i];
	}
	cout<<maxall<<endl;
	return 0;
}


int k;
int set(int i);
int num=0;
int currH=100000;
int MaxNum=0;
int a[100];
int b[100];
int main()
{
	int i;
	for(i=0;i<100;i++)
	{
		b[i]=0;
	}
	cin>>k;
	for(i=0;i<k;i++)
	{
		int j;
		cin>>j;
		a[i]=j;
	}
	set(0);
	cout<<MaxNum;
	return 0;
}

int set(int i)
{
	int lastNum=num;
	int lastcurrH=currH;
	if(i==k-1)
	{
		if(a[i]<=currH) num++;
		if(num>MaxNum) MaxNum=num;
		num=lastNum;
		currH=lastcurrH;
		return 0;
	}
		if(b[i]==0)  set(i+1);
	b[i]++;

	if(b[i]==1)
	{
		if(a[i]<=currH) { currH=a[i];  num++;}
		set(i+1);
	}

	num=lastNum;
	currH=lastcurrH;
	b[i]=0;
	return 0;
}


int a[100];

int f(int a[],int n,int min)
{
	if(n==1)
	{
		if(a[0]>=min)  return (1);
		else return(0);
	}
	else
	{
		if(a[n-1]<min) return(f(a,n-1,min));
		else if(f(a,n-1,a[n-1])+1<f(a,n-1,min))
			return(f(a,n-1,min));
		else return(f(a,n-1,a[n-1])+1);
	}
}

int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	int result;
	result=f(a,n,0);
	printf("%d",result);
	return 0;}


int xxx(int high,int j);
int max(int b,int c)
{
	if(b>=c) return b;
	else return c;
}
int n;
int x[26];
int main()
{
	int i;
	int m,k;
	scanf("%d",&n);
	int h[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&h[i]);
		x[i]=h[i];
		//printf(" %d",x[i]);
	}
	for(i=n;i<26;i++) x[i]=999999;
	int fly;
	fly=xxx(999999,0);
	printf("%d",fly);

}
int xxx(int high,int j)
{
	if(j==n-1)
	{
		if(high>=x[j]) return 1;
		else return 0;
	}
	else
	{
		if(high<x[j]) return xxx(high,j+1);
		else return max(1+xxx(x[j],j+1),xxx(high,j+1));
	}
}


main ()
{
     int k;
     scanf ("%d",&k);
     int(*p)=(int *)malloc(k*sizeof(int));
     int(*q)=(int *)malloc(k*sizeof(int));
     int i,j,t;
     for (i=0;i<k;i++)
     {
         scanf ("%d",&p[i]);
         q[i]=1;
     }
     for (i=0;i<k;i++)
     for (j=0;j<i;j++)
     {
         t=0;
         if (p[j]>=p[i])
         {
                        t=q[j]+1;
                        if (t>=q[i])
                        {
                                   q[i]=t;
                        }
         }
     }
     int max=0;
     for (i=0;i<k;i++)
     {
         if (q[i]>max)
         {max=q[i];}
     }
     printf("%d",max);
}


int main()
{
	int k;
	cin>>k;
	int h[50];
	int i,j;
	for(i=0;i<k;i++) cin>>h[i];
	int num[50],max;
	num[0]=1;
	for(i=1;i<k;i++)
	{
		max=0;
		for(j=0;j<i;j++)
		{
			if(h[j]>=h[i]&&num[j]>max) max=num[j];
		}
		num[i]=max+1;
	}
	max=0;
	for(i=1;i<k;i++)
	{
		if(num[i]>max) max=num[i];
	}
	cout<<max<<endl;
	return 0;
}


int n, a[MAXN + 10], f[MAXN + 10];

int main()
{

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < i; ++j)
		{
			if (a[j] >= a[i]) f[i] = max(f[i], f[j]);
		}
		f[i]++;
		ans = max(ans, f[i]);
	}
	cout << ans << endl;
	return 0;
}


int main()
{
	int f(int a[],int n);
	int a[30],n,i,s;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	s=f(a,n);
	printf("%d",s);
}

int f(int a[],int n)
{   int max(int x,int y);
int g(int a[],int n,int b);
	if(n==0)return(0);else
return(max(g(a+1,n-1,a[0])+1,f(a+1,n-1)));}

int g(int a[],int n,int b)
{   int max(int x,int y);
	if(n==0)return(0);else
	if(n==1)
    if(a[0]>b)
	return(0);
	else
	return(1);
	else
	if(a[0]>b)
	return(g(a+1,n-1,b));
	else
		return(max(g(a+1,n-1,b),g(a+1,n-1,a[0])+1));}
int max(int x,int y)
{
	return(x>y?x:y);

}


int n;
int *h;
int *m;
int max=0;

void calc(int num)
{
int i;
*(m+num)=1;
for(i=num+1;i<=n-1;i++)
if(*(h+i)<=*(h+num))
if(*(m+i)+1>*(m+num))
*(m+num)=*(m+i)+1;
if(*(m+num)>max)
max=*(m+num);
}

main()
{
int i;
scanf("%d",&n);
h=(int *)malloc(sizeof(int)*n);
m=(int *)malloc(sizeof(int)*n);
for(i=0;i<=n-1;i++)
scanf("%d",h+i);
*(m+n-1)=1;
for(i=n-2;i>=0;i--)
calc(i);
printf("%d",max);
}


int aa(int high[],int n,int k,int lh,int point)
{
	int remax=0,a=0,i;
	if(point==k-1)
	{
		if(lh>=high[k-1]) return 1;
		else return 0;
	}
	else
	{
		for (i=point;i<k;i++)
			if (high[i]<=lh)
			{
				a=aa(high,n+1,k,high[i],i+1)+1;
				if(a>remax) remax=a;
			}
		return remax;
	}
}

void main()
{
	int i,high[25],k;
	scanf("%d",&k);
	for(i=0;i<k;i++) scanf("%d",&high[i]);
	printf("%d",aa(high,0,k,32767,0));
}


int max(int *p,int num,int height)
{   int missile,case1,case2;
	if(num==1)
	{if(*p<=height)missile=1;
	else missile=0;}
	else
	{case1=max(p+1,num-1,*p)+1;
	case2=max(p+1,num-1,height);
	if(*p<=height&&case1>=case2)missile=case1;
	else missile=case2;
	}
	return(missile);
}
void main()
{
	int a[100],n,i,height=100000,H;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	H=max(a,n,height);
	printf("%d",H);
}


main()
{
      int k,i,j,max;
      scanf("%d",&k);
      int height[k];
      int num[k];
      for(i=0;i<k;i++)
      scanf("%d",&height[i]);
      num[k-1]=1;
      max=1;
         for(i=k-2;i>=0;i--)
         {
                           num[i]=0;
                            for(j=k-1;j>i;j--)
                            {
                                 if(height[i]>=height[j]&&num[i]<num[j])
                                 num[i]=num[j];
                            }
                            num[i]=num[i]+1;
                            if(num[i]>max)
                            max=num[i];
         }
         printf("%d\n",max);
         getchar();
         getchar();

}


int zui(int k,int m,int a[])
{
	int s=1,i=m+1,max=0;
	if(m==k) s=1;
	else
	{
	for(i=m+1;i<=k;i++)
	{
		if(a[k-m]<=a[k-i])
		{if(max<zui(k,i,a))
		{
			max=zui(k,i,a);
		}
		}
	}
	s=s+max;
	}
	return s;
}
int main()
{
	int i,k,a[25],max=0,s;
	scanf("%d",&k);
	for(i=0;i<k;i++)
	{
		scanf("%d",&a[i]);
	}
    for(i=1;i<k;i++)
	{
		s=zui(k,i,a);
		if(s>max) max=s;
	}
	printf("%d",max);
	return 0;
}


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

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

		}
	}
	cout<<max<<endl;
	return 0;
}


int main()
{
int k;
scanf("%d",&k);
int *a=(int *)malloc(sizeof(int)*k);
int i,j;
for(i=0;i<k;i++)
scanf("%d",&a[i]);
int count[30]={0};
int max;
max=0;
for(i=k-2;i>=0;i--)
{
for(j=i+1;j<k;j++)
{
if(a[j]<=a[i]&&count[i]<count[j]+1)
count[i]=count[j]+1;
}
}
for(i=0;i<k;i++)
{
if(max<count[i])
max=count[i];
}
printf("%d",max+1);
free(a);
return 0;
}


void sort(int *a,int i,int n) /*sort??a[i]?a[n]??????*/
{
  int j,k,t;
  for(j=i;j<n;j++)
  {
    for(k=j+1;k<=n;k++)
    {
      if(a[j]<=a[k])
      {t=a[j];a[j]=a[k];a[k]=t;}
    }
  }
}

main()
{
  int i,j,k,n;
  scanf("%d",&n);
  int *a=(int *)malloc(n*sizeof(int));
  int *jishu=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++)
  {scanf("%d",&a[i]);jishu[i]=1;}

  for(i=n-2;i>=0;i--)
  {
    for(j=i+1;j<=(n-1);j++)
    {
      if(a[j]<=a[i]&&jishu[j]>=jishu[i])
      {
        jishu[i]=jishu[j]+1;
      }
    }
  }
  sort(jishu,0,n-1);
  printf("%d\n",jishu[0]);
  free (a);free (jishu);

}


int k;
int h[25];
int l[25];
int main()
{
	cin >> k;
	int i, j;
	for (i = 0; i < k; i ++)
	{
		cin >> h[i];
		l[i] = 0;
	}
	l[0] = 1;

	for (i = 1; i < k; i ++)
	{
		int temp = -1;
		for (j = 0; j < i; j ++)
		{
			if (h[j] >= h[i] && l[j] + 1 > temp)
				temp = l[j] + 1;
		}
		if (temp == -1)
			l[i] = 1;
		else
			l[i] = temp;
	}
	int res = -1;

	for (i = 0; i < k; i ++)
	{
		if (l[i] > res)
			res = l[i];
	}
	cout << res << endl;

	return 0;
}


int main(int argc, char *argv[])
{
    int k;
    scanf("%d",&k);
    int i,j,h[26],amount[26],s=0;
    for(i=0;i<k;i++)
    {
      scanf("%d",&h[i]);
      amount[i]=1;
    }
    for(i=k-2;i>=0;i--)
    {
      for(j=i+1;j<k;j++)
      {
        if((h[i]>=h[j])&&(amount[i]<amount[j]+1))
          amount[i]=amount[j]+1;
      }
    }
    for(i=0;i<k;i++)
    {
      if(amount[i]>s)
        s=amount[i];
    }
    printf("%d\n",s);
  return 0;
}


int max(int sum[25],int x[25],int i,int j,int k)
{
   int t,l=1;
   static int y[25];
   t=i+1;
   for(;t<=k-1;t++)
      if(t!=j&&x[i]>=x[t])
        {y[l]=sum[t];
         l++;
         }
   for(i=1;i<l;i++)
      if(sum[j]<y[i])
        break;
   if(i==l)
     return(1);
   else
     return(0);
}
main()
{
      int k,i,j;
      static int x[25],sum[25];
      scanf("%d",&k);
      for(i=0;i<k;i++)
         scanf("%d",&x[i]);
       sum[k-1]=1;
      for(i=k-2;i>=0;i--)
      { for(j=i+1;j<=k-1;j++)
            if(x[i]>=x[j]&&max(sum,x,i,j,k))
              sum[i]=sum[j];
         sum[i]++;
      }
      int m=sum[0];
      for(i=1;i<k;i++)
         if(sum[i]>m)
           m=sum[i];
      printf("%d",m);
}


int a[30];
int len[30];
int main()
{
	int n;
	cin>>n;
	int i,j;
	for(i=1;i<=n;i++)
	{
      cin>>a[n-i+1];
	  len[i] = 1;
	}
    for(i=2;i<=n;i++)
		for(j=1;j<i;j++)
		{
			if(a[j]<=a[i]&&(len[j]+1>len[i]))
				len[i] = len[j] + 1;
		}
	int maxx=0;
	for(i=1;i<=n;i++)
	{
		if(len[i]>maxx)
			maxx= len[i];
	}
	cout<<maxx<<endl;
	return 0;
}


int f(int a[],int k,int m){
int ans=1,tag=1,i;
if(m<k-1) for(i=m+1;i<k;i++)
if(a[i]<=a[m]&&tag<=f(a,k,i)){
ans=1+f(a,k,i);
tag=f(a,k,i);}
return ans;}
int main(){
int a[25],k,i,max;
scanf("%d",&k);
for(i=0;i<k;i++)
scanf("%d",a+i);
max=f(a,k,0);
for(i=1;i<k;i++)
if(f(a,k,i)>max)
max=f(a,k,i);
printf("%d",max);
return 0;}


void main()
{
	int n,high[30],point,m,sum1,sum2,check;
	scanf("%d",&n);
	for (m=0;m<n;m++)
		scanf("%d",&high[m]);
	for(check=1;check==1;)
	{
		check=0;
		for(point=0;point<n-1;point++)
		{
		if(high[point]<high[point+1])
		{
			check=1;
			for(m=0,sum1=0;m<point;m++)
				if(high[m]>=high[point]&&high[m]<high[point+1]) sum1++;
			for(m=point+2,sum2=0;m<n;m++)
				if(high[m]>high[point]&&high[m]<=high[point+1]) sum2++;
			if(sum1>=sum2)
			{
				for (m=point+1;m<n-1;m++)
				{
					high[m]=high[m+1];
				}
			}
			else
			{
				for (m=point;m<n-1;m++)
				{
					high[m]=high[m+1];
				}
				point--;
			}
			n--;
		}
		}
	}
	printf("%d\n",n);
}


int b[MAX_N + 10];
int aMaxLen[MAX_N + 10];
int main()
{
	int N,i,j;
	scanf("%d",&N);
	for( i = N;i >= 1;i -- )
		scanf("%d", & b[i]);
	aMaxLen[1] = 1;
	for( i = 2; i <= N; i ++ )
	{
		int nTmp = 0;
		for( j = 1; j < i; j ++ )
		{
			if( b[i] >= b[j] )
			{
				if( nTmp < aMaxLen[j] )
					nTmp = aMaxLen[j];
			}
		}
		aMaxLen[i]  = nTmp + 1;
	}
	int nMax = -1;
	for( i = 1;i <= N;i ++ )
		if( nMax < aMaxLen[i])
			nMax = aMaxLen[i];
	printf("%d\n", nMax);
	return 0;
}


int k;
int num[26];
int val[26];
int main()
{

	cin>>k;
	for(int i=0;i<k;i++)
	{
		cin>>num[i];
		val[i]=0;
	}
	//for(int i=0;i<k;i++)
	//	cout<<num[i]<<endl;
	for(int i=k-1;i>=0;i--)
	{
		if(i==k-1)
			val[i]=1;
		else
		{
			int temp=0;
			for(int j=i;j<k;j++)
			{
				if(num[i]>=num[j]&&val[j]>=temp)
				{
					temp=val[j];
	//				cout<<num[i]<<" "<<num[j]<<" "<<temp<<endl;
				}
			}
			val[i]=temp+1;
		}

	}
int sum=0;
for(int i=0;i<k;i++)
{
	//cout<<val[i]<<endl;
		if(val[i]>=sum)
			sum=val[i];
}
cout<<sum<<endl;

return 0;

}


int max (int a,int b)
{
	if(a < b)
		return b;
	else
		return a;
}
int main()
{
	int num;
	int h[100];
	cin >> num;
	int i,j,k;
	for(i = 0; i < num; i ++)
		cin >> h[i];
	int f[100] = {0};
	f[0] = 1;
	for(i = 1; i  < num; i++)
	{
		f[i] = 1;
		for(j = 0; j < i; j ++)
		{
			if(h[i] <= h[j])
				f[i] = max(f[i],f[j]+1);
		}
	}
	int result = f[0];
	for(i = 1; i  < num; i ++)
	{
		result = max(f[i],result);
	}
	cout << result<<endl;
}


int max(int a[],int n,int high)
{
  int c,b;
  if(n==0)
     {
        if(a[0]>high) return 0;
        else return 1;
      }
  else
       if(a[n]>high)
          return max(a,n-1,high);
       else
         {
            c=max(a,n-1,a[n])+1;
            b=max(a,n-1,high);
            if(c>b) return c;
            else return b;
         }
}
main()
{
  int n,i;
  int a[25];
  scanf("%d",&n);
  for(i=0;i<n;i++)
     scanf("%d",&a[n-i-1]);
  printf("%d",max(a,n,32767));
}


int Height[26];
int MaxLen[26];

void LIS(int k){
    memset(MaxLen,0,sizeof(MaxLen));
    for(int i = 1;i <= k; i++){
        MaxLen[i] = 1;

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

            if(Height[i] <= Height[j]){

                int preMax = MaxLen[j] + 1;
                if(preMax > MaxLen[i]){
                    MaxLen[i] = preMax;
                }
            }
        }
    }
}

int main()
{
    int N,i;
    scanf("%d",&N);

        for(i = 1;i <= N;i++){
            scanf("%d",&Height[i]);
        }
        LIS(N);
        int Max = -1;

        for(i = 1;i <= N;i++){
            if(Max < MaxLen[i]){
                Max = MaxLen[i];
            }
        }
        if(N != 0){
            printf("%d\n",Max);
        }

    return 0;
}


int a[25];
int n;

void main()
{

	int i;
	int max(int);
	int num=0;

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		num=max(i)>num?max(i):num;
	printf("%d",num);

}

int max(int chu)
{
	int z=1,tempj;
	int i,j,k;

	if(chu==n-1) z=1;
	else{
			for(j=chu+1;j<n;j++)
			{
				if(a[j]>a[chu]) continue;
				tempj=1+max(j);
				z=tempj>z?tempj:z;
				tempj=0;

			}

		}

	return z;
}


void main()
{
	int n,a[100]={0},maxlen[100]={0},i,j,temp,temp2=1,temp3;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	for(i=0;i<n;i++)
	{
		temp2=1;
		if(i==0)maxlen[i]=1;
		else
		{
			temp3=0;
			for(j=i-1;j>=0;j--)
			{
				if( a[j]>=a[i])
				{
					if(maxlen[j]>maxlen[temp3])
					temp3=j;
					temp2=0;

				}
			}
			maxlen[i]=maxlen[temp3]+1;
			if(temp2==1)maxlen[i]=1;
		}
	}
	temp=0;
	for(i=0;i<n;i++)
		if(maxlen[i]>maxlen[temp])
		temp=i;
	printf("%d",maxlen[temp]);
}


int max(int x,int y);
int max(int x,int y)
{
	int z;
	if(x>y)
		z=x;
	else
		z=y;
	return(z);
}

int main()
{
	int a[25]={0};
	int c[25];
	int Height,k;
	int n;
	scanf("%d",&k);
	{
		for(n=0;n<k;n++)
		{
			scanf("%d",&Height);
			a[n]=Height;
			c[n]=1;
		}
	}
	int i,j;
	for(i=k-2;i>=0;i--)
	{
		for(j=i+1;j<=k-1;j++)
		{
			if((a[j]<=a[i]) && (c[i]<c[j]+1))
				c[i]=c[j]+1;
		}
	}

	int cMax=c[0];
	{
		for(i=0;i<=k-1;i++)
		{
			cMax=cMax>c[i]?cMax:c[i];
		}
		printf("%d",cMax);
	}
	return 0;
}


int k = 0;
int a[100];
int dp[100];

int solve()
{
	int ans = 0;

	dp[0] = 1;
	for(int i=1; i<k; i++)
	{
		dp[i] = 1;
		for(int j=0; j<i; j++)
		{
			if(a[j] >= a[i] && dp[j] + 1 > dp[i])
			{
				dp[i] = dp[j] + 1;
			}
		}
		if(dp[i] > ans)
		{
			ans = dp[i];
		}
	}

	return ans;
}

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	scanf("%d", &k);

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

	return 0;
}


int h[25],n;
int hack(int i,int w){
 if(i==n-1){
  if(h[i]<=w) return 1;
  else return 0;
 }
 int b=hack(i+1,w),c=0;
 if(h[i]<=w)
   c=1+hack(i+1,h[i]);
 if(b>c) return b;
 else return c;
}
int main(){
 scanf("%d",&n);
 int i,max=0;
 for(i=0;i<n;i++){
  scanf("%d",&h[i]);
  if(h[i]>max)
   max=h[i];
 }
 printf("%d",hack(0,max));
 return 0;
}


/*
 * lanjiedaodan.cpp
 *
 *  Created on: 2010-9-29
 *      Author: lz
 */

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

}


const long maxn=25;

long n;
long a[maxn+10];

long ans;

void dfs(long h,long maxH,long now){
    long i;
    if(h==n+1){
	if(now>ans)ans=now;
	return;
    }
    dfs(h+1,maxH,now);
    if(a[h]<=maxH)dfs(h+1,a[h],now+1);
}

main(){
    long i;
    scanf("%ld",&n);
    for(i=1;i<=n;i++){
	scanf("%ld",a+i);
    }
    dfs(1,1<<30,0);
    printf("%ld\n",ans);
    //getchar();getchar();
    return 0;
}


unsigned int h[26],n;
int go(int maxh,int cp)
{
	int x,y,max;
	while(h[cp]>maxh)cp=cp+1;
	if(h[cp]==0)return 0;
	x=go(maxh,cp+1);
	maxh=h[cp];
	y=1+go(maxh,cp+1);
	max=(x>y)?x:y;
	return max;
}
int main()
{
	unsigned int i,c,t;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&h[i]);
	h[n]=0;
	t=go(65535,0);
	printf("%d",t);
	return 0;
}


int numbers[1001],maxLength[1001];
int n,max = 0, temp = 0, check = 0;
int j;

int main()
{
	cin>>n;
	for (int i = n-1; i >= 0; i--)
		cin>>numbers[i];
	maxLength[0] = 1;
	for (int i = 1; i < n; i++)
	{
		temp = 0; check = 0;
		for (j = 0, maxLength[i] = 0; j < i; j++)
		{// <= !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
			if ( numbers[j] <= numbers[i] && maxLength[j] >= maxLength[i] && maxLength[j] >= maxLength[temp])
			{
				temp = j;
				check++;
			}
		}
		if (check) maxLength[i] = maxLength[temp]+1;
		else maxLength[i] = 1;
	}
	for (int i = 0; i < n; i++)
		if (max < maxLength[i]) max = maxLength[i];
	cout<<max;
	return 0;
}


int main()
{
	int n;
	cin>>n;
	int a[25];
	int rem[25] = {1};
	for(int i = 0; i < n; i++)
		cin>>a[i];
	int MMax = 0;
	for(int i = 1; i < n; i++)
	{
		int max = 0;
		for(int j = i-1; j >= 0; j--)
		{
			if(j < max) break;
			if(a[j] >= a[i] && rem[j] > max) max = rem[j];
		}
		rem[i] = max + 1;
		if(rem[i] > MMax) MMax = rem[i];
	}
	cout<<MMax<<endl;
	return 0;
}


int compare(const void *a,const void *b)
{
    return (*(int*)b-*(int*)a);
}
int main()
{
    int k,i,j,m=0;
    scanf("%d",&k);
    int a[30]={0};
    for(i=0;i<k;i++)
    {
    scanf("%d",&a[i]);
    }
    int b[30]={1};
    int t;
    int c[30];
    for(i=1;i<k;i++)
    {
                 t=0;
              for(j=0;j<30;j++)
              {
                               c[j]=0;
              }
              for(j=i-1;j>=0;j--)
              {
                               if(a[j]>=a[i])
                               {
                                       c[t]=b[j];
                                       t++;
                               }
              }
              qsort(c,t,sizeof(int),compare);
              b[i]=c[0]+1;
    }
    for(i=0;i<k;i++)
    {
                    if(m<b[i])
                    m=b[i];
    }
    printf("%d\n",m);
    getchar();
    getchar();
    getchar();
}


int H[100];
int N;

int memo[40][40];

int dp(int i, int k) { // from i, max H[k]
	int rslt;
	if(i == N) return 0;
	if(memo[i][k] != -1) return memo[i][k];
	if(k != 30 && H[i] > H[k]) rslt = dp(i + 1, k);
	else {
		int a = dp(i + 1, i) + 1;
		int b = dp(i + 1, k);
		if(a > b) rslt = a; else rslt = b;
	}
	return memo[i][k] = rslt;
}

int main() {
	scanf("%d", &N);
	for(int i = 0; i < 40; i++) for(int j = 0; j < 40; j++)
		memo[i][j] = -1;
	for(int i = 0; i < N; i++) {
		scanf("%d", &H[i]);
	}
	printf("%d\n", dp(0, 30));
}


int n;
int d[100];
int dp[30];

int main()
{
    while(scanf("%d", &n) == 1)
    {
        for(int i = 1; i <= n; i++)
            scanf("%d", d + i);

        d[0] = (-1u)>>1;
        for(int i = 1; i <= n; i++)
        {
            dp[i] = 0;
            for(int j = 0; j < i; j++)
                if(d[j] >= d[i])
                    dp[i] = max(dp[i], dp[j] + 1);
        }

        int ans = 0;
        for(int i = 1; i <= n; i++)
            ans = max(ans, dp[i]);

        printf("%d\n", ans);
    }
    return 0;
}


int k, i, j, an[30];
int DFS (int h, int n)
{
	int t1, t2;
	if (n == k - 1)
	{
		if (an[n] > h)
			return 0;
		else
			return 1;
	}
	if (an[n] > h)
		return DFS (h, n + 1);
	else
	{
		t1 = DFS (h, n + 1);
		t2 = DFS (an[n], n + 1) + 1;
		if (t1 > t2)
			return t1;
		else
			return t2;
	}
}
int main ()
{
	cin >> k;
	for (i = 0; i < k ;i ++)
	{
		cin >> an[i];
	}
	cout << DFS(INT_MAX, 0) << endl;
	return 0;
}


char f(int max,int a[],char m, char n)
{
	char num1,num2;
	if(m==n&&a[n-1]<=max)
		return(1);
	else if(m==n&&a[n-1]>max)
		return(0);
	else
	{
		if(a[m-1]<=max)
		{
			num1=f(max,a,m+1,n);
			num2=f(a[m-1],a,m+1,n)+1;
			if(num1>num2)
				return(num1);
			else
				return(num2);
		}
		else
			return(f(max,a,m+1,n));
	}

}

void main()
{
	int hmax=(unsigned)(~0)>>1;
	int h[N];
	char n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&h[i]);
	printf("%d\n",f(hmax,h,1,n));
	printf("input:\n");
	for(i=0;i<n;i++)
		printf("%d,",h[i]);

}


int main()
{
	int i,j,k,n,m,height[25],len[25],num[25];
	cin>>n;
	for(i=0;i<n;i++)
		cin>>height[i];
	for(i=0;i<n;i++)
		len[i]=0;
	for(i=n-1;i>=0;i--)
	{
		m=0;
		for(j=i+1;j<=n-1;j++)
			if(height[j]<=height[i])
			{
				num[m]=j;
				m++;
			}
		for(k=0;k<=m-1;k++)
			if(len[i]<len[num[k]])
				len[i]=len[num[k]];
			len[i]++;
	}
	m=0;
	for(i=0;i<n;i++)
		if(len[i]>m)
			m=len[i];
		cout<<m<<endl;
return 0;
}


const int maxn = 55;
int a[maxn], dp[maxn][maxn];

int main()
{
    int T, n, i, j, ans;
    while (scanf ("%d", &n)!=EOF)
    {
          for (i=1; i<=n; i++)scanf ("%d", a+i);
          memset (dp, -1, sizeof(dp));
          for (i=1; i<=n; i++) dp[i][i] = 1;
          for (i=1; i<n; i++)
          {
              for (j=1; j<=i;j++)
              {
                  dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
                  if (a[i+1]<=a[j])
                     dp[i+1][i+1] = max(dp[i+1][i+1], dp[i][j]+1);
              }
          }
          ans = 0;
          for (i=n, j=1;j<=i;j++) ans = max(ans, dp[i][j]);
          printf ("%d\n", ans);
    }
    return 0;
}


int height[26];

int cal(int N,int M){//NÎa¿aê¼±è½Ï?Äêy?ÄÎ»ÖÃ?¬MÎaê?ÏÂ?Äêy?Ä¸öêy?¬N+M=×ü?Äêy¸öêy
	int i,max,sub;
	max=0;
	if(M==0){
		return 1;
	}
	for(i=N+1;i<=N+M;i++){
		if(height[N]>=height[i]){
			sub=cal(i,N+M-i);
			if(sub>=max){
				max=sub;
			}
		}
	}
	return max+1;
}

int main()
{
	int k,i;
	scanf("%d\n",&k);
	height[0]=10000000;
	scanf("%d",&height[1]);
	for(i=1;i<=k-1;i++){
		scanf(" %d",&height[i+1]);
	}

	printf("%d",cal(0,k+1)-2);

	return 0;
 }


int rec[30],height[30];
int maxV;
int main()
{
 int n;
 maxV=0;
 cin>>n;
 if(n==0)
 {
     cout<<0<<endl;
     return 0;
 }
 int i,j;
 for(i=0;i<n;i++)
 {
     cin>>height[i];
     rec[i]=1;
     for(j=0;j<i;j++)
            if(height[j]>=height[i]&&rec[j]+1>rec[i])
                rec[i]=rec[j]+1;
        if(rec[i]>maxV)maxV=rec[i];
 }
 cout<<maxV<<endl;
 return 0;
}


int com(const void *a,const void *b)
{
    return(*(int *)a-*(int *)b);
}
int main()
{
   int n,i;
   int a[30];
   int s[30];
   for(int i=0;i<30;i++)
   s[i]=1;
   scanf("%d",&n);
   for(int i=0;i<n;i++)
   scanf("%d",&a[i]);
   for(int i=n-2;i>=0;i--)
   {
    for(int j=n-1;j>i;j--)
    {
     if(a[i]>=a[j])
     {
      s[i]=max(s[j]+1,s[i]);
     }
    }
   }
   qsort(s,30,sizeof(int),com);
   printf("%d",s[29]);
   getchar();
   getchar();
}


int num(int n, int *p)
{
	int i=1, max=0;
	int *q=p+1;
	if(n==2)
	{
		if(*p>=*q)
			return 2;
		else
			return 1;
	}
	else
	{
		while(i<=n)
		{
			for(; *p<*q && i<=n; i++, q++);
			i++;
			if(num(n-i+1, q)+1>max)
				max=num(n-i+1, q)+1;
			q++;
		}
	}
	return max;
}
int main()
{
	int k, i, a[25], max=0;
	scanf("%d", &k);
	for(i=0; i<k; i++)
		scanf("%d", &a[i]);
	for(i=k; i>=2; i--)
	{
		if(num(i, a+k-i)>max)
			max=num(i, a+k-i);
	}
	printf("%d\n", max);
	return 0;
}


int com(void const *a,void const *b)
{
    return (*(int *)a-*(int *)b);
}
main()
{
      int k,H;
      int j,count[25],n;
      scanf("%d",&k);
      int h[25],i;
      for (i=0;i<k;i++)
      {
          scanf("%d",&h[i]);
      }
      count[k-1]=1;
      for (i=k-2;i>=0;i--)
      {
          n=0;
          for (j=k-1;j>=i+1;j--)
          {
             if  (h[j]<=h[i])
             {
                  if (count[j]>=n)
                  {
                       n=count[j];
                  }
             }
          }
          count[i]=n+1;
      }

           qsort(count,k,sizeof(int),com);
           printf("%d",count[k-1]);
      getchar();getchar();getchar();getchar();getchar();getchar();
}


int N,height[25];
int main(void)
{
	int i;
	int work(int,int);
	cin >> N;
	for (i = 0 ; i < N ; i++) cin >>height[i];
	cout << work(0,99999) <<endl;
	return 0;
}
int work(int sub,int high)
{
	int i,max,num1,num2;
	for ( i = sub ; high < height[i] ; i++);
	if (sub >= N || i >= N) return 0;
	num1 = work(i+1,height[i]) + 1;
	num2 = work(sub+1,high);
	return num1 > num2 ? num1 : num2;
}//HONZE TEST


const int maxk = 300;

int main()	{
	int k;
	int a[maxk];
	int f[maxk];

	cin >> k;
	for (int i = 0; i < k; i ++)	cin >> a[i];

	int ans = 0;

	f[0] = 1;

	for (int i = 1; i < k; i ++)	{
		f[i] = 1;
		for (int j = 0; j < i; j ++)	{
			if (a[j] >= a[i] && f[j] + 1 > f[i])	f[i] = f[j] + 1;
		};
		if (f[i] > ans)	ans = f[i];
	};

	cout << ans << endl;

	return 0;
};


int max(int x,int y)
{
    if(x>y) return x;
    else return y;
}
int dao[26],n;
int fly(int high,int m)
{
    if(m==n)         return 0;
    else
    {
    if(high<dao[m])  return fly(high,m+1);
    else
    {
        return max(fly(high,m+1),fly(dao[m],m+1)+1);
    }
    }
}
int main()
{
   int i,j,k;
   scanf("%d",&n);
   for(i=0;i<n;i++)  scanf("%d",&dao[i]);
   k=fly(99999,0);
   printf("%d",k);
  }


int max(int x,int y)
{
	int z;
	if(x>=y)
		z=x;
	else
		z=y;
	return (z);
}

int MAX_multi(int str[25],int n)
{
	int t=0,i;
	for(i=0;i<n;i++)
	{
		t=max(t,str[i]);
	}
	return (t);
}

void count(int str[25],int num[25],int n)
{
	int i,j;
	for(i=n-1;i>=0;i--)
	{
		for(j=n-1;j>i;j--)
		{
			if(str[i]>=str[j])
				num[i]=max(num[i],num[j]+1);
		}
	}
	printf("%d\n",MAX_multi(num,n));
}

void main()
{
	int n,i,str[25],num[25]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&str[i]);
	count(str,num,n);
}


int main()
{
	int a[25],k,b[25];
	cin>>k;
	int max1;
//	int dex;
	for(int i=0;i<k;i++)
	{
		cin>>a[i];
		b[i]=1;
	}
	for(int j=k-1;j>=0;j--)
	{
		max1=0;
		for(int m=k-1;m>j;m--)
		{
			if(a[m]<=a[j]&&b[m]>=max1)
				max1=b[m];
		}
		b[j]=max1+1;
	}
	int max;
	max=b[0];
	for(int n=1;n<k;n++)
	{
		if(max<b[n])
			max=b[n];
	}
	cout<<max<<endl;

	return 0;
}


int a[25];
int f(int x)
{
    int t=1,max=1;
    if(a[x+1]==0)
    max=1;
    else
    {
        for(int i=x+1;a[i]!=0;i++)
        if(a[x]>=a[i])
        {
                       t=f(i)+1;
                       if(t>max) max=t;
        }
     }
    return max;
}
main()
{
      int n,t,max,i,M;
      scanf("%d",&n);
      memset(a,0,25*sizeof(int));
      for(i=0;i<n;i++)
      {
                      scanf("%d",&a[i]);
      }
      M=f(n-1);
      for(i=n-2;i>=0;i--)
      {
                        f(i);
                        if(M<f(i))
                        M=f(i);
      }
      printf("%d",M);
      getchar();
      getchar();
}


int search(int a[],int b,int c);
int main()
{
int n,s=1,t,k;
int *p,*a,*b;
scanf("%d",&n);
p=(int*)malloc(n*sizeof(int));
a=(int*)malloc(n*sizeof(int));
b=(int*)malloc(n*sizeof(int));
for(int i=0;i<n;i++) scanf("%d",p+i);
for(int i=0;i<n;i++) a[i]=-1;
a[1]=p[0];
for(int i=0;i<n;i++)
{
t=0;
k=search(a,s,p[i]);
if(k>s) s++;
a[k]=p[i];
}
printf("%d\n",s);
return 0;
}
int search(int a[],int s,int m)
{
int low = 1;
int high = s;
int mid;

while (low < high) {
mid = (low + high) / 2;
if (a[mid] == m )
return mid+1;
if (a[mid] > m)
low = mid + 1;
else
high = mid;
}
if (a[low] <= m)
return low;
else
return low+1;
}


int main()
{
    int n;
    int a[100];
    int h[100];
    int ans;
    while (scanf("%d", &n) != EOF)
    {
          ans = 1;
          for (int i = 0; i < n; i ++)
          {
              scanf("%d", &a[i]);
              h[i] = 1;
          }
          for (int i = 1; i < n; i ++)
          {
              int sum = 1;
              for (int j = 0; j < i; j ++)
              {
                  if (a[j] >= a[i] && h[i] < h[j] + 1)
                     h[i] = h[j] + 1;
              }
              if (h[i] > ans) ans = h[i];
          }
          printf("%d\n", ans);
    }
    return 0;
}


void main()
{
    int a[50]={0},flag[50],max,i,j;
    int num;
    scanf("%d",&num);
    for (i=0;i<num;i++)
    {
        scanf("%d",&a[i]);
        flag[i]=1;
    }
    for (i=0;i<num;i++)
    {
        for(j=0;j<i;j ++)
        {
            if(a[j]>=a[i])
            {
                flag[i]=flag[j]+1>flag[i]?flag[j]+1:flag[i];
            }
        }
    }
    max = flag[0];
    for (i=1;i<num;i++)
    {
        if (flag[i]>max)
        max=flag[i];
    }
    printf("%d\n",max);
}


int main()
{
	int height[27];
	int result[27];
	int k;
	int i , j;
	int nmax;
	cin>>k;
	for(i = 1; i <= k; i++){
		cin>>height[i];
	}
	height[k+1] = 0;
	result[k+1] = 0;
	for(i = k; i > 0; i--){
		nmax = 0;
		for(j = i+1; j <= k+1; j++){
			if(height[i] >= height[j]){
				if(result[j] > nmax){
					nmax = result[j];
				}
			}
		}
		result[i] = nmax + 1;
	}
	nmax = 0;
	for(i = 1; i < k; i++){
		if(result[i] > nmax){
			nmax = result[i];
		}
	}
	cout<<nmax<<endl;
	return 0;
}


void main()
{
    int a[50]={0},flag[50],max,i,j,count=1,st=0;
    int num;
    scanf("%d",&num);
    for (i=0;i<num;i++)
    {
        scanf("%d",&a[i]);
        flag[i]=1;
    }
    for (i=0;i<num;i++)
    {
        for(j=0;j<i;j ++)
        {
            if(a[j]>=a[i])
            {
                flag[i]=flag[j]+1>flag[i]?flag[j]+1:flag[i];
            }
        }
    }
    max = flag[0];
    for (i=1;i<num;i++)
    {
        if (flag[i]>max)
        max=flag[i];
    }
    printf("%d\n",max);
}


int k;
int arr[30];
int num[30];

int main()
{
    cin>>k;
    for(int i=0;i<k;i++)
        cin>>arr[i];
    for(int i=0;i<k;i++)
        num[i]=1;
    for(int i=0;i<k;i++)
    {
        for(int j=0;j<i;j++)
        {
            if(arr[j]>=arr[i]&&num[j]>=num[i])
                num[i]=num[j]+1;
        }
    }
    int res=-1;
    for(int i=0;i<k;i++)
        if(num[i]>res)
            res=num[i];
    cout<<res<<endl;
    return 0;
}


int a[max+10];
int b[max+10];
int maxlen[max+10];
void main()
{
	int i,j,n;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=n;i++){
		b[n+1-i]=a[i];
	}
	maxlen[1]=1;
	for(i=2;i<=n;i++){
		int tmp=0;
		for(j=1;j<i;j++){
			if(b[i]>=b[j]){
				if(tmp<maxlen[j]){
					tmp=maxlen[j];
				}
			}
		}
		maxlen[i]=tmp+1;
	}
	int nmax=-1;
	for(i=1;i<=n;i++){
		if(nmax<maxlen[i]){
			nmax=maxlen[i];
		}
	}
	printf("%d",nmax);
}


int max(int x,int y)
{
    if(x>=y)
    return x;
    else
    return y;
}
main()
{
      int i,j,k,m,n,res=0;
      scanf("%d",&n);
      int a[n];
      for(i=0;i<n;i++)
      scanf("%d",&a[i]);
      int b[n],tem=0;
      for(i=0;i<n;i++) b[i]=0;
      b[n-1]=1;
      for(i=n-2;i>=0;i--)
      {
                         tem=0;
                         for(j=n-1;j>i;j--)
                         {
                                           if(a[i]>=a[j])
                                           tem=max(tem,b[j]);
                                           else
                                           continue;
                         }
                         b[i]=tem+1;
      }
      for(i=0;i<n;i++) res=max(res,b[i]);
      printf("%d",res);

}


int max[26]={0};
int a[26]={0};
void attack(int n)
{
	int i=0,j=0,premax=0;
	for(i=0;i<n;i++)
	{   max[i]=1;
		for(j=0;j<i;j++)
		{
			if(a[i]<=a[j])
			{
			premax=max[j]+1;
			if(premax>max[i])
			max[i]=premax;}
		}
	}
}
int main()
{   static int n,i,num=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	attack(n);
	num=max[0];
	for(i=1;i<n;i++)
	if(max[i]>num)
	num=max[i];
	printf("%d",num);
}


int changdu(int i,int n,int *a,int *b)
{
    int j,max=1;
    for(j=i+1;j<n;j++)
    {
                      if(a[i]>=a[j])
                      {
                                    b[i]=changdu(j,n,a,b)+1;
                                    if(b[i]>max)
                                    max=b[i];
                                    }
                                    }
    b[i]=max;
    return max;
}
main()
{
      int a[25],b[25];
      int n;
      int max=0,i;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      scanf("%d",&a[i]);
      for(i=0;i<n;i++)
      b[i]=changdu(i,n,a,b);
      for(i=0;i<n;i++)
      {
                      if(b[i]>max)
                      max=b[i];
                      }
      printf("%d",max);

      }


int lanjie(int m,int b[26],int lim)
{
if(m==1)
 {
if(b[0]<=lim)
return(1);
else return(0);
 }
else if(m==2)
{ if(b[0]<=lim&&b[1]<=b[0])return(2); else if(b[0]>lim&&b[1]>lim)return(0); else return(1); } else { if(b[0]<=lim)return(lanjie(m-1,&b[1],b[0])+1>=lanjie(m-1,&b[1],lim)?lanjie(m-1,&b[1],b[0])+1:lanjie(m-1,&b[1],lim)); else return(lanjie(m-1,&b[1],lim)); } } void main() { int a[26],i,k; scanf("%d",&k); for(i=0;i<=k-1;i++) { scanf("%d",&a[i]); } getchar(); printf("%d\n",lanjie(k,a,32767)); }