import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto S = readln.chomp;
    auto T = readln.chomp;

    auto N = S.length.to!int;
    auto M = T.length.to!int;

    auto next = new int[][](M, 26);
    foreach (i; 0..M) fill(next[i], 1<<29);

    foreach (i; 0..M) {
        foreach_reverse (j; i..M) {
            next[i][T[j]-'a'] = j;
        }
    }

    auto dp = new int[][](N+1, M+1);
    auto prevc = new dchar[][](N+1, M+1);
    auto previ = new Tuple!(int, int)[][](N+1, M+1);
    foreach (i; 0..N+1) fill(previ[i], tuple(-1, -1));

    foreach (i; 0..N) {
        foreach (j; 0..M) {
            {
                int nx = j;
                int nv = dp[i][j];
                if (nv > dp[i+1][nx]) {
                    dp[i+1][nx] = nv;
                    prevc[i+1][nx] = prevc[i][j];
                    previ[i+1][nx] = previ[i][j];
                }
            }
            if (next[j][S[i]-'a'] != 1<<29) {
                int nx = next[j][S[i]-'a'] + 1;
                int nv = dp[i][j] + 1;

                if (nv > dp[i+1][nx]) {
                    dp[i+1][nx] = nv;
                    prevc[i+1][nx] = S[i];
                    previ[i+1][nx] = tuple(i, j);
                }
            }
        }
    }

    int mi = 0;
    int mj = 0;
    int ms = 0;
    foreach (i; 0..N+1) {
        foreach (j; 0..M+1) {
            if (dp[i][j] > ms) {
                ms = dp[i][j];
                mi = i;
                mj = j;
            }
        }
    }

    dchar[] ans;
    while (previ[mi][mj][0] != -1) {
        ans ~= prevc[mi][mj];
        auto t = previ[mi][mj];
        mi = t[0];
        mj = t[1];
    }
    ans.reverse;

    ans.writeln;
}
