/// Swift5 -> Swift2.2

extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
extension Array where Element: Comparable {
    // sorted()
    func sorted() -> [Element] {
        return self.sort( { $0 < $1 } )
    }
    // lastIndex(where:)
    func lastIndex(where predicate: (Element) -> Bool) -> Int? {
        for i in (0 ..< self.count).reverse() {
            if predicate(self[i]) {
                return i
            }
        }
        return nil
    }
}
// stride(from:through:by:)
func stride(from start: Int, through end: Int, by stride: Int) -> StrideThrough<Int> {
    return start.stride(through: end, by: stride)
}
// stride(from:to:by)
func stride(from start: Int, to end: Int, by stride: Int) -> StrideTo<Int> {
    return start.stride(to: end, by: stride)
}
extension Range {
    func reversed() -> [Element] {
        return self.reverse()
    }
}

/// end

let s = Array(readLine()!.characters)
let t = Array(readLine()!.characters)

var dp = Array(repeating: Array(repeating: 0, count: t.count + 1), count: s.count + 1)

for i in 0 ..< s.count {
    for j in 0 ..< t.count {
        if s[i] == t[j] {
            dp[i+1][j+1] = dp[i][j] + 1
        } else {
            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])
        }
    }
}

var result = ""
var i = s.count
var j = t.count

while i > 0 && j > 0 {
    if dp[i][j] == dp[i - 1][j - 1] + 1 {
        result = String(s[i - 1]) + result
        i -= 1
        j -= 1
    } else if dp[i][j] == dp[i - 1][j] {
        i -= 1
    } else if dp[i][j] == dp[i][j - 1] {
        j -= 1
    } else {
        fatalError()
    }
}

print(result)
