from bisect import bisect_left

N = int(eval(input()))

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

X = [A[0]]



for i in range(1, N):

    if X[0] >= A[i]:

        X.insert(0, A[i])

    else:

        idx = bisect_left(X, A[i])

        X[idx-1] = A[i]



print((len(X)))

from bisect import bisect_right

N = int(eval(input()))

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

A.reverse()

X = [A[0]]



for i in range(1, N):

    if X[-1] <= A[i]:

        X.append(A[i])

    else:

        idx = bisect_right(X, A[i])

        X[idx] = A[i]



print((len(X)))

from bisect import bisect_left

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
X = [A[0]]
for i in range(1, N):
    if X[0] >= A[i]:
        X.insert(0, A[i])
    else:
        idx = bisect_left(X, A[i])
        X[idx - 1] = A[i]
print((len(X)))

from bisect import bisect_right

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
A.reverse()
X = [A[0]]
for i in range(1, N):
    if X[-1] <= A[i]:
        X.append(A[i])
    else:
        idx = bisect_right(X, A[i])
        X[idx] = A[i]
print((len(X)))

-from bisect import bisect_left +from bisect import bisect_right +A.reverse() -    if X[0] >= A[i]: -        X.insert(0, A[i]) +    if X[-1] <= A[i]: +        X.append(A[i]) -        idx = bisect_left(X, A[i]) -        X[idx - 1] = A[i] +        idx = bisect_right(X, A[i]) +        X[idx] = A[i]