n = int(eval(input()))

A = [int(eval(input())) for _ in range(n)]



B = []

import bisect

for i, a in enumerate(A):

    if len(B) == 0:

        B.append(-a)

    else:

        j = bisect.bisect_right(B, -a)

        #print(j)

        if j == len(B):

            B.append(-a)

        elif j == 0:

            B[0] = -a

        else:

            B[j] = -a

    #print(B)

#print(B)

print((len(B)))

n = int(eval(input()))

A = [int(eval(input())) for _ in range(n)]



A.reverse()



import bisect

B = [10**18]

for a in A:

    i = bisect.bisect_right(B, a)

    if 0 <= i < len(B):

        B[i] = a

    else:

        B.append(a)

print((len(B)))
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
B = []
import bisect

for i, a in enumerate(A):
    if len(B) == 0:
        B.append(-a)
    else:
        j = bisect.bisect_right(B, -a)
        # print(j)
        if j == len(B):
            B.append(-a)
        elif j == 0:
            B[0] = -a
        else:
            B[j] = -a
    # print(B)
# print(B)
print((len(B)))

n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
A.reverse()
import bisect

B = [10**18]
for a in A:
    i = bisect.bisect_right(B, a)
    if 0 <= i < len(B):
        B[i] = a
    else:
        B.append(a)
print((len(B)))

-B = [] +A.reverse() -for i, a in enumerate(A): -    if len(B) == 0: -        B.append(-a) +B = [10**18] +for a in A: +    i = bisect.bisect_right(B, a) +    if 0 <= i < len(B): +        B[i] = a -        j = bisect.bisect_right(B, -a) -        # print(j) -        if j == len(B): -            B.append(-a) -        elif j == 0: -            B[0] = -a -        else: -            B[j] = -a -    # print(B) -# print(B) +        B.append(a)