n = int(eval(input()))

a = []

for i in range(n):

    a.append(int(eval(input())))



import bisect

from collections import deque



lis = deque()

for i in range(n):

    ind = bisect.bisect_left(lis,a[i])

    if ind==0:

        lis.appendleft(a[i])

    else:

        lis[ind-1] = a[i]



print((len(lis)))

import sys

def input():

    return sys.stdin.readline()[:-1]

n = int(eval(input()))

a = []

for i in range(n):

    a.append(int(eval(input())))



import bisect

from collections import deque



lis = deque()

for i in range(n):

    ind = bisect.bisect_left(lis,a[i])

    if ind==0:

        lis.appendleft(a[i])

    else:

        lis[ind-1] = a[i]



print((len(lis)))

n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
import bisect
from collections import deque

lis = deque()
for i in range(n):
    ind = bisect.bisect_left(lis, a[i])
    if ind == 0:
        lis.appendleft(a[i])
    else:
        lis[ind - 1] = a[i]
print((len(lis)))

import sys


def input():
    return sys.stdin.readline()[:-1]


n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
import bisect
from collections import deque

lis = deque()
for i in range(n):
    ind = bisect.bisect_left(lis, a[i])
    if ind == 0:
        lis.appendleft(a[i])
    else:
        lis[ind - 1] = a[i]
print((len(lis)))

+import sys + + +def input(): +    return sys.stdin.readline()[:-1] + +