import bisect

from collections import deque

N = int(eval(input()))

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

# i<jで、 AiとAjが同じ色で塗られている場合、Ai < Ajが成り立つ.

# その際に、色の最小数をだす。

LIS = deque([nums[0]])

count = 0

for index, num in enumerate(nums):

    if index == 0:

        continue

    if num <= LIS[0]:

        LIS.appendleft(num)

    else:

        insert_index = bisect.bisect_left(LIS, num)

        LIS[insert_index - 1] = num

print((len(LIS)))

import bisect

from collections import deque

N = int(eval(input()))

nums = deque([])



for i in range(N):

    num = int(eval(input()))

    if i == 0:

        nums.append(num)

    else:

        if nums[-1] < num:

            nums[-1] = num

        else:

            insert_index = bisect.bisect_left(nums, num)

            if insert_index == 0:

                nums.appendleft(num)

            else:

                nums[insert_index - 1] = num

#     print(nums)

# print(nums)

print((len(nums)))

import bisect
from collections import deque

N = int(eval(input()))
nums = [int(eval(input())) for _ in range(N)]
# i<jで、 AiとAjが同じ色で塗られている場合、Ai < Ajが成り立つ.
# その際に、色の最小数をだす。
LIS = deque([nums[0]])
count = 0
for index, num in enumerate(nums):
    if index == 0:
        continue
    if num <= LIS[0]:
        LIS.appendleft(num)
    else:
        insert_index = bisect.bisect_left(LIS, num)
        LIS[insert_index - 1] = num
print((len(LIS)))

import bisect
from collections import deque

N = int(eval(input()))
nums = deque([])
for i in range(N):
    num = int(eval(input()))
    if i == 0:
        nums.append(num)
    else:
        if nums[-1] < num:
            nums[-1] = num
        else:
            insert_index = bisect.bisect_left(nums, num)
            if insert_index == 0:
                nums.appendleft(num)
            else:
                nums[insert_index - 1] = num
#     print(nums)
# print(nums)
print((len(nums)))

-nums = [int(eval(input())) for _ in range(N)] -# i<jで、 AiとAjが同じ色で塗られている場合、Ai < Ajが成り立つ. -# その際に、色の最小数をだす。 -LIS = deque([nums[0]]) -count = 0 -for index, num in enumerate(nums): -    if index == 0: -        continue -    if num <= LIS[0]: -        LIS.appendleft(num) +nums = deque([]) +for i in range(N): +    num = int(eval(input())) +    if i == 0: +        nums.append(num) -        insert_index = bisect.bisect_left(LIS, num) -        LIS[insert_index - 1] = num -print((len(LIS))) +        if nums[-1] < num: +            nums[-1] = num +        else: +            insert_index = bisect.bisect_left(nums, num) +            if insert_index == 0: +                nums.appendleft(num) +            else: +                nums[insert_index - 1] = num +#     print(nums) +# print(nums) +print((len(nums)))