fun main(args: Array<String>) {
    val s = readLine()!!
    val t = readLine()!!
    val dp = Array(s.length + 1) { IntArray(t.length+1) }
    for (x in 1 .. s.length) {
        for (y in 1 .. t.length) {
            if (s[x-1] == t[y-1]) {
                dp[x][y] = dp[x-1][y-1] + 1
            } else {
                dp[x][y] = Math.max(dp[x][y-1], dp[x-1][y])
            }
        }
    }
    var x=s.length
    var y = t.length
    var ans = ""
    while(x!= 0 && y != 0) {
        when {
            dp[x][y] == dp[x-1][y] -> x--
            dp[x][y] == dp[x][y-1] -> y--
            dp[x][y] == dp[x-1][y-1] + 1 -> {
                ans = s[x-1] + ans
                x--
                y--
            }
        }
    }
    println(ans)
}