S = gets.chomp.chars
T = gets.chomp.chars

def max(x, y)
  x > y ? x : y
end

dp = []
dp << Array.new(T.size + 1, 0)

S.size.times do |s|
  T.size.times do |t|
    dp << Array.new(T.size + 1, 0)
    dp[s + 1][t + 1] = dp[s][t] + 1 if S[s] == T[t]
    dp[s + 1][t + 1] = max(dp[s + 1][t + 1], dp[s + 1][t])
    dp[s + 1][t + 1] = max(dp[s + 1][t + 1], dp[s][t + 1])
  end
end

l = dp[S.size][T.size]
s = S.size
t = T.size
a = ''

while l > 0
  case
  when dp[s - 1][t] == l then s -= 1
  when dp[s][t - 1] == l then t -= 1
  else
    a << S[s - 1]
    l -= 1
    s -= 1
    t -= 1
  end
end

print a.reverse
