s = eval(input())

t = eval(input())



ls = len(s)

lt = len(t)



dp = [[0 for _ in range(lt + 1)] for _ in range(ls + 1)]

# dp[si][ti] = si文字目までとti文字目までのLCS長



for si in range(ls):

    for ti in range(lt):

        if s[si] == t[ti]:

            dp[si + 1][ti + 1] = max(dp[si + 1][ti + 1], dp[si][ti] + 1)



        dp[si + 1][ti + 1] = max(dp[si + 1][ti + 1], dp[si + 1][ti])

        dp[si + 1][ti + 1] = max(dp[si + 1][ti + 1], dp[si][ti + 1])



ans = ''

si = ls

ti = lt

while si > 0 and ti > 0:

    if dp[si][ti] == dp[si - 1][ti]:

        si -= 1

    elif dp[si][ti] == dp[si][ti - 1]:

        ti -= 1

    else:

        ans = s[si - 1] + ans

        si -= 1

        ti -= 1

print(ans)

s = eval(input())

n = len(s)



t = eval(input())

m = len(t)



dp = tuple([0] * (m + 1) for _ 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 + 1][j], dp[i][j + 1])



rest = dp[n][m]

ans = ''



i = n

j = m

while rest > 0:

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

        ans = s[i - 1] + ans

        rest -= 1

        i -= 1

        j -= 1

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

        i -= 1

    else:

        j -= 1

print(ans)

s = eval(input())
t = eval(input())
ls = len(s)
lt = len(t)
dp = [[0 for _ in range(lt + 1)] for _ in range(ls + 1)]
# dp[si][ti] = si文字目までとti文字目までのLCS長
for si in range(ls):
    for ti in range(lt):
        if s[si] == t[ti]:
            dp[si + 1][ti + 1] = max(dp[si + 1][ti + 1], dp[si][ti] + 1)
        dp[si + 1][ti + 1] = max(dp[si + 1][ti + 1], dp[si + 1][ti])
        dp[si + 1][ti + 1] = max(dp[si + 1][ti + 1], dp[si][ti + 1])
ans = ""
si = ls
ti = lt
while si > 0 and ti > 0:
    if dp[si][ti] == dp[si - 1][ti]:
        si -= 1
    elif dp[si][ti] == dp[si][ti - 1]:
        ti -= 1
    else:
        ans = s[si - 1] + ans
        si -= 1
        ti -= 1
print(ans)

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

+n = len(s) -ls = len(s) -lt = len(t) -dp = [[0 for _ in range(lt + 1)] for _ in range(ls + 1)] -# dp[si][ti] = si文字目までとti文字目までのLCS長 -for si in range(ls): -    for ti in range(lt): -        if s[si] == t[ti]: -            dp[si + 1][ti + 1] = max(dp[si + 1][ti + 1], dp[si][ti] + 1) -        dp[si + 1][ti + 1] = max(dp[si + 1][ti + 1], dp[si + 1][ti]) -        dp[si + 1][ti + 1] = max(dp[si + 1][ti + 1], dp[si][ti + 1]) +m = len(t) +dp = tuple([0] * (m + 1) for _ 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 + 1][j], dp[i][j + 1]) +rest = dp[n][m] -si = ls -ti = lt -while si > 0 and ti > 0: -    if dp[si][ti] == dp[si - 1][ti]: -        si -= 1 -    elif dp[si][ti] == dp[si][ti - 1]: -        ti -= 1 +i = n +j = m +while rest > 0: +    if s[i - 1] == t[j - 1]: +        ans = s[i - 1] + ans +        rest -= 1 +        i -= 1 +        j -= 1 +    elif dp[i][j] == dp[i - 1][j]: +        i -= 1 -        ans = s[si - 1] + ans -        si -= 1 -        ti -= 1 +        j -= 1