fun main(args: Array<String>) {
    val s = readLine()!!
    val t = readLine()!!

    val dp = Array(s.length + 1) { IntArray(t.length + 1) { 0 } }

    for (i in 0 until s.length) {
        for (j in 0 until t.length) {
            if (s[i] == t[j]) dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j] + 1)
            dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i + 1][j])
            dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j + 1])
        }
    }

    var res = ""
    var i = s.length
    var j = t.length
    while (i > 0 && j > 0) {

        if (dp[i][j] == dp[i - 1][j]) {
            i--
            continue
        }

        if (dp[i][j] == dp[i][j - 1]) {
            j--
            continue
        }

        res = s[i - 1] + res
        i--
        j--
    }

    println(res)
}
