import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

fun main() {
  val a = readLine()!!
  val b = readLine()!!

  val n = a.length
  val m = b.length

  val dp = Array<IntArray>(n+1){IntArray(m+1){0}}
  for (i in 0 until n){
    for(j in 0 until m){
      if(a[i] == b[j]){
        dp[i+1][j+1] = 1 + dp[i][j]
      }else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])
    }
  }

  val ans = CharArray(dp[n][m]){'?'}
  var ix = dp[n][m]-1
  var i = n
  var j = m
  while(i > 0 && j > 0){
    if(a[i-1] == b[j-1]){
      ans[ix] = a[i-1]
      i--
      j--
      ix--
      continue
    }

    if(dp[i][j-1] > dp[i-1][j]){
      j--
    }else i--
  }

  println(ans)
}