import sys

from collections import deque

from bisect import bisect_left, bisect_right



N=eval(input())

A=[ int(sys.stdin.readline().strip())  for _ in range(N) ]



q=deque()



for x in A:

	i=bisect_left(q,x)

	if i==0:

		q.appendleft(x)

	else:

		q[i-1]=x



print(len(q))
import sys

from collections import deque

from bisect import bisect_left, bisect_right



N=eval(input())

seq=[ int(sys.stdin.readline().strip())*-1  for _ in range(N) ]



LIS = [seq[0]]

for i in range(len(seq)):

	if i==0: continue

	if seq[i] >= LIS[-1]:

		LIS.append(seq[i])

	else:

		LIS[bisect_right(LIS, seq[i])] = seq[i]



print((len(LIS)))
import sys
from collections import deque
from bisect import bisect_left, bisect_right

N = eval(input())
A = [int(sys.stdin.readline().strip()) for _ in range(N)]
q = deque()
for x in A:
    i = bisect_left(q, x)
    if i == 0:
        q.appendleft(x)
    else:
        q[i - 1] = x
print(len(q))

import sys
from collections import deque
from bisect import bisect_left, bisect_right

N = eval(input())
seq = [int(sys.stdin.readline().strip()) * -1 for _ in range(N)]
LIS = [seq[0]]
for i in range(len(seq)):
    if i == 0:
        continue
    if seq[i] >= LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect_right(LIS, seq[i])] = seq[i]
print((len(LIS)))

-A = [int(sys.stdin.readline().strip()) for _ in range(N)] -q = deque() -for x in A: -    i = bisect_left(q, x) +seq = [int(sys.stdin.readline().strip()) * -1 for _ in range(N)] +LIS = [seq[0]] +for i in range(len(seq)): -        q.appendleft(x) +        continue +    if seq[i] >= LIS[-1]: +        LIS.append(seq[i]) -        q[i - 1] = x -print(len(q)) +        LIS[bisect_right(LIS, seq[i])] = seq[i] +print((len(LIS)))