object Main extends App {
  val s = io.StdIn.readLine()
  val t = io.StdIn.readLine()
  val (m, n) = (s.length, t.length)
  val dp = Array.ofDim[Int](m+1, n+1)

  for (i <- 0 until m)
    for (j <- 0 until n) {
      if (s(i) == t(j) && dp(i+1)(j+1) < dp(i)(j) + 1) dp(i+1)(j+1) = dp(i)(j) + 1
      if (dp(i+1)(j+1) < dp(i+1)(j)) dp(i+1)(j+1) = dp(i+1)(j)
      if (dp(i+1)(j+1) < dp(i)(j+1)) dp(i+1)(j+1) = dp(i)(j+1)
    }

  var (i, j) = (m, n)
  val buf = StringBuilder.newBuilder
  while (i > 0 && j > 0) {
    if (dp(i)(j) == dp(i)(j-1)) {j -= 1}
    else if (dp(i)(j) == dp(i-1)(j)) {i -= 1}
    else {i-= 1; j -= 1; buf += s(i)}
  }

  println(buf.reverse)
}