s = eval(input())

t = eval(input())



S, T = len(s), len(t)

dp = [[0]*(T+1) for _ in range(S+1)]

prev = [[(-1,-1)]*(T+1) for _ in range(S+1)]



for i in range(S):

    for j in range(T): 

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

        p = (i, j-1) if r == dp[i][j-1] else (i-1, j)

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

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

            p = (i-1, j-1) if r == dp[i-1][j-1] + 1 else p

        dp[i][j] = r

        prev[i][j] = p





ans = ''

i, j = S - 1, T - 1

while i >= 0 and j >= 0:

    if prev[i][j] == (i-1, j-1):

        ans += s[i]

    i, j = prev[i][j]



print((ans[::-1]))
def solve(S, T):

    L1 = len(S)

    L2 = len(T)

    dp = [[0]*(L2+1) for i in range(L1+1)]



    for i in range(L1-1, -1, -1):

        for j in range(L2-1, -1, -1):

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

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

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

            dp[i][j] = r



    # dp[0][0] が長さの解



    # ここからは復元処理

    res = []

    i = 0; j = 0

    while i < L1 and j < L2:

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

            res.append(S[i])

            i += 1; j += 1

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

            i += 1

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

            j += 1

    return "".join(res)



S = eval(input())

T = eval(input())

print((solve(S,T)))
s = eval(input())
t = eval(input())
S, T = len(s), len(t)
dp = [[0] * (T + 1) for _ in range(S + 1)]
prev = [[(-1, -1)] * (T + 1) for _ in range(S + 1)]
for i in range(S):
    for j in range(T):
        r = max(dp[i][j - 1], dp[i - 1][j])
        p = (i, j - 1) if r == dp[i][j - 1] else (i - 1, j)
        if s[i] == t[j]:
            r = max(dp[i - 1][j - 1] + 1, r)
            p = (i - 1, j - 1) if r == dp[i - 1][j - 1] + 1 else p
        dp[i][j] = r
        prev[i][j] = p
ans = ""
i, j = S - 1, T - 1
while i >= 0 and j >= 0:
    if prev[i][j] == (i - 1, j - 1):
        ans += s[i]
    i, j = prev[i][j]
print((ans[::-1]))

def solve(S, T):
    L1 = len(S)
    L2 = len(T)
    dp = [[0] * (L2 + 1) for i in range(L1 + 1)]
    for i in range(L1 - 1, -1, -1):
        for j in range(L2 - 1, -1, -1):
            r = max(dp[i + 1][j], dp[i][j + 1])
            if S[i] == T[j]:
                r = max(r, dp[i + 1][j + 1] + 1)
            dp[i][j] = r
    # dp[0][0] が長さの解
    # ここからは復元処理
    res = []
    i = 0
    j = 0
    while i < L1 and j < L2:
        if S[i] == T[j]:
            res.append(S[i])
            i += 1
            j += 1
        elif dp[i][j] == dp[i + 1][j]:
            i += 1
        elif dp[i][j] == dp[i][j + 1]:
            j += 1
    return "".join(res)


S = eval(input())
T = eval(input())
print((solve(S, T)))

-s = eval(input()) -t = eval(input()) -S, T = len(s), len(t) -dp = [[0] * (T + 1) for _ in range(S + 1)] -prev = [[(-1, -1)] * (T + 1) for _ in range(S + 1)] -for i in range(S): -    for j in range(T): -        r = max(dp[i][j - 1], dp[i - 1][j]) -        p = (i, j - 1) if r == dp[i][j - 1] else (i - 1, j) -        if s[i] == t[j]: -            r = max(dp[i - 1][j - 1] + 1, r) -            p = (i - 1, j - 1) if r == dp[i - 1][j - 1] + 1 else p -        dp[i][j] = r -        prev[i][j] = p -ans = "" -i, j = S - 1, T - 1 -while i >= 0 and j >= 0: -    if prev[i][j] == (i - 1, j - 1): -        ans += s[i] -    i, j = prev[i][j] -print((ans[::-1])) +def solve(S, T): +    L1 = len(S) +    L2 = len(T) +    dp = [[0] * (L2 + 1) for i in range(L1 + 1)] +    for i in range(L1 - 1, -1, -1): +        for j in range(L2 - 1, -1, -1): +            r = max(dp[i + 1][j], dp[i][j + 1]) +            if S[i] == T[j]: +                r = max(r, dp[i + 1][j + 1] + 1) +            dp[i][j] = r +    # dp[0][0] が長さの解 +    # ここからは復元処理 +    res = [] +    i = 0 +    j = 0 +    while i < L1 and j < L2: +        if S[i] == T[j]: +            res.append(S[i]) +            i += 1 +            j += 1 +        elif dp[i][j] == dp[i + 1][j]: +            i += 1 +        elif dp[i][j] == dp[i][j + 1]: +            j += 1 +    return "".join(res) + + +S = eval(input()) +T = eval(input()) +print((solve(S, T)))