import bisect

n = int(eval(input()))

A = [int(eval(input())) for j in range(n)]

dp = [A[0]]

for i in range(1, n):

    if dp[-1] < A[i]:

        dp.append(A[i])

    else:

        dp[bisect.bisect_left(dp, A[i])] = A[i]

print((len(dp)))
import bisect

n = int(eval(input()))

A = [int(eval(input())) for j in range(n)]

dp = A[:1]

for a_i in A[1:]:

    if dp[-1] < a_i:

        dp.append(a_i)

    else:

        dp[bisect.bisect_left(dp, a_i)] = a_i

print((len(dp)))
import bisect

n = int(eval(input()))
A = [int(eval(input())) for j in range(n)]
dp = [A[0]]
for i in range(1, n):
    if dp[-1] < A[i]:
        dp.append(A[i])
    else:
        dp[bisect.bisect_left(dp, A[i])] = A[i]
print((len(dp)))

import bisect

n = int(eval(input()))
A = [int(eval(input())) for j in range(n)]
dp = A[:1]
for a_i in A[1:]:
    if dp[-1] < a_i:
        dp.append(a_i)
    else:
        dp[bisect.bisect_left(dp, a_i)] = a_i
print((len(dp)))

-dp = [A[0]] -for i in range(1, n): -    if dp[-1] < A[i]: -        dp.append(A[i]) +dp = A[:1] +for a_i in A[1:]: +    if dp[-1] < a_i: +        dp.append(a_i) -        dp[bisect.bisect_left(dp, A[i])] = A[i] +        dp[bisect.bisect_left(dp, a_i)] = a_i