import sys

from bisect import bisect_left



N = int(eval(input()))

dp = [float("inf")]*N

result = -1



for n in map(int, sys.stdin.readlines()):

    i = bisect_left(dp, n)

    dp[i] = n

    result = i if i > result else result



print((result+1))
import sys

from bisect import bisect_left



N = int(eval(input()))

dp = []

append = dp.append

result = -1



for n in map(int, sys.stdin.readlines()):

    i = bisect_left(dp, n)

    if i > result:

        append(n)

        result += 1

    else:

        dp[i] = n



print((result+1))
import sys
from bisect import bisect_left

N = int(eval(input()))
dp = [float("inf")] * N
result = -1
for n in map(int, sys.stdin.readlines()):
    i = bisect_left(dp, n)
    dp[i] = n
    result = i if i > result else result
print((result + 1))

import sys
from bisect import bisect_left

N = int(eval(input()))
dp = []
append = dp.append
result = -1
for n in map(int, sys.stdin.readlines()):
    i = bisect_left(dp, n)
    if i > result:
        append(n)
        result += 1
    else:
        dp[i] = n
print((result + 1))

-dp = [float("inf")] * N +dp = [] +append = dp.append -    dp[i] = n -    result = i if i > result else result +    if i > result: +        append(n) +        result += 1 +    else: +        dp[i] = n