object Main extends App {

  import scala.io.StdIn._

  val s = '\0' + readLine.trim
  val t = '\0' + readLine.trim
  val maxLength = Array.tabulate(s.length){_ ⇒ Array.tabulate(t.length){_ ⇒ 0}}
  for (i ← 1 until s.length){
    for (j ← 1 until t.length){
      if (s(i) == t(j)){
        maxLength(i)(j) = List(maxLength(i - 1)(j - 1) + 1, maxLength(i)(j - 1), maxLength(i - 1)(j)).max
      }else {
        maxLength(i)(j) = List(maxLength(i - 1)(j), maxLength(i)(j - 1)).max
      }
    }
  }
  println(makeString(maxLength, s))
  def makeString(maxLength: Array[Array[Int]], s: String): String = {
    var string: List[Char] = Nil
    var i = maxLength.length - 1
    var j = maxLength.head.length - 1
    while (i != 0 && j != 0){
      if (maxLength(i)(j) == maxLength(i - 1)(j - 1) + 1){
        string ::= s(i)
        i -= 1
        j -= 1
      } else {
        if (maxLength(i)(j) == maxLength(i - 1)(j)){
          i -= 1
        }else {
          j -= 1
        }
      }
    }
    string.mkString
  }
  implicit class Extend[T](value: T){
    def also(func: T ⇒ Unit): T = {func(value); value}
    def let[A](func: T ⇒ A): A = func(value)
  }
}