s = eval(input())

t = eval(input())

Ls = len(s)

Lt = len(t)



dp = [[0]*(Ls+1) for i in range(Lt+1)]

Lans = 0



for i in range(1,Lt+1):

  for j in range(1,Ls+1):

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

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

    else:

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

    Lans = max(Lans,dp[i][j])

i = Lt

j = Ls

ans = [""]*Lans

count = 0

while Lans > 0:

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

    i -= 1

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

    j -= 1

  else:

    ans[Lans-1] = s[j-1]

    i -= 1

    j -= 1

    Lans -= 1

print(("".join(ans)))
s = eval(input())

t = eval(input())

ls = len(s)

lt = len(t)

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

ans = ""



for i in range(1,lt+1):

    for j in range(1,ls+1):

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

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

        else:

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

i = lt

j = ls

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 = t[i-1] + ans

        i -= 1

        j -= 1



print(ans)
s = eval(input())
t = eval(input())
Ls = len(s)
Lt = len(t)
dp = [[0] * (Ls + 1) for i in range(Lt + 1)]
Lans = 0
for i in range(1, Lt + 1):
    for j in range(1, Ls + 1):
        if s[j - 1] == t[i - 1]:
            dp[i][j] = dp[i - 1][j - 1] + 1
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
        Lans = max(Lans, dp[i][j])
i = Lt
j = Ls
ans = [""] * Lans
count = 0
while Lans > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        ans[Lans - 1] = s[j - 1]
        i -= 1
        j -= 1
        Lans -= 1
print(("".join(ans)))

s = eval(input())
t = eval(input())
ls = len(s)
lt = len(t)
dp = [[0] * (ls + 1) for i in range(lt + 1)]
ans = ""
for i in range(1, lt + 1):
    for j in range(1, ls + 1):
        if s[j - 1] == t[i - 1]:
            dp[i][j] = dp[i - 1][j - 1] + 1
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
i = lt
j = ls
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 = t[i - 1] + ans
        i -= 1
        j -= 1
print(ans)

-Ls = len(s) -Lt = len(t) -dp = [[0] * (Ls + 1) for i in range(Lt + 1)] -Lans = 0 -for i in range(1, Lt + 1): -    for j in range(1, Ls + 1): +ls = len(s) +lt = len(t) +dp = [[0] * (ls + 1) for i in range(lt + 1)] +ans = "" +for i in range(1, lt + 1): +    for j in range(1, ls + 1): -        Lans = max(Lans, dp[i][j]) -i = Lt -j = Ls -ans = [""] * Lans -count = 0 -while Lans > 0: +i = lt +j = ls +while i > 0 and j > 0: -        ans[Lans - 1] = s[j - 1] +        ans = t[i - 1] + ans -        Lans -= 1 -print(("".join(ans))) +print(ans)