'use strict'
const lines = require('fs').readFileSync(0, 'utf8').split('\n')
const s = lines[0]
const t = lines[1]
let dp = []
for(var i=0;i<=s.length;i++){
  dp.push(Array(t.length+1).fill(""));
}

for (let i=1;i <= s.length;i++) {
  for (let j=1;j <= t.length;j++) {
    if (s.charAt(i-1) == t.charAt(j-1)) {
      const newStr = dp[i-1][j-1] + s.charAt(i-1)
      if (newStr.length > dp[i-1][j].length && newStr.length > dp[i][j-1].length) {
        dp[i][j] = newStr
      } else if (dp[i-1][j].length > dp[i][j-1].length) {
        dp[i][j] = dp[i-1][j]
      } else {
        dp[i][j] = dp[i][j-1]
      }
    } else {
      if (dp[i-1][j].length > dp[i][j-1].length) {
        dp[i][j] = dp[i-1][j]
      } else {
        dp[i][j] = dp[i][j-1]
      }
    }
  }
}
console.log(dp[s.length][t.length])