from bisect import bisect_right



N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]

A.reverse()



L = [A[0]]

for a in A[1:]:

    if a >= L[-1]:

        L.append(a)

    else:

        L[bisect_right(L, a)] = a



print((len(L)))

from bisect import bisect

N = int(eval(input()))

A = [-int(eval(input())) for _ in range(N)]

L = [A[0]]

for a in A[1:]:

    if a >= L[-1]:

        L.append(a)

    else:

        L[bisect(L, a)] = a

print((len(L)))
from bisect import bisect_right

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
A.reverse()
L = [A[0]]
for a in A[1:]:
    if a >= L[-1]:
        L.append(a)
    else:
        L[bisect_right(L, a)] = a
print((len(L)))

from bisect import bisect

N = int(eval(input()))
A = [-int(eval(input())) for _ in range(N)]
L = [A[0]]
for a in A[1:]:
    if a >= L[-1]:
        L.append(a)
    else:
        L[bisect(L, a)] = a
print((len(L)))

-from bisect import bisect_right +from bisect import bisect -A = [int(eval(input())) for _ in range(N)] -A.reverse() +A = [-int(eval(input())) for _ in range(N)] -        L[bisect_right(L, a)] = a +        L[bisect(L, a)] = a