#!/usr/bin/env ruby

# opt(i, j) = max{ 1+opt(i-1, j-1), opt(i-1, j), opt(i, j-1) }
s = STDIN.readline.strip
t = STDIN.readline.strip

def opt(s, t, i, j, m, p)
  return 0 if i < 0 or j < 0
  return m[i][j] if m[i][j]
  if s[i] == t[j]
    with = 1 + opt(s, t, i-1, j-1, m, p)
    without_1 = opt(s, t, i-1, j, m, p)
    without_2 = opt(s, t, i, j-1, m, p)
    max_i = [with, without_1, without_2].each_with_index.max
    m[i][j] = max_i[0]
    p[i][j] = [[i-1, j-1], [i-1, j], [i, j-1]][max_i[1]]
    # puts "opt(#{s}, #{t}, #{i}, #{j}, m, p) #{s[i]}, #{t[j]}, max_i:#{max_i} "
    # puts "with:#{with}, without_1:#{without_1}, without_2:#{without_2}, m[#{i}][#{j}]:#{m[i][j]}"
  else
    without_1 = opt(s, t, i-1, j, m, p)
    without_2 = opt(s, t, i, j-1, m, p)
    max_i = [without_1, without_2].each_with_index.max
    m[i][j] = max_i[0]
    p[i][j] = [[i-1, j], [i, j-1]][max_i[1]]
  end
  m[i][j]
end

m = Array.new(s.length){[]}
p = Array.new(s.length){Array.new(t.length){''}}
opt(s, t, s.length-1, t.length-1, m, p)
lp = ''
i = s.length-1
j = t.length-1
while i >= 0 and j >= 0 do
  pi, pj = p[i][j]
  # break if pi < 0 or pj < 0
  mpij = (pi < 0 or pj < 0) ? 0 : m[pi][pj]
  lp +=  s[i] if m[i][j] != mpij
  # puts "lp:#{lp}, s:#{s}, m[#{i}][#{j}]:m[i][j], mpij:#{mpij} "
  # puts "[#{i}, #{j}] → [#{pi}, #{pj}] #{m[i][j]} #{m[pi][pj]}"
  i, j = p[i][j]
end
# puts "m:#{m}"
# puts "p:#{p}"
puts lp.reverse
# puts m[s.length-1][t.length-1]
