import bisect

import sys

input=sys.stdin.readline

from collections import deque

N=int(eval(input()))



cnt=0

L=[]

for i in range(N):

    n=int(eval(input()))

    L.append(n)

#print(L)

Q=[-1,10**10]

Q=deque()

#Q.appendleft(10**10)

#print(Q)

for i in range(N):

    if bisect.bisect_left(Q,L[i])==0:

        Q.appendleft(L[i])

    #elif bisect.bisect_left(Q,L[i])==len(Q)-1:

        #Q.insert(len(Q)-1,L[i])

    else:

        Q[bisect.bisect_left(Q,L[i])-1]=L[i]

#print(Q)

print((len(Q)))
N=int(eval(input()))

L=[1 for i in range(N+1)]

L[0]=-10**10



import bisect

for i in range(N):

    n=int(eval(input()))

    L[bisect.bisect_right(L,-n)]=-n

#print(L)

ans=0

for i in range(1,N+1):

    if L[i]==1:

        break

    ans+=1

print(ans)
import bisect
import sys

input = sys.stdin.readline
from collections import deque

N = int(eval(input()))
cnt = 0
L = []
for i in range(N):
    n = int(eval(input()))
    L.append(n)
# print(L)
Q = [-1, 10**10]
Q = deque()
# Q.appendleft(10**10)
# print(Q)
for i in range(N):
    if bisect.bisect_left(Q, L[i]) == 0:
        Q.appendleft(L[i])
    # elif bisect.bisect_left(Q,L[i])==len(Q)-1:
    # Q.insert(len(Q)-1,L[i])
    else:
        Q[bisect.bisect_left(Q, L[i]) - 1] = L[i]
# print(Q)
print((len(Q)))

N = int(eval(input()))
L = [1 for i in range(N + 1)]
L[0] = -(10**10)
import bisect

for i in range(N):
    n = int(eval(input()))
    L[bisect.bisect_right(L, -n)] = -n
# print(L)
ans = 0
for i in range(1, N + 1):
    if L[i] == 1:
        break
    ans += 1
print(ans)

+N = int(eval(input())) +L = [1 for i in range(N + 1)] +L[0] = -(10**10) -import sys -input = sys.stdin.readline -from collections import deque - -N = int(eval(input())) -cnt = 0 -L = [] -    L.append(n) +    L[bisect.bisect_right(L, -n)] = -n -Q = [-1, 10**10] -Q = deque() -# Q.appendleft(10**10) -# print(Q) -for i in range(N): -    if bisect.bisect_left(Q, L[i]) == 0: -        Q.appendleft(L[i]) -    # elif bisect.bisect_left(Q,L[i])==len(Q)-1: -    # Q.insert(len(Q)-1,L[i]) -    else: -        Q[bisect.bisect_left(Q, L[i]) - 1] = L[i] -# print(Q) -print((len(Q))) +ans = 0 +for i in range(1, N + 1): +    if L[i] == 1: +        break +    ans += 1 +print(ans)