#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

//string dp[3001][3001];
//int main(void){
//    cin.tie(0);
//    ios::sync_with_stdio(false);
//    string s,t;
//    cin>>s>>t;
//    REP(i,3001)REP(j,3001)dp[i][j]="";
//
//    REP(i,s.size()){
//        REP(j,t.size()){
//            LL dpi = i+1;
//            LL dpj = j+1;
//            if(s[i] == t[j]){
//                dp[dpi][dpj] = dp[dpi-1][dpj-1] + s[i];
//            }
//            else {
//                if(dp[dpi-1][dpj].size() >= dp[dpi][dpj-1].size()){
//                    dp[dpi][dpj] = dp[dpi-1][dpj];
//                }
//                else {
//                    dp[dpi][dpj] = dp[dpi][dpj-1];
//                }
//            }
//        }
//    }
//    PUTS(dp[s.size()][t.size()]);
//}

LL dp[3001][3001][3] = {{{0}}};
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;

    REP(i,s.size()){
        REP(j,t.size()){
            LL dpi = i+1;
            LL dpj = j+1;
            if(s[i] == t[j]){
                dp[dpi][dpj][0] = dp[dpi-1][dpj-1][0] + 1;
                dp[dpi][dpj][1] = dpi-1;
                dp[dpi][dpj][2] = dpj-1;
            }
            else {
                if(dp[dpi-1][dpj][0] >= dp[dpi][dpj-1][0]){
                    dp[dpi][dpj][0] = dp[dpi-1][dpj][0];
                    dp[dpi][dpj][1] = dpi-1;
                    dp[dpi][dpj][2] = dpj;
                }
                else {
                    dp[dpi][dpj][0] = dp[dpi][dpj-1][0];
                    dp[dpi][dpj][1] = dpi;
                    dp[dpi][dpj][2] = dpj-1;
                }
            }
        }
    }

    string ans = "";
    LL i = s.size();
    LL j = t.size();
    UNTIL(i == 0 || j == 0){
        LL next_i = dp[i][j][1];
        LL next_j = dp[i][j][2];
        if(next_i != i && next_j != j){
            ans.PB(t[j-1]);
        }
        i = next_i;
        j = next_j;
    }
    reverse(ALL(ans));
    PUTS(ans);
}

Measured memory_bytes: 211328