Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import bisect as bi


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    bi.insort_left(heads, a)
    while A:
        a = A.pop()
        if a < heads[-1]:
            j = -1
            for i, h in enumerate(heads):
                if h > a:
                    j = i
                    break
            del heads[j]
        bi.insort_left(heads, a)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import bisect as bi


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    bi.insort(heads, a)
    while A:
        a = A.pop()
        if a < heads[-1]:
            j = bi.bisect(heads, a)
            del heads[j]
        bi.insort(heads, a)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import bisect as bi


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    bi.insort_left(heads, a)
    while A:
        a = A.pop()
        if a < heads[-1]:
            k = -1
            for h in heads:
                if h > a:
                    k = h
                    break
            heads.remove(k)
            bi.insort_left(heads, a)
        else:
            bi.insort_left(heads, a)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import bisect as bi


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    bi.insort(heads, a)
    while A:
        a = A.pop()
        if a < heads[-1]:
            j = bi.bisect(heads, a)
            del heads[j]
        bi.insort(heads, a)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import heapq


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    heapq.heappush(heads, -a)
    while A:
        a = A.pop()
        h = -heapq.heappop(heads)
        if a < h:
            for b in heads[::-1]:
                if - b > a:
                    heads.remove(b)
                    heapq.heapify(heads)
                    heapq.heappush(heads, -a)
                    break
        else:
            heapq.heappush(heads, -a)
            heapq.heappush(heads, -h)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import bisect as bi


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    bi.insort(heads, a)
    while A:
        a = A.pop()
        if a < heads[-1]:
            j = bi.bisect(heads, a)
            del heads[j]
        bi.insort(heads, a)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import heapq


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    heapq.heappush(heads, -a)
    while A:
        a = A.pop()
        h = -heapq.heappop(heads)
        if a < h:
            for b in heads[::-1]:
                if - b > a:
                    heads.remove(b)
                    heapq.heappush(heads, -a)
                    break
        else:
            heapq.heappush(heads, -a)
            heapq.heappush(heads, -h)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import bisect as bi


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    bi.insort(heads, a)
    while A:
        a = A.pop()
        if a < heads[-1]:
            j = bi.bisect(heads, a)
            del heads[j]
        bi.insort(heads, a)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from copy import copy


def solve():
    N = int(input())
    A = []
    count = 0
    for _ in range(N):
        A.append(int(input()))
    while A:
        a = A.pop()
        count += 1
        B = []
        while A:
            b = A.pop()
            if b >= a:
                B.append(b)
                continue
            a = b
        A = B[::-1]
    return count
  

def main():
    print(solve())


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import bisect as bi


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    bi.insort(heads, a)
    while A:
        a = A.pop()
        if a < heads[-1]:
            j = bi.bisect(heads, a)
            del heads[j]
        bi.insort(heads, a)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve():
    N = int(input())
    A = []
    checked = [False for _ in range(N)]
    count = 0
    for _ in range(N):
        A.append(int(input()))
    for i, a in enumerate(reversed(A)):
        i = N - 1 - i  # reversed index
        # print('searching:', i, ',', a)
        if checked[i]:
            # print('checked')
            continue
        count += 1
        searching = a
        for j, b in enumerate(reversed(A[:i])):
            # print(A[:i])
            j = i - j - 1
            # print(i, j, b)
            if b >= searching or checked[j]:
                continue
            searching = b
            checked[j] = True
            # print('check:', j, ',', b)
    return count
  

def main():
    print(solve())


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import bisect as bi


def solve():
    N = int(input())
    A = []
    heads = []
    for _ in range(N):
        A.append(int(input()))
    a = A.pop()
    bi.insort(heads, a)
    while A:
        a = A.pop()
        if a < heads[-1]:
            j = bi.bisect(heads, a)
            del heads[j]
        bi.insort(heads, a)
    return len(heads)
  

def main():
    print(solve())


if __name__ == "__main__":
    main()