def bisect_right(a, x, lo=0, hi=None):

    if lo < 0:

        raise ValueError('lo must be non-negative')

    if hi is None:

        hi = len(a)

    while lo < hi:

        mid = (lo + hi) // 2

        if x > a[mid]:

            hi = mid

        else:

            lo = mid + 1

    return lo



import collections

n = int(eval(input()))

dat = []

for i in range(n):

    dat.append(int(eval(input())))

res = collections.deque([])



res.append(dat[0])

import bisect



for i in range(1, n):

    a = bisect_right(res, dat[i])

    #print("2 : {0}".format(a))



    if a == len(res):

        res.append(dat[i])

    else:

        res[a] = dat[i]

print((len(res)))

#print(res)
n = int(eval(input()))

dat = []

for i in range(n):

    dat.append(int(eval(input())))

res = []

res.append(0 - dat[0])



import bisect



for i in range(1, n):

    #print(res)

    a = bisect.bisect_right(res, 0 - dat[i])

    #print("a={0}".format(a))



    if a == len(res):

        res.append( (0 - dat[i]) )

    else:

        res[a] = (0 - dat[i])



print((len(res)))
def bisect_right(a, x, lo=0, hi=None):
    if lo < 0:
        raise ValueError("lo must be non-negative")
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo + hi) // 2
        if x > a[mid]:
            hi = mid
        else:
            lo = mid + 1
    return lo


import collections

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

for i in range(1, n):
    a = bisect_right(res, dat[i])
    # print("2 : {0}".format(a))
    if a == len(res):
        res.append(dat[i])
    else:
        res[a] = dat[i]
print((len(res)))
# print(res)

n = int(eval(input()))
dat = []
for i in range(n):
    dat.append(int(eval(input())))
res = []
res.append(0 - dat[0])
import bisect

for i in range(1, n):
    # print(res)
    a = bisect.bisect_right(res, 0 - dat[i])
    # print("a={0}".format(a))
    if a == len(res):
        res.append((0 - dat[i]))
    else:
        res[a] = 0 - dat[i]
print((len(res)))

-def bisect_right(a, x, lo=0, hi=None): -    if lo < 0: -        raise ValueError("lo must be non-negative") -    if hi is None: -        hi = len(a) -    while lo < hi: -        mid = (lo + hi) // 2 -        if x > a[mid]: -            hi = mid -        else: -            lo = mid + 1 -    return lo - - -import collections - -res = collections.deque([]) -res.append(dat[0]) +res = [] +res.append(0 - dat[0]) -    a = bisect_right(res, dat[i]) -    # print("2 : {0}".format(a)) +    # print(res) +    a = bisect.bisect_right(res, 0 - dat[i]) +    # print("a={0}".format(a)) -        res.append(dat[i]) +        res.append((0 - dat[i])) -        res[a] = dat[i] +        res[a] = 0 - dat[i] -# print(res)