import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let s = Array(readLine()!)
    let t = Array(readLine()!)

    let sn = s.count
    let tn = t.count

    var dp = (0...sn).map { i in (0...tn).map { j in 0 }}

    for i in 0..<sn {
        for j in 0..<tn {
            if s[i] == t[j] {
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
            }
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])
        }
    }

    var ans = ""
    var (i, j) = (sn, tn)
    while i > 0 && j > 0 {
        if dp[i][j] == dp[i-1][j] {
            i -= 1
        } else if dp[i][j] == dp[i][j-1] {
            j -= 1
        } else {
            ans.append(s[i-1])
            i -= 1
            j -= 1
        }
    }

    print(String(ans.reversed()))

}


main()