s = eval(input())

t = eval(input())



dp = [[0 for j in range(len(t)+1)] for i in range(len(s)+1)]

dp[0][0] = 0



for i in range(len(s)):

    for j in range(len(t)):

        if s[i] == t[j]:

            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j],dp[i][j]+1)

        else:

            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])



ans = ''

i,j = len(s),len(t)



while i>0 and j>0:

    if dp[i][j] == dp[i-1][j]:

        i -= 1

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

        j -= 1

    else:

        ans = s[i-1]+ans

        i -= 1

        j -= 1

        

print(ans)
def LCS(s,t,restore=False):

    dp = [[0 for j in range(len(t)+1)] for i in range(len(s)+1)]

    for i in range(len(s)):

        for j in range(len(t)):

            if s[i] == t[j]:

                dp[i+1][j+1] = dp[i][j]+1

            else:

                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])

    if restore:

        lcs = []

        stack = [(len(s),len(t))]

        while stack:

            x,y = stack.pop()

            if dp[x][y] == 0:

                break

            if x-1 >= 0 and dp[x][y] == dp[x-1][y]:

                stack.append((x-1,y))

            elif y-1 >= 0 and dp[x][y] == dp[x][y-1]:

                stack.append((x,y-1))

            else:

                lcs.append(s[x-1])

                stack.append((x-1,y-1))

        lcs = ''.join(lcs)[::-1]

        return dp[-1][-1],lcs

    return dp[-1][-1]

  

S = eval(input())

T = eval(input())



print((LCS(S,T,True)[1]))
s = eval(input())
t = eval(input())
dp = [[0 for j in range(len(t) + 1)] for i in range(len(s) + 1)]
dp[0][0] = 0
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j], dp[i][j] + 1)
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
ans = ""
i, j = len(s), len(t)
while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        ans = s[i - 1] + ans
        i -= 1
        j -= 1
print(ans)

def LCS(s, t, restore=False):
    dp = [[0 for j in range(len(t) + 1)] for i in range(len(s) + 1)]
    for i in range(len(s)):
        for j in range(len(t)):
            if s[i] == t[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
    if restore:
        lcs = []
        stack = [(len(s), len(t))]
        while stack:
            x, y = stack.pop()
            if dp[x][y] == 0:
                break
            if x - 1 >= 0 and dp[x][y] == dp[x - 1][y]:
                stack.append((x - 1, y))
            elif y - 1 >= 0 and dp[x][y] == dp[x][y - 1]:
                stack.append((x, y - 1))
            else:
                lcs.append(s[x - 1])
                stack.append((x - 1, y - 1))
        lcs = "".join(lcs)[::-1]
        return dp[-1][-1], lcs
    return dp[-1][-1]


S = eval(input())
T = eval(input())
print((LCS(S, T, True)[1]))

-s = eval(input()) -t = eval(input()) -dp = [[0 for j in range(len(t) + 1)] for i in range(len(s) + 1)] -dp[0][0] = 0 -for i in range(len(s)): -    for j in range(len(t)): -        if s[i] == t[j]: -            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j], dp[i][j] + 1) -        else: -            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]) -ans = "" -i, j = len(s), len(t) -while i > 0 and j > 0: -    if dp[i][j] == dp[i - 1][j]: -        i -= 1 -    elif dp[i][j] == dp[i][j - 1]: -        j -= 1 -    else: -        ans = s[i - 1] + ans -        i -= 1 -        j -= 1 -print(ans) +def LCS(s, t, restore=False): +    dp = [[0 for j in range(len(t) + 1)] for i in range(len(s) + 1)] +    for i in range(len(s)): +        for j in range(len(t)): +            if s[i] == t[j]: +                dp[i + 1][j + 1] = dp[i][j] + 1 +            else: +                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]) +    if restore: +        lcs = [] +        stack = [(len(s), len(t))] +        while stack: +            x, y = stack.pop() +            if dp[x][y] == 0: +                break +            if x - 1 >= 0 and dp[x][y] == dp[x - 1][y]: +                stack.append((x - 1, y)) +            elif y - 1 >= 0 and dp[x][y] == dp[x][y - 1]: +                stack.append((x, y - 1)) +            else: +                lcs.append(s[x - 1]) +                stack.append((x - 1, y - 1)) +        lcs = "".join(lcs)[::-1] +        return dp[-1][-1], lcs +    return dp[-1][-1] + + +S = eval(input()) +T = eval(input()) +print((LCS(S, T, True)[1]))