// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

namespace pcon {

int run(istream& in, ostream& out) {
    string s,t;
    in >> s >> t;
    vector<vector<ll>> dp(s.size(), vector<ll>(t.size(), 0));
    vector<vector<pair<ll,ll>>> prev(s.size(), vector<pair<ll,ll>>(t.size(), {-2,-2}));

    REP(i, s.size()) {
        REP(j, t.size()) {
            if (i == 0) {
                REP(k, j+1) {
                    if (t[k] == s[0]) {
                        dp[0][j] = 1;
                        prev[0][j] = make_pair(-3, -3);
                        break;
                    }
                }
            } else {
                if (j == 0) {
                    REP(k, i+1) {
                        if (s[k] == t[0]) {
                            dp[i][0] = 1;
                            prev[i][0] = make_pair(-3, -3);
                            break;
                        }
                    }
                } else {
                    if (s[i] == t[j]) {
                        dp[i][j] = dp[i-1][j-1] + 1;
                        prev[i][j] = make_pair(i-1, j-1);
                    } else {
                        if (dp[i][j-1] < dp[i-1][j]) {
                            dp[i][j] = dp[i-1][j];
                            prev[i][j] = make_pair(i-1, j);
                        } else {
                            dp[i][j] = dp[i][j-1];
                            prev[i][j] = make_pair(i, j-1);
                        }
                    }
                }
            }
        }
    }
    ll maxI{}, maxJ{}, maxLen = 0;
    REP(i, s.size()) {
        REP(j, t.size()) {
            if (dp[i][j] > maxLen) {
                maxI = i;
                maxJ = j;
                maxLen = dp[i][j];
            }
        }
    }
    string ret(maxLen, 0);
    while(true) {
        auto p = prev[maxI][maxJ];
        if (p.first == maxI - 1 && p.second == maxJ -1) {
            ret[maxLen-1] = s[maxI];
            --maxLen;
        }
        if (p.first == - 3 && p.second == -3) {
            ret[0] = maxI == 0 ? s[0] : t[0];
            break;
        }
        if (p.first == - 2 && p.second == -2) {
            break;
        }
        maxI = p.first;
        maxJ = p.second;
    }

    out << ret << endl;
//    debug(ret);
    return 0;
}

int run2(istream& in, ostream& out) {
    ll N, M, R;
    in >> N >> M >> R;
    vector<ll> r{};
    REP(i, R) {
        ll x;
        in >> x;
        r.emplace_back(x);
    }
    vector<tuple<ll,ll,ll>> v{};
    REP(i, M) {
        ll a,b,c;
        in >> a >> b >> c;
        v.emplace_back(make_tuple(a,b,c));
    }

    ll ans = 0;

    // solution here

    out << ans << endl;
//    debug(ans);
    return 0;
}

} // namespace

int main() {
    return pcon::run(cin, cout);
}


Measured memory_bytes: 211456