n = int(eval(input()))

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





b = []



for ai in a:

    if len(b) == 0:

        b.append(ai)

    else:

        if ai <= b[-1]:

            b.append(ai)

        else:

            l = -1

            r = len(b)

            mid = (l + r) // 2

            while (r - l > 1):

                mid = (l + r) // 2

                if b[mid] >= ai:

                    l = mid

                else:

                    r = mid

            b[r] = ai



print((len(b)))

from collections import deque

import bisect



n = int(eval(input()))

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





b = deque([])



for ai in a:

    if len(b) == 0:

        b.append(ai)

    else:

        if ai <= b[0]:

            b.appendleft(ai)

        else:

            index = bisect.bisect_left(b, ai)

            b[index-1] = ai



print((len(b)))

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = []
for ai in a:
    if len(b) == 0:
        b.append(ai)
    else:
        if ai <= b[-1]:
            b.append(ai)
        else:
            l = -1
            r = len(b)
            mid = (l + r) // 2
            while r - l > 1:
                mid = (l + r) // 2
                if b[mid] >= ai:
                    l = mid
                else:
                    r = mid
            b[r] = ai
print((len(b)))

from collections import deque
import bisect

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = deque([])
for ai in a:
    if len(b) == 0:
        b.append(ai)
    else:
        if ai <= b[0]:
            b.appendleft(ai)
        else:
            index = bisect.bisect_left(b, ai)
            b[index - 1] = ai
print((len(b)))

+from collections import deque +import bisect + -b = [] +b = deque([]) -        if ai <= b[-1]: -            b.append(ai) +        if ai <= b[0]: +            b.appendleft(ai) -            l = -1 -            r = len(b) -            mid = (l + r) // 2 -            while r - l > 1: -                mid = (l + r) // 2 -                if b[mid] >= ai: -                    l = mid -                else: -                    r = mid -            b[r] = ai +            index = bisect.bisect_left(b, ai) +            b[index - 1] = ai