def main():

  import numpy as np



  s = np.array(list(eval(input())), np.str)

  sl = len(s)

  t = np.array(list(eval(input())), np.str)

  tl = len(t)

  equal = (s[:, None] == t[None, :])



  dp = [np.zeros(tl + 1, np.int32)]

  for i in range(sl):

    tmp = dp[-1].copy()

    np.maximum(tmp[1:], tmp[:-1] + equal[i], out=tmp[1:])

    np.maximum.accumulate(tmp, out=tmp)

    dp.append(tmp)



  answer = ''

  while sl > 0 and tl > 0:

    if s[sl - 1] == t[tl - 1]:

      sl -= 1

      tl -= 1

      answer += s[sl]

      continue



    if dp[sl - 1][tl] > dp[sl][tl - 1]:

      sl -= 1

    else:

      tl -= 1



  print((answer[::-1]))



if __name__ == '__main__':

  main()
s = eval(input())

t = eval(input())

n = len(s)

m = len(t)

dp = [[0 for j in range(1 + m)] for i in range(1 + n)]

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

    for j in range(1, m + 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])

res = ""

i, j = n, m

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:

        res = s[i - 1] + res

        i -= 1

        j -= 1

print(res)
def main():
    import numpy as np

    s = np.array(list(eval(input())), np.str)
    sl = len(s)
    t = np.array(list(eval(input())), np.str)
    tl = len(t)
    equal = s[:, None] == t[None, :]
    dp = [np.zeros(tl + 1, np.int32)]
    for i in range(sl):
        tmp = dp[-1].copy()
        np.maximum(tmp[1:], tmp[:-1] + equal[i], out=tmp[1:])
        np.maximum.accumulate(tmp, out=tmp)
        dp.append(tmp)
    answer = ""
    while sl > 0 and tl > 0:
        if s[sl - 1] == t[tl - 1]:
            sl -= 1
            tl -= 1
            answer += s[sl]
            continue
        if dp[sl - 1][tl] > dp[sl][tl - 1]:
            sl -= 1
        else:
            tl -= 1
    print((answer[::-1]))


if __name__ == "__main__":
    main()

s = eval(input())
t = eval(input())
n = len(s)
m = len(t)
dp = [[0 for j in range(1 + m)] for i in range(1 + n)]
for i in range(1, n + 1):
    for j in range(1, m + 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])
res = ""
i, j = n, m
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:
        res = s[i - 1] + res
        i -= 1
        j -= 1
print(res)

-def main(): -    import numpy as np - -    s = np.array(list(eval(input())), np.str) -    sl = len(s) -    t = np.array(list(eval(input())), np.str) -    tl = len(t) -    equal = s[:, None] == t[None, :] -    dp = [np.zeros(tl + 1, np.int32)] -    for i in range(sl): -        tmp = dp[-1].copy() -        np.maximum(tmp[1:], tmp[:-1] + equal[i], out=tmp[1:]) -        np.maximum.accumulate(tmp, out=tmp) -        dp.append(tmp) -    answer = "" -    while sl > 0 and tl > 0: -        if s[sl - 1] == t[tl - 1]: -            sl -= 1 -            tl -= 1 -            answer += s[sl] -            continue -        if dp[sl - 1][tl] > dp[sl][tl - 1]: -            sl -= 1 +s = eval(input()) +t = eval(input()) +n = len(s) +m = len(t) +dp = [[0 for j in range(1 + m)] for i in range(1 + n)] +for i in range(1, n + 1): +    for j in range(1, m + 1): +        if s[i - 1] == t[j - 1]: +            dp[i][j] = dp[i - 1][j - 1] + 1 -            tl -= 1 -    print((answer[::-1])) - - -if __name__ == "__main__": -    main() +            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) +res = "" +i, j = n, m +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: +        res = s[i - 1] + res +        i -= 1 +        j -= 1 +print(res)