from collections import deque

from bisect import bisect_left

N=int(eval(input()))

que=deque()

ans=0

for i in range(N):

    a=int(eval(input()))

    b=bisect_left(que,a)

    if b-1<0:

        que.appendleft(a)

        ans+=1

    else:

        que[b-1]=a

print(ans)
from collections import deque

from bisect import bisect_left

N=int(eval(input()))

li=[]

ans=0

for i in range(N):

    a=-int(eval(input()))

    b=bisect_left(li,a+1)

    if b==len(li):

        li.append(a)

        ans+=1

    else:

        li[b]=a

print(ans)
from collections import deque
from bisect import bisect_left

N = int(eval(input()))
que = deque()
ans = 0
for i in range(N):
    a = int(eval(input()))
    b = bisect_left(que, a)
    if b - 1 < 0:
        que.appendleft(a)
        ans += 1
    else:
        que[b - 1] = a
print(ans)

from collections import deque
from bisect import bisect_left

N = int(eval(input()))
li = []
ans = 0
for i in range(N):
    a = -int(eval(input()))
    b = bisect_left(li, a + 1)
    if b == len(li):
        li.append(a)
        ans += 1
    else:
        li[b] = a
print(ans)

-que = deque() +li = [] -    a = int(eval(input())) -    b = bisect_left(que, a) -    if b - 1 < 0: -        que.appendleft(a) +    a = -int(eval(input())) +    b = bisect_left(li, a + 1) +    if b == len(li): +        li.append(a) -        que[b - 1] = a +        li[b] = a