'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function getArray(str) {
    return str.split(' ').map(x => Number(x));
}

function getInt(str) {
    return Number(str);
}

function getStrArray(str) {
    return str.split(' ').map(x => x);
}

function create2DArray(row, col, filler = 0) {
    return Array(row)
        .fill(filler)
        .map(() => Array(col).fill(filler));
}
// ---------------------------------------



function main() {
    let s1 = readline();
    let s2 = readline();  
    let l1 = s1.length;
    let l2 = s2.length;
    
    let dp = create2DArray(l1+1, l2+1, 0);

    for(let i=1; i<= s1.length; i++) {
        for (let j=1; j <= s2.length; j++) {
            if(s1[i-1] === s2[j-1]) {
                dp[i][j] = 1 + dp[i-1][j-1];
            } else {
                dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
            }
        }    
    }

    let s  = '';
    while(l1 > 0 && l2 >0) {
        if (s1[l1 - 1] === s2[l2-1]) {
            s = s1[l1-1]+s;
            l1--;
            l2--;
        } else {
            if(dp[l1 - 1][l2] > dp[l1][l2 - 1]) {
                l1--;
            } else {
                l2--;
            }
        }
    }
    console.log(s);
}