"""

https://atcoder.jp/contests/dp/tasks/dp_f

"""

from collections import defaultdict

s = eval(input())

t = eval(input())



ls = len(s)

lt = len(t)



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



pre = defaultdict(lambda: defaultdict(tuple))



for i in range(ls):

    for j in range(lt):

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

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

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

        else:

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

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

                pre[i + 1][j + 1] = pre[i + 1][j]

            else:

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

                pre[i + 1][j + 1] = pre[i][j + 1]



# print(dp[ls][lt])



ans = ''

y = ls

x = lt

while pre[y][x]:

    ny, nx = pre[y][x]

    ans = s[ny] + ans

    y = ny

    x = nx



print(ans)

"""

https://atcoder.jp/contests/dp/tasks/dp_f

"""

from collections import defaultdict

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(ls):

    for j in range(lt):

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

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

        else:

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



# print(dp[ls][lt])

N = dp[ls][lt]

y = ls

x = lt

ans = ''

while N:

    if dp[y][x] == dp[y - 1][x]:

        y -= 1

        continue

    if dp[y][x] == dp[y][x - 1]:

        x -= 1

        continue

    else:

        ans = s[y - 1] + ans

        N -= 1

        x -= 1

        y -= 1



print(ans)

"""
https://atcoder.jp/contests/dp/tasks/dp_f
"""
from collections import defaultdict

s = eval(input())
t = eval(input())
ls = len(s)
lt = len(t)
dp = [[0] * (lt + 1) for _ in range(ls + 1)]
pre = defaultdict(lambda: defaultdict(tuple))
for i in range(ls):
    for j in range(lt):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = 1 + dp[i][j]
            pre[i + 1][j + 1] = (i, j)
        else:
            if dp[i + 1][j] >= dp[i][j + 1]:
                dp[i + 1][j + 1] = dp[i + 1][j]
                pre[i + 1][j + 1] = pre[i + 1][j]
            else:
                dp[i + 1][j + 1] = dp[i][j + 1]
                pre[i + 1][j + 1] = pre[i][j + 1]
# print(dp[ls][lt])
ans = ""
y = ls
x = lt
while pre[y][x]:
    ny, nx = pre[y][x]
    ans = s[ny] + ans
    y = ny
    x = nx
print(ans)

"""
https://atcoder.jp/contests/dp/tasks/dp_f
"""
from collections import defaultdict

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(ls):
    for j in range(lt):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = 1 + dp[i][j]
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
# print(dp[ls][lt])
N = dp[ls][lt]
y = ls
x = lt
ans = ""
while N:
    if dp[y][x] == dp[y - 1][x]:
        y -= 1
        continue
    if dp[y][x] == dp[y][x - 1]:
        x -= 1
        continue
    else:
        ans = s[y - 1] + ans
        N -= 1
        x -= 1
        y -= 1
print(ans)

-pre = defaultdict(lambda: defaultdict(tuple)) -            pre[i + 1][j + 1] = (i, j) -            if dp[i + 1][j] >= dp[i][j + 1]: -                dp[i + 1][j + 1] = dp[i + 1][j] -                pre[i + 1][j + 1] = pre[i + 1][j] -            else: -                dp[i + 1][j + 1] = dp[i][j + 1] -                pre[i + 1][j + 1] = pre[i][j + 1] +            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]) -ans = "" +N = dp[ls][lt] -while pre[y][x]: -    ny, nx = pre[y][x] -    ans = s[ny] + ans -    y = ny -    x = nx +ans = "" +while N: +    if dp[y][x] == dp[y - 1][x]: +        y -= 1 +        continue +    if dp[y][x] == dp[y][x - 1]: +        x -= 1 +        continue +    else: +        ans = s[y - 1] + ans +        N -= 1 +        x -= 1 +        y -= 1