s = eval(input())

t = eval(input())

len_s = len(s)

len_t = len(t)

dp = [[0]*(len_t+1) for _ in range(len_s+1)]

# dp[i][j]はi、j文字目までのs[i],t[j]で、最長の部分列の長さ

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



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

#print(dp)

ans = ""

while len_t > 0 and len_s > 0:

    if dp[len_s][len_t] == dp[len_s-1][len_t]:

        len_s -= 1

    elif dp[len_s][len_t] == dp[len_s][len_t-1]:

        len_t -= 1

    else:

        ans += s[len_s-1]

        len_s -= 1

        len_t -= 1

print((ans[::-1]))
s = eval(input())

t = eval(input())

n_s = len(s)

n_t = len(t)



dp = [[0]*(n_t+1) for _ in range(n_s+1)]

#dp[i][j]はsのi文字目までとtのj文字目までのLCSの長さ



for i in range(n_s+1):

    for j in range(n_t+1):

        if i == 0 or j == 0:

            continue

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

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

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



sna = ""

while n_s > 0 and n_t > 0:

    if dp[n_s][n_t] == dp[n_s-1][n_t]:

        n_s -= 1

    elif dp[n_s][n_t] == dp[n_s][n_t-1]:

        n_t -= 1

    else:

        sna += s[n_s-1]

        n_s -= 1

        n_t -= 1

ans = ""

for i in range(len(sna))[::-1]:

    ans += sna[i]

print(ans)
s = eval(input())
t = eval(input())
len_s = len(s)
len_t = len(t)
dp = [[0] * (len_t + 1) for _ in range(len_s + 1)]
# dp[i][j]はi、j文字目までのs[i],t[j]で、最長の部分列の長さ
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])
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j], dp[i][j + 1])
# print(dp)
ans = ""
while len_t > 0 and len_s > 0:
    if dp[len_s][len_t] == dp[len_s - 1][len_t]:
        len_s -= 1
    elif dp[len_s][len_t] == dp[len_s][len_t - 1]:
        len_t -= 1
    else:
        ans += s[len_s - 1]
        len_s -= 1
        len_t -= 1
print((ans[::-1]))

s = eval(input())
t = eval(input())
n_s = len(s)
n_t = len(t)
dp = [[0] * (n_t + 1) for _ in range(n_s + 1)]
# dp[i][j]はsのi文字目までとtのj文字目までのLCSの長さ
for i in range(n_s + 1):
    for j in range(n_t + 1):
        if i == 0 or j == 0:
            continue
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
        if s[i - 1] == t[j - 1]:
            dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)
sna = ""
while n_s > 0 and n_t > 0:
    if dp[n_s][n_t] == dp[n_s - 1][n_t]:
        n_s -= 1
    elif dp[n_s][n_t] == dp[n_s][n_t - 1]:
        n_t -= 1
    else:
        sna += s[n_s - 1]
        n_s -= 1
        n_t -= 1
ans = ""
for i in range(len(sna))[::-1]:
    ans += sna[i]
print(ans)

-len_s = len(s) -len_t = len(t) -dp = [[0] * (len_t + 1) for _ in range(len_s + 1)] -# dp[i][j]はi、j文字目までのs[i],t[j]で、最長の部分列の長さ -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]) -        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j], dp[i][j + 1]) -# print(dp) +n_s = len(s) +n_t = len(t) +dp = [[0] * (n_t + 1) for _ in range(n_s + 1)] +# dp[i][j]はsのi文字目までとtのj文字目までのLCSの長さ +for i in range(n_s + 1): +    for j in range(n_t + 1): +        if i == 0 or j == 0: +            continue +        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) +        if s[i - 1] == t[j - 1]: +            dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1) +sna = "" +while n_s > 0 and n_t > 0: +    if dp[n_s][n_t] == dp[n_s - 1][n_t]: +        n_s -= 1 +    elif dp[n_s][n_t] == dp[n_s][n_t - 1]: +        n_t -= 1 +    else: +        sna += s[n_s - 1] +        n_s -= 1 +        n_t -= 1 -while len_t > 0 and len_s > 0: -    if dp[len_s][len_t] == dp[len_s - 1][len_t]: -        len_s -= 1 -    elif dp[len_s][len_t] == dp[len_s][len_t - 1]: -        len_t -= 1 -    else: -        ans += s[len_s - 1] -        len_s -= 1 -        len_t -= 1 -print((ans[::-1])) +for i in range(len(sna))[::-1]: +    ans += sna[i] +print(ans)