#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;intC[1100];constint MAXN =10;voidupdate(int x,int ans){C[x]= ans ;while(x < MAXN){C[x]=max(C[x], ans);
x += x&-x;}}intquery(int x){int ret =0;while(x >0){
ret =max(ret,C[x]);
x -= x&-x;}return ret;}intmain(){int n;int a[1100];int b[1100];scanf("%d",&n);for(int i =1; i <= n; i++){scanf("%d",&a[i]);
b[i]= a[i];}
sort (b+1, b+1+n);for(int i =1; i <= n ; i ++){
a[i]= lower_bound (b+1,b+1+n,a[i])- b ;}for(int i =1; i <= n; i++)printf("%d ", a[i]);int ans =0;for(int i =1; i <= n; i++){
ans =max(ans,query(a[i]-1)+1);if(ans >C[a[i]])update(a[i], ans);}printf("%d\n", ans);return0;}