Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys

    input = sys.stdin.readline

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

    b = [-1]
    for x in a:
        for i, top in enumerate(b):
            if top < x:
                b[i] = x
                break
        else:
            b.append(x)

    ans = len(b)

    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Fixed submission:
from bisect import bisect_left
from collections import deque

n = int(input())
a = tuple(int(input()) for _ in range(n))

d = deque()

for ai in a:
    p = bisect_left(d, ai)  # aa以上の最小値のindex
    if p == 0:
        d.appendleft(ai)
    else:
        d[p - 1] = ai
ans = len(d)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
inf = float('inf')

n = int(input())
a = tuple(int(input()) for _ in range(n))

c = [inf]

for aa in a:
    push_to = -1
    target = -1
    for i, cc in enumerate(c):
        if target < cc < aa:
            push_to = i
            target = cc
    if push_to != -1:
        c[push_to] = aa
    else:
        c.append(aa)
    # print(c)
print(len(c) - 1)


Fixed submission:
from bisect import bisect_left
from collections import deque

n = int(input())
a = tuple(int(input()) for _ in range(n))

d = deque()

for ai in a:
    p = bisect_left(d, ai)  # aa以上の最小値のindex
    if p == 0:
        d.appendleft(ai)
    else:
        d[p - 1] = ai
ans = len(d)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline

inf = float('inf')

n = int(input())
a = tuple(int(input()) for _ in range(n))

seen = [False] * n
cnt = 0

flg = True
while flg:
    flg = False
    num = -1
    for i, aa in enumerate(a):
        if seen[i]:
            continue
        flg = True
        if num == -1:
            num = aa
            seen[i] = True
            cnt += 1
        else:
            if aa > num:
                num = aa
                seen[i] = True

print(cnt)


Fixed submission:
from bisect import bisect_left
from collections import deque

n = int(input())
a = tuple(int(input()) for _ in range(n))

d = deque()

for ai in a:
    p = bisect_left(d, ai)  # aa以上の最小値のindex
    if p == 0:
        d.appendleft(ai)
    else:
        d[p - 1] = ai
ans = len(d)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush

inf = float('inf')

n = int(input())
a = tuple(int(input()) for _ in range(n))

h = [inf]

cnt = 0
for aa in a:
    if aa <= h[0]:
        heappush(h, aa)
        cnt += 1
    else:
        s = []
        while True:
            v = heappop(h)
            if aa <= h[0]:
                heappush(h, aa)
                for ss in s:
                    heappush(h, ss)
                break
            else:
                s.append(v)
print(cnt)


Fixed submission:
from bisect import bisect_left
from collections import deque

n = int(input())
a = tuple(int(input()) for _ in range(n))

d = deque()

for ai in a:
    p = bisect_left(d, ai)  # aa以上の最小値のindex
    if p == 0:
        d.appendleft(ai)
    else:
        d[p - 1] = ai
ans = len(d)
print(ans)