from bisect import*

n,*a=list(map(int,open(0)))

b=[-1]*n

for a in a:b[bisect(b,a-1)-1]=a

print((n-b.count(-1)))
from bisect import*

n,*a=list(map(int,open(0)))

b=bisect

c=[-1]*n

for a in a:c[b(c,a-1)-1]=a

print((n-b(c,-1)))
from bisect import *

n, *a = list(map(int, open(0)))
b = [-1] * n
for a in a:
    b[bisect(b, a - 1) - 1] = a
print((n - b.count(-1)))

from bisect import *

n, *a = list(map(int, open(0)))
b = bisect
c = [-1] * n
for a in a:
    c[b(c, a - 1) - 1] = a
print((n - b(c, -1)))

-b = [-1] * n +b = bisect +c = [-1] * n -    b[bisect(b, a - 1) - 1] = a -print((n - b.count(-1))) +    c[b(c, a - 1) - 1] = a +print((n - b(c, -1)))