let S = Array(readLine()!)
let T = Array(readLine()!)

var dp: [[Int]] = .init(repeating: .init(repeating: 0, count: S.count + 1), count: T.count + 1)


for i in 1...T.count {
  for j in 1...S.count {
    if T[i-1] == S[j-1] {
      dp[i][j] = dp[i-1][j-1] + 1
    } else {
      dp[i][j] = max(dp[i][j-1], dp[i-1][j])
    }
  }
}
var len = dp[T.count][S.count]

var ans: [String] = .init(repeating: "", count: len)

var i = T.count
var j = S.count

while len > 0 {
  if T[i-1] == S[j-1] {
    ans[len - 1] = String(T[i-1])
    i -= 1
    j -= 1
    len -= 1
  } else if dp[i-1][j] > dp[i][j - 1] {
    i -= 1
  } else {
    j -= 1
  }
}

print(ans.joined())