# 広義最長部分増加数列の長さを求めるdef

# 配列LIS自体は広義最長部分増加文字列ではない

import bisect

def lis(seq):

    LIS = [seq[0]]

    for i in range(1, len(seq)):

        if seq[i] >= LIS[-1]:

            LIS.append(seq[i])

        else:

            LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]

    return(len(LIS))



n = int(eval(input()))

a = [0] * n

for i in range(n):

    a[i] = int(eval(input()))



b = a[::-1]

print((lis(b)))
n = int(eval(input()))

a = []

for i in range(n):

    ai = int(eval(input()))

    a.append(ai)



lst = [a[0]]

for i in range(1, n):

    ai = a[i]

    left = -1

    right = len(lst)

    while left+1 < right:

        mid = (left + right) // 2

        if lst[mid] < ai:

            right = mid

        else:

            left = mid

    if right == len(lst):

        lst.append(ai)

    else:

        lst[right] = ai

print((len(lst)))
# 広義最長部分増加数列の長さを求めるdef
# 配列LIS自体は広義最長部分増加文字列ではない
import bisect


def lis(seq):
    LIS = [seq[0]]
    for i in range(1, len(seq)):
        if seq[i] >= LIS[-1]:
            LIS.append(seq[i])
        else:
            LIS[bisect.bisect_right(LIS, seq[i])] = seq[i]
    return len(LIS)


n = int(eval(input()))
a = [0] * n
for i in range(n):
    a[i] = int(eval(input()))
b = a[::-1]
print((lis(b)))

n = int(eval(input()))
a = []
for i in range(n):
    ai = int(eval(input()))
    a.append(ai)
lst = [a[0]]
for i in range(1, n):
    ai = a[i]
    left = -1
    right = len(lst)
    while left + 1 < right:
        mid = (left + right) // 2
        if lst[mid] < ai:
            right = mid
        else:
            left = mid
    if right == len(lst):
        lst.append(ai)
    else:
        lst[right] = ai
print((len(lst)))

-# 広義最長部分増加数列の長さを求めるdef -# 配列LIS自体は広義最長部分増加文字列ではない -import bisect - - -def lis(seq): -    LIS = [seq[0]] -    for i in range(1, len(seq)): -        if seq[i] >= LIS[-1]: -            LIS.append(seq[i]) +n = int(eval(input())) +a = [] +for i in range(n): +    ai = int(eval(input())) +    a.append(ai) +lst = [a[0]] +for i in range(1, n): +    ai = a[i] +    left = -1 +    right = len(lst) +    while left + 1 < right: +        mid = (left + right) // 2 +        if lst[mid] < ai: +            right = mid -            LIS[bisect.bisect_right(LIS, seq[i])] = seq[i] -    return len(LIS) - - -n = int(eval(input())) -a = [0] * n -for i in range(n): -    a[i] = int(eval(input())) -b = a[::-1] -print((lis(b))) +            left = mid +    if right == len(lst): +        lst.append(ai) +    else: +        lst[right] = ai +print((len(lst)))