import bisect
n=input()
a=[input() for i in xrange(n)]
dp=[float('inf') for _ in xrange(n)]
for i in xrange(n):
    dp[bisect.bisect_left(dp,a[i])]=a[i]
print dp
for i in xrange(n):
    if dp[i]==float('inf'):
        i-=1
        break
print(i+1)