#import

#import math

#import numpy as np

#= int(input())

#= input()

#= map(int, input().split())

#= [input(), input()]



s = eval(input())

t = eval(input())



sl = len(s)

tl = len(t)



dp = [[0] * (tl + 1) for _ in range(sl + 1)]



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

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

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

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

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



res = ""

i = sl

j = tl  

while i > 0 and j > 0:

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

        i -= 1



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

        j -= 1



    else:

        res = s[i - 1] + res

        i -= 1

        j -= 1



print(res)
#!/usr/bin/env python3



#import

#import math

#import numpy as np

#= int(input())

S = eval(input())

T = eval(input())



ls = len(S)

lt = len(T)



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



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

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

        if S[i - 1] == T[j - 1]:

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

            

        else:

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

            

i = ls

j = lt

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] + ans

        i -= 1

        j -= 1



print(ans)





# import
# import math
# import numpy as np
# = int(input())
# = input()
# = map(int, input().split())
# = [input(), input()]
s = eval(input())
t = eval(input())
sl = len(s)
tl = len(t)
dp = [[0] * (tl + 1) for _ in range(sl + 1)]
for i in range(1, sl + 1):
    for j in range(1, tl + 1):
        if s[i - 1] == t[j - 1]:
            dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)
        dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1])
res = ""
i = sl
j = tl
while i > 0 and j > 0:
    if dp[i - 1][j] == dp[i][j]:
        i -= 1
    elif dp[i][j - 1] == dp[i][j]:
        j -= 1
    else:
        res = s[i - 1] + res
        i -= 1
        j -= 1
print(res)

#!/usr/bin/env python3
# import
# import math
# import numpy as np
# = int(input())
S = eval(input())
T = eval(input())
ls = len(S)
lt = len(T)
dp = [[0] * (lt + 1) for _ in range(ls + 1)]
for i in range(1, ls + 1):
    for j in range(1, lt + 1):
        if S[i - 1] == T[j - 1]:
            dp[i][j] = dp[i - 1][j - 1] + 1
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
i = ls
j = lt
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] + ans
        i -= 1
        j -= 1
print(ans)

+#!/usr/bin/env python3 -# = input() -# = map(int, input().split()) -# = [input(), input()] -s = eval(input()) -t = eval(input()) -sl = len(s) -tl = len(t) -dp = [[0] * (tl + 1) for _ in range(sl + 1)] -for i in range(1, sl + 1): -    for j in range(1, tl + 1): -        if s[i - 1] == t[j - 1]: -            dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1) -        dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1]) -res = "" -i = sl -j = tl +S = eval(input()) +T = eval(input()) +ls = len(S) +lt = len(T) +dp = [[0] * (lt + 1) for _ in range(ls + 1)] +for i in range(1, ls + 1): +    for j in range(1, lt + 1): +        if S[i - 1] == T[j - 1]: +            dp[i][j] = dp[i - 1][j - 1] + 1 +        else: +            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) +i = ls +j = lt +ans = "" -    if dp[i - 1][j] == dp[i][j]: +    if dp[i][j] == dp[i - 1][j]: -    elif dp[i][j - 1] == dp[i][j]: +    elif dp[i][j] == dp[i][j - 1]: -        res = s[i - 1] + res +        ans = S[i - 1] + ans -print(res) +print(ans)