S = gets.chomp
T = gets.chomp

S_CODES = S.codepoints
T_CODES = T.codepoints

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

S_SIZE.times do |s|
  dp_cur = dp[s]
  dp_next = dp[s+1]
  T_SIZE.times do |t|
    if S_CODES[s] == T_CODES[t]
      dp_next[t+1] = dp_cur[t] + 1
    else
      dp_next[t+1] = dp_cur[t+1]
      dp_next[t+1] = dp_next[t] if dp_next[t+1] < dp_next[t]
    end
  end
end

lcs = ''
s = S_SIZE
t = T_SIZE
while s > 0 && t > 0
  if dp[s][t] == dp[s-1][t]
    s -= 1
  elsif dp[s][t] == dp[s][t-1]
    t -= 1
  else
    lcs << S[s-1]
    s -= 1
    t -= 1
  end
end

puts lcs.reverse