s=eval(input())

t=eval(input())



dp=[[0]*(len(t)+1) for _ in range(len(s)+1)]

ans=[[(-1,-1) for _ in range(len(t)+1)] for _ in range(len(s)+1)]



for i,c in enumerate(s):

    for j,d in enumerate(t):

        if c==d:

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

            ans[i+1][j+1]=(i,j)

        else:

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

            ans[i+1][j+1]=ans[i][j+1] if dp[i+1][j+1]==dp[i][j+1] else ans[i+1][j]



i=len(s)

j=len(t)

ss=['']*dp[i][j]

l=dp[i][j]-1

while i>0 and j>0:

    i,j=ans[i][j]

    if i>-1:

        ss[l]=s[i]

        l-=1



print((''.join(ss)))

s=eval(input())

t=eval(input())



m=len(s)

n=len(t)



dp=[[0]*(n+1) for _ in range(m+1)]

trans=[[(-1,-1)]*(n+1) for _ in range(m+1)]



for i in range(m):

    for j in range(n):

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

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

            trans[i+1][j+1]=(i,j)

        else:

            if dp[i][j+1]>dp[i+1][j]:

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

                trans[i+1][j+1]=(i,j+1)

            else:

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

                trans[i+1][j+1]=(i+1,j)



ans=''



i=m

j=n

while i>0 and j>0:

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

        ans=str(s[i-1])+ans

    i,j=trans[i][j]



print(ans)
s = eval(input())
t = eval(input())
dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
ans = [[(-1, -1) for _ in range(len(t) + 1)] for _ in range(len(s) + 1)]
for i, c in enumerate(s):
    for j, d in enumerate(t):
        if c == d:
            dp[i + 1][j + 1] = dp[i][j] + 1
            ans[i + 1][j + 1] = (i, j)
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
            ans[i + 1][j + 1] = (
                ans[i][j + 1] if dp[i + 1][j + 1] == dp[i][j + 1] else ans[i + 1][j]
            )
i = len(s)
j = len(t)
ss = [""] * dp[i][j]
l = dp[i][j] - 1
while i > 0 and j > 0:
    i, j = ans[i][j]
    if i > -1:
        ss[l] = s[i]
        l -= 1
print(("".join(ss)))

s = eval(input())
t = eval(input())
m = len(s)
n = len(t)
dp = [[0] * (n + 1) for _ in range(m + 1)]
trans = [[(-1, -1)] * (n + 1) for _ in range(m + 1)]
for i in range(m):
    for j in range(n):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
            trans[i + 1][j + 1] = (i, j)
        else:
            if dp[i][j + 1] > dp[i + 1][j]:
                dp[i + 1][j + 1] = dp[i][j + 1]
                trans[i + 1][j + 1] = (i, j + 1)
            else:
                dp[i + 1][j + 1] = dp[i + 1][j]
                trans[i + 1][j + 1] = (i + 1, j)
ans = ""
i = m
j = n
while i > 0 and j > 0:
    if s[i - 1] == t[j - 1]:
        ans = str(s[i - 1]) + ans
    i, j = trans[i][j]
print(ans)

-dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)] -ans = [[(-1, -1) for _ in range(len(t) + 1)] for _ in range(len(s) + 1)] -for i, c in enumerate(s): -    for j, d in enumerate(t): -        if c == d: +m = len(s) +n = len(t) +dp = [[0] * (n + 1) for _ in range(m + 1)] +trans = [[(-1, -1)] * (n + 1) for _ in range(m + 1)] +for i in range(m): +    for j in range(n): +        if s[i] == t[j]: -            ans[i + 1][j + 1] = (i, j) +            trans[i + 1][j + 1] = (i, j) -            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]) -            ans[i + 1][j + 1] = ( -                ans[i][j + 1] if dp[i + 1][j + 1] == dp[i][j + 1] else ans[i + 1][j] -            ) -i = len(s) -j = len(t) -ss = [""] * dp[i][j] -l = dp[i][j] - 1 +            if dp[i][j + 1] > dp[i + 1][j]: +                dp[i + 1][j + 1] = dp[i][j + 1] +                trans[i + 1][j + 1] = (i, j + 1) +            else: +                dp[i + 1][j + 1] = dp[i + 1][j] +                trans[i + 1][j + 1] = (i + 1, j) +ans = "" +i = m +j = n -    i, j = ans[i][j] -    if i > -1: -        ss[l] = s[i] -        l -= 1 -print(("".join(ss))) +    if s[i - 1] == t[j - 1]: +        ans = str(s[i - 1]) + ans +    i, j = trans[i][j] +print(ans)