s = eval(input())

t = eval(input())



len_s = len(s)

len_t = len(t)

INF = float('inf')



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



dp[0][0] = 0



for i in range(len_s+1):

    for j in range(len_t+1):

        if i+1 <= len_s and j <= len_t:

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

        if i <= len_s and j+1 <= len_t:

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

        if i+1 <= len_s and j+1 <= len_t and s[i] == t[j]:

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



i = len_s

j = len_t

ans = ""

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]

        i -= 1

        j -= 1



print((ans[::-1]))

s = eval(input())

t = eval(input())



len_s = len(s)

len_t = len(t)



dp = [[0] * 3010 for _ in range(3010)]



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 + 1][j + 1], dp[i][j] + 1)

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

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



i = len_s

j = len_t

res = ""

while i > 0 and j > 0:

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

        j -= 1

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

        i -= 1

    else:

        res += s[i-1]

        i -= 1

        j -= 1



print((res[::-1]))

s = eval(input())
t = eval(input())
len_s = len(s)
len_t = len(t)
INF = float("inf")
dp = [[-INF] * (len_t + 1) for _ in range(len_s + 1)]
dp[0][0] = 0
for i in range(len_s + 1):
    for j in range(len_t + 1):
        if i + 1 <= len_s and j <= len_t:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
        if i <= len_s and j + 1 <= len_t:
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j])
        if i + 1 <= len_s and j + 1 <= len_t and s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
i = len_s
j = len_t
ans = ""
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]
        i -= 1
        j -= 1
print((ans[::-1]))

s = eval(input())
t = eval(input())
len_s = len(s)
len_t = len(t)
dp = [[0] * 3010 for _ in range(3010)]
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 + 1][j + 1], dp[i][j] + 1)
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])
i = len_s
j = len_t
res = ""
while i > 0 and j > 0:
    if dp[i][j] == dp[i][j - 1]:
        j -= 1
    elif dp[i][j] == dp[i - 1][j]:
        i -= 1
    else:
        res += s[i - 1]
        i -= 1
        j -= 1
print((res[::-1]))

-INF = float("inf") -dp = [[-INF] * (len_t + 1) for _ in range(len_s + 1)] -dp[0][0] = 0 -for i in range(len_s + 1): -    for j in range(len_t + 1): -        if i + 1 <= len_s and j <= len_t: -            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) -        if i <= len_s and j + 1 <= len_t: -            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]) -        if i + 1 <= len_s and j + 1 <= len_t and s[i] == t[j]: +dp = [[0] * 3010 for _ in range(3010)] +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 + 1][j + 1], dp[i + 1][j]) +        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]) -ans = "" +res = "" -    if dp[i][j] == dp[i - 1][j]: +    if dp[i][j] == dp[i][j - 1]: +        j -= 1 +    elif dp[i][j] == dp[i - 1][j]: -    elif dp[i][j] == dp[i][j - 1]: -        j -= 1 -        ans += s[i - 1] +        res += s[i - 1] -print((ans[::-1])) +print((res[::-1]))