Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
n = len(s)
m = len(t)
dp = [[0 for i in range(1 + m)] for j in range(1 + n)]
word = [["" for i in range(1 + m)] for j in range(1 + n)]
ans = [0, 0]
res=0
for i in range(1, n + 1):
    for j in range(1, m + 1):
        if s[i - 1] == t[j - 1]:
            word[i][j] = word[i - 1][j - 1] + s[i - 1]
            dp[i][j] = dp[i - 1][j - 1] + 1
            if dp[i][j] > res:
                ans = [i, j]
            res = max(res, dp[i][j])
        else:
            if dp[i - 1][j] >= dp[i][j - 1]:
                word[i][j] = word[i - 1][j]
            else:
                word[i][j] = word[i][j - 1]
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
i, j = ans

print(word[i][j])

Fixed submission:
s = input()
t = input()

m = len(s)
n = len(t)

dp = [[None] * (n+1) for i in range(m+1)]

for i in range(m+1):
    for j in range(n+1):

        if i == 0 or j == 0:
            dp[i][j] = 0

        elif s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1

        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])



final = dp[m][n]

lcs = [""] * (final + 1)
lcs[final] = ""

i = m
j = n

while i > 0 and j > 0:
    if s[i-1] == t[j-1]:
        lcs[final-1] = s[i-1]
        i -= 1
        j -= 1
        final -= 1

    elif dp[i-1][j] > dp[i][j-1]:
        i -= 1
    else:
        j -= 1


print("".join(lcs))

Buggy python submission (verdict: Runtime Error):
c = []
direction = []
def lcsLength(s, t):
    n = len(s) + 1
    m = len(t) + 1
    global c, direction
    c = [[-1] * (m) for x in [-1] * (n)]
    direction = [[-1] * (m) for x in [-1] * (n)]
    lcsLengthMemoized(s, t, n - 1, m - 1)
    return direction

def lcsLengthMemoized(s, t, i, j):
    global c
    if c[i][j] == -1:
        if i == 0 or j == 0:
            c[i][j] = 0
            return c[i][j]
        elif s[i - 1] == t[j - 1]:
            c[i][j] = lcsLengthMemoized(s, t, i - 1, j - 1) + 1
            direction[i - 1][j - 1] = 0 # volta uma linha e uma coluna
            return c[i][j]
        else:
            top_p = lcsLengthMemoized(s, t, i - 1, j)
            left_p = lcsLengthMemoized(s, t, i, j - 1)
            if left_p >= top_p:
                c[i][j] = left_p
                direction[i - 1][j - 1] = 1 # volta uma coluna na mesma linha
            else:
                c[i][j] = top_p
                direction[i - 1][j - 1] = 2 # volta uma linha na mesma coluna
            return c[i][j]
    else:
        return c[i][j]

def getLCS(direction, s, i, j, lcs=""):
    if i < 0 or j < 0:
        return lcs
    if direction[i][j] == 0: # volta uma linha e uma coluna
        lcs += getLCS(direction, s, i - 1, j - 1, lcs)
        lcs += s[i]
        return lcs
    elif direction[i][j] == 2: # volta uma linha na mesma coluna
        lcs += getLCS(direction, s, i - 1, j, lcs)
    else: # volta uma coluna na mesma linha
        lcs += getLCS(direction, s, i, j - 1, lcs)
    return lcs

s = input()
t = input()
d = lcsLength(s, t)
print(getLCS(d, s, len(d) - 2, len(d[0]) - 2))

Fixed submission:
s = input()
t = input()

m = len(s)
n = len(t)

dp = [[None] * (n+1) for i in range(m+1)]

for i in range(m+1):
    for j in range(n+1):

        if i == 0 or j == 0:
            dp[i][j] = 0

        elif s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1

        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])



final = dp[m][n]

lcs = [""] * (final + 1)
lcs[final] = ""

i = m
j = n

while i > 0 and j > 0:
    if s[i-1] == t[j-1]:
        lcs[final-1] = s[i-1]
        i -= 1
        j -= 1
        final -= 1

    elif dp[i-1][j] > dp[i][j-1]:
        i -= 1
    else:
        j -= 1


print("".join(lcs))

Buggy python submission (verdict: Time Limit Exceeded):
def lcsLength(s, t):
    n = len(s) + 1
    m = len(t) + 1
    c = [[-1] * (m) for x in [-1] * (n)]
    direction = [[-1] * (m) for x in [-1] * (n)]
    for i in range(n):
        c[i][0] = 0
    for j in range(m):
        c[0][j] = 0
    for i in range(1, n):
        for j in range(1, m):
            if s[i - 1] == t[j - 1]:
                c[i][j] = c[i - 1][j - 1] + 1
                direction[i][j] = 0 # volta uma linha e uma coluna
            elif c[i][j - 1] >= c[i - 1][j]:
                c[i][j] = c[i][j - 1]
                direction[i][j] = 1 # volta uma coluna na mesma linha
            else:
                c[i][j] = c[i - 1][j]
                direction[i][j] = 2 # volta uma linha na mesma coluna
    return direction

