Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
num_list = []
for i in range(n):
    num_list.append(int(input()))
# 広義単調減少部分列の最長を求める

## dp[i] := num_listのi番目までの数字が末尾となるような文字列の長さの最大 と定義すると
# 1.num_list[i]番目のみ
# 2.num_list[j] >= num_list[i] を満たす num_list[j] で終わる文字列の末尾にnum_list[i] をつける
# 1 もしくは 2をみたすものの中で最大のものがdp[i]

dp = [0] * n
dp[0] = 1

for i in range(1, n):
    add_previous = [0] # 2の条件を満たすものを入れる
    for j in range(0, i):
        if num_list[i] <= num_list[j]:
            add_previous.append(dp[j] + 1)
       
    dp[i] = max([1, max(add_previous)])
    
print(max(dp))

Fixed submission:
import bisect

n = int(input())
num_list = []
for i in range(n):
    num_list.append(int(input()) * -1) 

dp = [1] * n 

for i in num_list:
    indx = bisect.bisect_right(dp, i)
    dp[indx] = min(dp[indx], i)

ans = sum(x < 1 for x in dp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
num_list = []
for i in range(n):
    num_list.append(int(input()))

dp = [ [0, -1, -1] for i in range(n + 1) ] ## [length, sequence_top_num, sequence_second_num]

ans = 0
while sum( x==-2 for x in num_list) < n:
    longest_list = []
    for i in range(n):
        if dp[i][1] >= num_list[i]:
            if dp[i][2] < num_list[i]:
                longest_list.pop()
                longest_list.append(i)
                dp[i+1][0] = dp[i][0]
                dp[i+1][1] = num_list[i]
                dp[i+1][2] = dp[i][2]
            else:
                dp[i+1][0] = dp[i][0]
                dp[i+1][1] = dp[i][1]
                dp[i+1][2] = dp[i][2]
        else:
            dp[i+1][0] = dp[i][0] + 1
            dp[i+1][2] = dp[i][1]
            dp[i+1][1] = num_list[i]
            longest_list.append(i)
    
    for indx in longest_list:
        num_list[indx] = -2
    
    ans += 1

print(ans)

Fixed submission:
import bisect

n = int(input())
num_list = []
for i in range(n):
    num_list.append(int(input()) * -1) 

dp = [1] * n 

for i in num_list:
    indx = bisect.bisect_right(dp, i)
    dp[indx] = min(dp[indx], i)

ans = sum(x < 1 for x in dp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
num_list = []
for i in range(n):
    num_list.append(int(input()))

dp = [ [0, -1, -1] for i in range(n + 1) ] ## [length, sequence_top_num, sequence_second_num]

ans = 0
while sum( x==-2 for x in num_list) < n:
    longest_list = []
    for i in range(n):
        if dp[i][1] >= num_list[i]:
            if dp[i][2] < num_list[i]:
                longest_list.pop()
                longest_list.append(i)
                dp[i+1][0] = dp[i][0]
                dp[i+1][1] = num_list[i]
                dp[i+1][2] = dp[i][2]
            else:
                dp[i+1][0] = dp[i][0]
                dp[i+1][1] = dp[i][1]
                dp[i+1][2] = dp[i][2]
        else:
            dp[i+1][0] = dp[i][0] + 1
            dp[i+1][2] = dp[i][1]
            dp[i+1][1] = num_list[i]
            longest_list.append(i)
    
    for indx in longest_list:
        num_list[indx] = -2
    
    ans += 1

print(ans)

Fixed submission:
import bisect

n = int(input())
num_list = []
for i in range(n):
    num_list.append(int(input()) * -1) 

dp = [1] * n 

for i in num_list:
    indx = bisect.bisect_right(dp, i)
    dp[indx] = min(dp[indx], i)

ans = sum(x < 1 for x in dp)

print(ans)