#include<stdio.h>
#include<algorithm>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <functional>
using namespace std;
int a[100000] = { 0 };
int dp[10001][10001] = { 0 };
int n, w;
int main() {
	int mx;
	scanf_s("%d",&n);
	for (int i = 0; i < n; ++i) {
		scanf_s("%d", &a[i]);
	}
	for (int i = n; i >= 1; --i) {
		for (int j = i; j <= n; ++j) {
			if (i == j) dp[i][j] = 1;
			else if(a[i - 1] < a[j - 1]){
				dp[i][j] = max(dp[j][n] + 1, dp[i][j - 1]);
			}
			else {
				dp[i][j] = dp[i][j - 1];
			}
		}
	}
	mx = 0;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			printf("%2d ", dp[i][j]);
		}
		printf("\n");
	}
	for (int i = 0; i <= n; ++i) {
		if (mx < dp[i][n]) {
			mx = dp[i][n];
		}
	}
	printf("%d\n", mx);
}