require 'pp'
require 'csv'

S = ARGF.gets.strip
T = ARGF.gets.strip

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

def dfs(i, j)
  if Memo[i][j] >= 0
    return Memo[i][j]
  end

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

  if i == S.size-1 && j == T.size-1
    Memo[i][j] = matched
    return matched
  end

  if i == S.size-1
    res = [matched, dfs(i, j+1)].max
    Memo[i][j] = res
    return res
  end

  if j == T.size-1
    res = [matched, dfs(i+1, j)].max
    Memo[i][j] = res
    return matched
  end

  res = [dfs(i+1, j+1)+matched, dfs(i+1, j), dfs(i, j+1)].max
  Memo[i][j] = res
  res
end

def trace
  str = []
  for i in 0...S.size-1
    if Memo[i][0] != Memo[i+1][0]
      str << S[i]
    end
  end

  if Memo.last[0] == 1
    str << S[S.size-1]
  end

  str.join("")
end

dfs(0, 0)
puts trace
