Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [0 for i in range(N)]

color = 1
A[0] = int(input())

for i in range(N - 1):
        a = int(input())
        num = -1
        for j in range(color):
                if A[j] < a:
                        num = j + 1
                        A[j] = a
                        break

        if num == -1:
                A[color] = a
                color += 1

print(color)

Fixed submission:
N = int(input())
A = [-1 for i in range(N)]

color = 1
A[0] = int(input())


def search(A, color, a):
        left = 0
        right = color - 1
        signal = 0
        while left < right:
                mid = (left + right) // 2
                if A[mid] == a - 1:
                        return mid
                        signal = 1
                elif a <= A[mid]:
                        left = mid + 1
                else:
                        right = mid
        if signal == 0:
                return left


for i in range(N - 1):
        
        a = int(input())
        num = search(A, color, a)
        if num == color - 1 and a <= A[num]:
                A[color] = a
                color += 1
        else:
                A[num] = a

print(color)

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

remain = N
color = 0

while remain != 0:
        num = A[0]
        B = []
        remain -= 1
        for i in range(1, len(A)):
                if num >= A[i]:
                        B.append(A[i])
                else:
                        num = A[i]
                        remain -= 1
        
        color += 1
        A = B

print(color)





Fixed submission:
N = int(input())
A = [-1 for i in range(N)]

color = 1
A[0] = int(input())


def search(A, color, a):
        left = 0
        right = color - 1
        signal = 0
        while left < right:
                mid = (left + right) // 2
                if A[mid] == a - 1:
                        return mid
                        signal = 1
                elif a <= A[mid]:
                        left = mid + 1
                else:
                        right = mid
        if signal == 0:
                return left


for i in range(N - 1):
        
        a = int(input())
        num = search(A, color, a)
        if num == color - 1 and a <= A[num]:
                A[color] = a
                color += 1
        else:
                A[num] = a

print(color)

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

remain = N
color = 0

while len(A) != 0:
        num = A[0]
        B = []
        for i in range(1, len(A)):
                if num >= A[i]:
                        B.append(A[i])
                else:
                        num = A[i]
        
        color += 1
        A = B

print(color)

Fixed submission:
N = int(input())
A = [-1 for i in range(N)]

color = 1
A[0] = int(input())


def search(A, color, a):
        left = 0
        right = color - 1
        signal = 0
        while left < right:
                mid = (left + right) // 2
                if A[mid] == a - 1:
                        return mid
                        signal = 1
                elif a <= A[mid]:
                        left = mid + 1
                else:
                        right = mid
        if signal == 0:
                return left


for i in range(N - 1):
        
        a = int(input())
        num = search(A, color, a)
        if num == color - 1 and a <= A[num]:
                A[color] = a
                color += 1
        else:
                A[num] = a

print(color)