import java.util.*
import kotlin.math.*

fun main() {
    val s = readString()
    val t = readString()

    val dp = List(s.length + 1) { MutableList(t.length + 1) { 0 } }

    for (i in s.indices) {
        for (j in t.indices) {
            dp[i + 1][j + 1] = if (s[i] == t[j]) {
                dp[i][j] + 1
            } else {
                max(dp[i][j + 1], dp[i + 1][j])
            }
        }
    }

    var len = dp[s.length][t.length]
    val ans = CharArray(dp[s.length][t.length])
    var i = s.length
    var j = t.length
    while (i > 0 && j > 0) {
        when {
            dp[i][j] == dp[i - 1][j] -> i--
            dp[i][j] == dp[i][j - 1] -> j--
            else -> {
                ans[len - 1] = s[i - 1]
                i--
                j--
                len--
            }
        }
    }
    println(ans)
}


fun readString() = readLine()!!