def getLCS(direction, s, i, j, lcs=""):
    if i == 0 or j == 0:
        return lcs
    if direction[i][j] == 0: # volta uma linha e uma coluna
        lcs += getLCS(direction, s, i - 1, j - 1, lcs)
        lcs += s[i - 1]
        return lcs
    elif direction[i][j] == 2: # volta uma linha na mesma coluna
        lcs += getLCS(direction, s, i - 1, j, lcs)
    else: # volta uma coluna na mesma linha
        lcs += getLCS(direction, s, i, j - 1, lcs)
    return lcs

s = input()
t = input()
d = lcsLength(s, t)
print(getLCS(d, s, len(d) - 1, len(d[0]) - 1))

Fixed submission:
s = input()
t = input()

m = len(s)
n = len(t)

dp = [[None] * (n+1) for i in range(m+1)]

for i in range(m+1):
    for j in range(n+1):

        if i == 0 or j == 0:
            dp[i][j] = 0

        elif s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1

        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])



final = dp[m][n]

lcs = [""] * (final + 1)
lcs[final] = ""

i = m
j = n

while i > 0 and j > 0:
    if s[i-1] == t[j-1]:
        lcs[final-1] = s[i-1]
        i -= 1
        j -= 1
        final -= 1

    elif dp[i-1][j] > dp[i][j-1]:
        i -= 1
    else:
        j -= 1


print("".join(lcs))

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
from collections import defaultdict
trim = lambda s: s[:-1] if s[-1] == "\n" else s
s = trim(stdin.readline())
t = trim(stdin.readline())

dp = defaultdict(lambda: defaultdict(int))
dp[0][0] = 0
for minS in range(0, len(s)):
    for minT in range(0, len(t)):
        dp[minS+1][minT] = max(dp[minS+1][minT], dp[minS][minT])
        dp[minS][minT+1] = max(dp[minS][minT+1], dp[minS][minT])
        if s[minS] == t[minT]:
            dp[minS+1][minT+1] = max(dp[minS+1][minT+1], dp[minS][minT]+1)
            
edgesS = list(dp[len(s)].values())
edgesT = [dp[i][len(t)] for i in range(0, len(s)+1)]
ind = (-1, -1)
ans = ''
if max(edgesS) >= max(edgesT):
    for i in range(0, len(t)+1):
        if dp[len(s)][i] == max(edgesS):
            ind = (len(s), i)
            break
    while (ind[0] != 0) and (ind[1] != 0):
        cur = max(dp[ind[0]-1][ind[1]-1], dp[ind[0]-1][ind[1]], dp[ind[0]][ind[1]-1])
        if (cur == dp[ind[0]-1][ind[1]-1]) and (s[ind[0]-1] == t[ind[1]-1]):
            ind = (ind[0]-1, ind[1]-1)
            ans += s[ind[0]]
        elif cur == dp[ind[0]-1][ind[1]]:
            ind = (ind[0]-1, ind[1])
        else:
            ind = (ind[0], ind[1]-1)
else:
    for i in range(0, len(s)+1):
        if dp[i][len(t)] == max(edgesT):
            ind = (i, len(t))
            break
    while (ind[0] != 0) and (ind[1] != 0):
        cur = max(dp[ind[0]-1][ind[1]-1], dp[ind[0]-1][ind[1]], dp[ind[0]][ind[1]-1])
        if cur == dp[ind[0]-1][ind[1]-1]:
            ind = (ind[0]-1, ind[1]-1)
            ans += s[ind[0]]
        elif cur == dp[ind[0]-1][ind[1]]:
            ind = (ind[0]-1, ind[1])
        else:
            ind = (ind[0], ind[1]-1)
print(ans[::-1])

Fixed submission:
s = input()
t = input()

m = len(s)
n = len(t)

dp = [[None] * (n+1) for i in range(m+1)]

for i in range(m+1):
    for j in range(n+1):

        if i == 0 or j == 0:
            dp[i][j] = 0

        elif s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1

        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])



final = dp[m][n]

lcs = [""] * (final + 1)
lcs[final] = ""

i = m
j = n

while i > 0 and j > 0:
    if s[i-1] == t[j-1]:
        lcs[final-1] = s[i-1]
        i -= 1
        j -= 1
        final -= 1

    elif dp[i-1][j] > dp[i][j-1]:
        i -= 1
    else:
        j -= 1


print("".join(lcs))