object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val S = sc.nextLine()
    val T = sc.nextLine()

    val dp = Array.fill(S.length+1, T.length+1, 3)(0)
    dp(0)(0)(0) = 0
    dp(0)(0)(1) = -1
    dp(0)(0)(2) = -1
    var i = 0
    while (i < S.length) {
      var j = 0
      while (j < T.length) {
        if (S(i) == T(j)) {
          if ((dp(i)(j)(0) + 1) > dp(i + 1)(j + 1)(0)) {
            dp(i + 1)(j + 1)(0) = dp(i)(j)(0) + 1
            dp(i + 1)(j + 1)(1) = i
            dp(i + 1)(j + 1)(2) = j
          }
        }
        if (dp(i+1)(j)(0) > dp(i + 1)(j + 1)(0)) {
          dp(i + 1)(j + 1)(0) = dp(i + 1)(j)(0)
          dp(i + 1)(j + 1)(1) = i + 1
          dp(i + 1)(j + 1)(2) = j
        }
        if (dp(i)(j+1)(0) > dp(i + 1)(j + 1)(0)) {
          dp(i + 1)(j + 1)(0) = dp(i)(j + 1)(0)
          dp(i + 1)(j + 1)(1) = i
          dp(i + 1)(j + 1)(2) = j + 1
        }
        j += 1
      }
      i += 1
    }

    i = dp(S.length)(T.length)(1)
    var j = dp(S.length)(T.length)(2)
    var bldr = new StringBuilder
    while (i >= 0 || j >= 0) {
      if (S(i) == T(j))
        bldr.append(S(i))
      val _i = dp(i)(j)(1)
      val _j = dp(i)(j)(2)
      i = _i
      j = _j
    }
    println(bldr.result().reverse)
  }

}
