#include <bits/stdc++.h>
using namespace std;
// #define LOCAL // 提出時はコメントアウト

typedef long long ll;
const double EPS = 1e-9;
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;

template<typename T, typename U>
using mapv = map<T,vector<U>>;

#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define contains(S,x) find(ALL(S),x) != S.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> vector<vector<T>> double_arr(ll n,ll m,T init) { return vector<vector<T>>(n,vector<T>(m,init)); }

///// For Debug

#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#define DEBUG_

#ifndef LOCAL
#undef DEBUG_
#endif

#ifdef DEBUG_

#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)

#endif

//////////

int main() {
    #ifdef LOCAL
    ifstream in("../../Atcoder/input.txt");
    cin.rdbuf(in.rdbuf());
    #endif

    string S,T;
    cin>>S>>T;

    ll N = S.length(), M = T.length();
    auto dp = double_arr(N+10,M+10,0LL);
    ll lcs = 0;
    rep(i,N) {
        rep(j,M) {
            if (S[i]==T[j]) chmax(dp[i+1][j+1],dp[i][j] + 1);
            chmax(dp[i+1][j+1],dp[i][j+1]);
            chmax(dp[i+1][j+1],dp[i+1][j]);

            chmax(lcs,dp[i+1][j+1]);
        }
    }

    map<ll,vector<pair<ll,ll>>> memo;
    rep(i,N+1) {
        rep(j,M+1) {
            memo[dp[i][j]].push_back({i-1,j-1});
        }
    }


    ll cs = lcs;
    ll n = N+10;
    ll m = M+10;
    vector<char> ans;
    while (cs > 0) {
        for (auto &v : memo[cs]) {
            auto &[i,j] = v;
            if (i < n && j < m) {
                ans.push_back(S[i]);
                n = i; m = j;
                break;
            }
        }
        cs--;
    }

    dump(ans);

    string a = "";
    rep(i,ans.size()) {
        ll j = ans.size()-i-1;  
        a.push_back(ans[j]);
    }


    cout << a << endl;


    return 0;
}


Measured memory_bytes: 336336