# F - LCS

def lcs(S: str, T: str) -> str:

    # dp[i][j] := the maximum length of LCS of S[:i+1] and T[:j+1]

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

    for i, s in enumerate(S):

        for j, t in enumerate(T):

            if s == t:

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

            else:

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



    res = ""

    i, j = len(S) - 1, len(T) - 1

    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

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

            res += S[i]

            i -= 1

            j -= 1

    return res[::-1]  # dp[-1][-1]





def main():

    S, T = open(0).read().split()

    print((lcs(S, T)))





if __name__ == "__main__":

    main()

def get_lcs(S: str, T: str):

    N, M = len(S), len(T)

    dp = [[0] * (M + 1) for _ in range(N + 1)]

    for i, s in enumerate(S):

        for j, t in enumerate(T):

            if s == t:

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

            else:

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



    reversed_lcs = ""

    while N and M:

        if S[N - 1] == T[M - 1]:

            N -= 1

            M -= 1

            reversed_lcs += S[N]

            continue

        if dp[N - 1][M] > dp[N][M - 1]:

            N -= 1

        else:

            M -= 1

    return reversed_lcs[::-1]





def main():

    S, T = open(0).read().split()

    print((get_lcs(S, T)))





if __name__ == "__main__":

    main()

# F - LCS
def lcs(S: str, T: str) -> str:
    # dp[i][j] := the maximum length of LCS of S[:i+1] and T[:j+1]
    dp = [[0] * (len(T) + 1) for _ in range(len(S) + 1)]
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            if s == t:
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)
            else:
                dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1])
    res = ""
    i, j = len(S) - 1, len(T) - 1
    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
        elif dp[i][j] == dp[i - 1][j - 1] + 1:
            res += S[i]
            i -= 1
            j -= 1
    return res[::-1]  # dp[-1][-1]


def main():
    S, T = open(0).read().split()
    print((lcs(S, T)))


if __name__ == "__main__":
    main()

def get_lcs(S: str, T: str):
    N, M = len(S), len(T)
    dp = [[0] * (M + 1) for _ in range(N + 1)]
    for i, s in enumerate(S):
        for j, t in enumerate(T):
            if s == t:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
    reversed_lcs = ""
    while N and M:
        if S[N - 1] == T[M - 1]:
            N -= 1
            M -= 1
            reversed_lcs += S[N]
            continue
        if dp[N - 1][M] > dp[N][M - 1]:
            N -= 1
        else:
            M -= 1
    return reversed_lcs[::-1]


def main():
    S, T = open(0).read().split()
    print((get_lcs(S, T)))


if __name__ == "__main__":
    main()

-# F - LCS -def lcs(S: str, T: str) -> str: -    # dp[i][j] := the maximum length of LCS of S[:i+1] and T[:j+1] -    dp = [[0] * (len(T) + 1) for _ in range(len(S) + 1)] +def get_lcs(S: str, T: str): +    N, M = len(S), len(T) +    dp = [[0] * (M + 1) for _ in range(N + 1)] -                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1) +                dp[i + 1][j + 1] = dp[i][j] + 1 -                dp[i][j] = max(dp[i][j], dp[i - 1][j], dp[i][j - 1]) -    res = "" -    i, j = len(S) - 1, len(T) - 1 -    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 -        elif dp[i][j] == dp[i - 1][j - 1] + 1: -            res += S[i] -            i -= 1 -            j -= 1 -    return res[::-1]  # dp[-1][-1] +                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]) +    reversed_lcs = "" +    while N and M: +        if S[N - 1] == T[M - 1]: +            N -= 1 +            M -= 1 +            reversed_lcs += S[N] +            continue +        if dp[N - 1][M] > dp[N][M - 1]: +            N -= 1 +        else: +            M -= 1 +    return reversed_lcs[::-1] -    print((lcs(S, T))) +    print((get_lcs(S, T)))