S = gets.chomp.codepoints
T = gets.chomp.codepoints
s_size = S.size
t_size = T.size

dp = Array.new(S.size + 1) { Array.new(T.size + 1, 0) }

def max a,b,c
  ab = a > b ? a : b
  return ab > c ? ab : c
end

S.size.times do |s0|
  s1 = s0 + 1

  t_size.times do |t0|
    t1 = t0 + 1
    if S[s0] == T[t0]
      dp[s1][t1] = dp[s0][t0] + 1
    else
      dp[s1][t1] = max(dp[s1][t1],dp[s1][t0], dp[s0][t1])
    end
  end
end

i = dp[S.size][T.size]
s = S.size
t = T.size
a = []

while i > 0
  case
  when dp[s - 1][t] == i then s -= 1
  when dp[s][t - 1] == i then t -= 1
  else
    a.unshift(S[s - 1])
    i -= 1
    s -= 1
    t -= 1
  end
end

print a.pack('U*')