s=eval(input())

t=eval(input())

n=len(s)

m=len(t)

dp=[[0 for i in range(m+1)] for j in range(n+1)]

for i in range(n):

    for j in range(m):

        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])

ans = ''

while(dp[n][m]>0):

  if dp[n][m] == dp[n-1][m-1] +1 and dp[n][m] == dp[n-1][m] +1 and dp[n][m] == dp[n][m-1] +1:

    ans = ''.join([s[n-1],ans])

    n -= 1

    m -= 1

  elif dp[n-1][m] > dp[n][m-1]:

    n -= 1

  else:

    m -= 1

print(ans)
import numpy as np



def longest_common_subsequence(S, T):

    """compute table dp satisfying: 

    dp[i,j] = LCS(S[:i], T[:j])"""

    LS, LT = len(S), len(T)

    dp = np.zeros((LS + 1, LT + 1), np.int32)

    for n in range(1, LS + 1):

        dp[n, 1:] = dp[n - 1, :-1] + (S[n - 1] == T)  # 左上から

        np.maximum(dp[n], dp[n - 1], out=dp[n])  # 上から

        np.maximum.accumulate(dp[n], out=dp[n])  # 左から

    return dp



def reconstruct_LCS(S, T, dp):

    tmp = []

    i, j = len(S), len(T)

    while i and j:

        if S[i - 1] == T[j - 1]:

            i, j = i - 1, j - 1

            tmp.append(S[i])

        elif dp[i, j] == dp[i - 1, j]:

            i -= 1

        else:

            j -= 1

    return ''.join(reversed(tmp))



s, t = np.array(list(eval(input()))), np.array(list(eval(input())))



print((reconstruct_LCS(s, t, longest_common_subsequence(s, t))))



s = eval(input())
t = eval(input())
n = len(s)
m = len(t)
dp = [[0 for i in range(m + 1)] for j in range(n + 1)]
for i in range(n):
    for j in range(m):
        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])
ans = ""
while dp[n][m] > 0:
    if (
        dp[n][m] == dp[n - 1][m - 1] + 1
        and dp[n][m] == dp[n - 1][m] + 1
        and dp[n][m] == dp[n][m - 1] + 1
    ):
        ans = "".join([s[n - 1], ans])
        n -= 1
        m -= 1
    elif dp[n - 1][m] > dp[n][m - 1]:
        n -= 1
    else:
        m -= 1
print(ans)

import numpy as np


def longest_common_subsequence(S, T):
    """compute table dp satisfying:
    dp[i,j] = LCS(S[:i], T[:j])"""
    LS, LT = len(S), len(T)
    dp = np.zeros((LS + 1, LT + 1), np.int32)
    for n in range(1, LS + 1):
        dp[n, 1:] = dp[n - 1, :-1] + (S[n - 1] == T)  # 左上から
        np.maximum(dp[n], dp[n - 1], out=dp[n])  # 上から
        np.maximum.accumulate(dp[n], out=dp[n])  # 左から
    return dp


def reconstruct_LCS(S, T, dp):
    tmp = []
    i, j = len(S), len(T)
    while i and j:
        if S[i - 1] == T[j - 1]:
            i, j = i - 1, j - 1
            tmp.append(S[i])
        elif dp[i, j] == dp[i - 1, j]:
            i -= 1
        else:
            j -= 1
    return "".join(reversed(tmp))


s, t = np.array(list(eval(input()))), np.array(list(eval(input())))
print((reconstruct_LCS(s, t, longest_common_subsequence(s, t))))

-s = eval(input()) -t = eval(input()) -n = len(s) -m = len(t) -dp = [[0 for i in range(m + 1)] for j in range(n + 1)] -for i in range(n): -    for j in range(m): -        if s[i] == t[j]: -            dp[i + 1][j + 1] = dp[i][j] + 1 +import numpy as np + + +def longest_common_subsequence(S, T): +    """compute table dp satisfying: +    dp[i,j] = LCS(S[:i], T[:j])""" +    LS, LT = len(S), len(T) +    dp = np.zeros((LS + 1, LT + 1), np.int32) +    for n in range(1, LS + 1): +        dp[n, 1:] = dp[n - 1, :-1] + (S[n - 1] == T)  # 左上から +        np.maximum(dp[n], dp[n - 1], out=dp[n])  # 上から +        np.maximum.accumulate(dp[n], out=dp[n])  # 左から +    return dp + + +def reconstruct_LCS(S, T, dp): +    tmp = [] +    i, j = len(S), len(T) +    while i and j: +        if S[i - 1] == T[j - 1]: +            i, j = i - 1, j - 1 +            tmp.append(S[i]) +        elif dp[i, j] == dp[i - 1, j]: +            i -= 1 -            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]) -ans = "" -while dp[n][m] > 0: -    if ( -        dp[n][m] == dp[n - 1][m - 1] + 1 -        and dp[n][m] == dp[n - 1][m] + 1 -        and dp[n][m] == dp[n][m - 1] + 1 -    ): -        ans = "".join([s[n - 1], ans]) -        n -= 1 -        m -= 1 -    elif dp[n - 1][m] > dp[n][m - 1]: -        n -= 1 -    else: -        m -= 1 -print(ans) +            j -= 1 +    return "".join(reversed(tmp)) + + +s, t = np.array(list(eval(input()))), np.array(list(eval(input()))) +print((reconstruct_LCS(s, t, longest_common_subsequence(s, t))))