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

    s = input()
    t = input()
    m, n = len(s), len(t)
    dp = [["" for _ in range(n+1)] for _ in range(2)]

    for i in range(m):
        for j in range(n):
            if s[i] == t[j]:
                dp[(i+1)%2][j+1] = dp[i%2][j] + s[i]
            else:
                if len(dp[(i+1)%2][j]) >= len(dp[i%2][j+1]):
                    dp[(i+1)%2][j+1] = dp[(i+1)%2][j]
                else:
                    dp[(i+1)%2][j+1] = dp[i%2][j+1]
    return dp[(i+1)%2][n]


if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    s = input()
    t = input()
    m, n = len(s), len(t)
    dp = [[0 for _ in range(n+1)] for _ in range(m+1)]

    for i in range(m):
        for j in range(n):
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

    i, j = m, n
    ans = ""
    while i > 0 and j > 0:
        if s[i-1] == t[j-1]:
            ans += s[i-1]
            i -= 1
            j -= 1
        elif dp[i][j-1] > dp[i-1][j]:
            j -= 1
        else:
            i -= 1
    return ans[::-1]


if __name__ == '__main__':
    print(main())

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

    s = input()
    t = input()
    m, n = len(s), len(t)
    dp = [["" for _ in range(n+1)] for _ in range(2)]

    for i in range(m):
        for j in range(n):
            if s[i] == t[j]:
                dp[(i+1)%2][j+1] = dp[i%2][j] + s[i]
            else:
                max_l = 0
                max_cand = ""
                for c in [dp[(i+1)%2][j], dp[i%2][j+1]]:
                    if len(c) > max_l:
                        max_l = len(c)
                        max_cand = c
                dp[(i+1)%2][j+1] = max_cand
    return dp[(i+1)%2][n]


if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    s = input()
    t = input()
    m, n = len(s), len(t)
    dp = [[0 for _ in range(n+1)] for _ in range(m+1)]

    for i in range(m):
        for j in range(n):
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

    i, j = m, n
    ans = ""
    while i > 0 and j > 0:
        if s[i-1] == t[j-1]:
            ans += s[i-1]
            i -= 1
            j -= 1
        elif dp[i][j-1] > dp[i-1][j]:
            j -= 1
        else:
            i -= 1
    return ans[::-1]


if __name__ == '__main__':
    print(main())

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

    s = input()
    t = input()
    m, n = len(s), len(t)
    dp = [["" for _ in range(n+1)] for _ in range(m+1)]

    for i in range(m):
        for j in range(n):
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j] + s[i]
            else:
                cand = [dp[i][j], dp[i+1][j], dp[i][j+1]]
                max_l = 0
                max_cand = ""
                for c in cand:
                    if len(c) > max_l:
                        max_l = len(c)
                        max_cand = c
                dp[i+1][j+1] = max_cand
    return dp[m][n]


if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    s = input()
    t = input()
    m, n = len(s), len(t)
    dp = [[0 for _ in range(n+1)] for _ in range(m+1)]

    for i in range(m):
        for j in range(n):
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

    i, j = m, n
    ans = ""
    while i > 0 and j > 0:
        if s[i-1] == t[j-1]:
            ans += s[i-1]
            i -= 1
            j -= 1
        elif dp[i][j-1] > dp[i-1][j]:
            j -= 1
        else:
            i -= 1
    return ans[::-1]


if __name__ == '__main__':
    print(main())