Buggy python submission (verdict: Runtime Error):
S = input().strip()
T = input().strip()


dp = [[0] * (len(T)+1) for _ in range(len(S))]

for i, s in enumerate(S):
  for j, t in enumerate(T):
    if s == t:
      dp[i][j] = dp[i-1][j-1] + 1
    else:
      dp[i][j] = max(dp[i][j-1], dp[i-1][j])
ans = []
s = (len(S)-1, len(T)-1)
while True:
  x, y = s
  if x < 0 or y < 0:
    assert x == y
    break
  if S[x] == T[y]:
    ans.append(S[x])
    s = (x-1, y-1)
  else:
    if dp[x-1][y] > dp[x][y-1]:
      s = (x-1, y)
    else:
      s = (x, y-1)

    
print(''.join(reversed(ans)))

Fixed submission:
S = input().strip()
T = input().strip()


dp = [[0] * (len(T)+1) for _ in range(len(S)+1)]

for i, s in enumerate(S):
  for j, t in enumerate(T):
    if s == t:
      dp[i][j] = dp[i-1][j-1] + 1
    else:
      dp[i][j] = max(dp[i][j-1], dp[i-1][j])
ans = []
s = (len(S)-1, len(T)-1)
while True:
  x, y = s
  if x < 0 or y < 0:
    break
  if S[x] == T[y]:
    ans.append(S[x])
    s = (x-1, y-1)
  else:
    if dp[x-1][y] > dp[x][y-1]:
      s = (x-1, y)
    else:
      s = (x, y-1)

    
print(''.join(reversed(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
S = input().strip()
T = input().strip()

import bisect
from collections import defaultdict
ti = defaultdict(list)

for i, c in enumerate(T):
  ti[c].append(i)

dp = {}
dp[-1] = []

for c in S:
  ndp = {}
  for k, v in dp.items():
    #j = T.find(c, k+1)
    l = bisect.bisect_left(ti[c], k+1)
    if l < len(ti[c]):
      j = ti[c][l]
    else:
      j = -1
    if k not in ndp or (len(v) > len(ndp[k])):
      ndp[k] = v[:]
    if j != -1:
      if j not in ndp or (len(v) + 1 > len(ndp[j])):
        ndp[j] = v[:] + [c]
  dp = ndp

ans = ''
for s in list(map(lambda x: ''.join(x), dp.values())):
  if len(s) > len(ans):
    ans = s
print(ans)


Fixed submission:
S = input().strip()
T = input().strip()


dp = [[0] * (len(T)+1) for _ in range(len(S)+1)]

for i, s in enumerate(S):
  for j, t in enumerate(T):
    if s == t:
      dp[i][j] = dp[i-1][j-1] + 1
    else:
      dp[i][j] = max(dp[i][j-1], dp[i-1][j])
ans = []
s = (len(S)-1, len(T)-1)
while True:
  x, y = s
  if x < 0 or y < 0:
    break
  if S[x] == T[y]:
    ans.append(S[x])
    s = (x-1, y-1)
  else:
    if dp[x-1][y] > dp[x][y-1]:
      s = (x-1, y)
    else:
      s = (x, y-1)

    
print(''.join(reversed(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
S = input().strip()
T = input().strip()

import bisect

dp = {}
dp[-1] = []

for c in S:
  ndp = {}
  for k, v in dp.items():
    j = T.find(c, k+1)
    if k not in ndp or (len(v) > len(ndp[k])):
      ndp[k] = v[:]
    if j != -1:
      if j not in ndp or (len(v) + 1 > len(ndp[j])):
        ndp[j] = v[:] + [c]
  dp = ndp

ans = ''
for s in list(map(lambda x: ''.join(x), dp.values())):
  if len(s) > len(ans):
    ans = s
print(ans)


Fixed submission:
S = input().strip()
T = input().strip()


dp = [[0] * (len(T)+1) for _ in range(len(S)+1)]

for i, s in enumerate(S):
  for j, t in enumerate(T):
    if s == t:
      dp[i][j] = dp[i-1][j-1] + 1
    else:
      dp[i][j] = max(dp[i][j-1], dp[i-1][j])
ans = []
s = (len(S)-1, len(T)-1)
while True:
  x, y = s
  if x < 0 or y < 0:
    break
  if S[x] == T[y]:
    ans.append(S[x])
    s = (x-1, y-1)
  else:
    if dp[x-1][y] > dp[x][y-1]:
      s = (x-1, y)
    else:
      s = (x, y-1)

    
print(''.join(reversed(ans)))