require 'pp'

S = ARGF.gets
T = ARGF.gets

Memo = Array.new(S.size+1) do Array.new(T.size+1, nil) end

def dfs(i, j)
  if !Memo[i][j].nil?
    return Memo[i][j].clone
  end

  matched = S[i] == T[j] ? [S[i], 1] : ["", 0]

  if i == S.size-1
    return matched
  end
  if j == T.size-1
    return matched
  end

  ls = [dfs(i+1, j+1), dfs(i+1, j), dfs(i, j+1)] 
  
  if S[i] == T[j]
    a = ls[0]
    a[0] = S[i] + a[0]
    a[1] = a[1] + 1
  end

  res = ls.max_by(&:last)
  Memo[i][j] = res
  res
end

puts dfs(0, 0)[0]
