//********************************************************************//
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fi first 
#define se second 
#define RANGE(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DFOR(i, a, b) for(int i = a; i > b; --i)
#define DEB(x) cout << #x << ": " << x << endl
#define ALL(v) v.begin(), v.end() 
#define SORT(v) sort(ALL(v))
#define DISPV(v) { for(auto x___: v) cout << x___ << " "; cout << endl; }
#define DISPM(m) { for(auto x____: m){ cout << x____.first << ": " << x____.second << endl; } };
#define DISPMV(m) { for(auto x_____: m){ cout << x_____.first << ": " ;DISPV(x_____.second);} };
using LL = long long;
using VI = vector <int>;
using VC = vector <char>;
using VS = vector <string>;
using VL = vector <long long>;
using VVI = vector<VI>;
using VVL = vector <VL>;
using MII = map<int, int>;
using MIVI = map<int, VI>;
using MSS = map<string, string>;
using MLL = map<LL, LL>;
int READ_INT(){int temp;cin>>temp;return temp;}      // read an int
LL READ_LONG(){LL temp;cin>>temp;return temp;}      // read a long long
void mcs(VI &series, int &max_sum){                    // maximum contigous sub sum(kadane)
    int s=0;
    for(auto x: series){
        s += x;
        max_sum = max(max_sum, s);
        if(s < 0)s = 0;
    }
}
template<typename T>
T MAX(T t){ return t;}
template <typename T, typename... Args>
T MAX(T t, Args... args){ return max(t, MAX(args...)); }
const int MOD = int(1e9) + 7;
const int INF = 1e9 + 5;
const double PI = acos(-1.0); //M_PI;
const double EPS = 1e-9;
//********************************************************************//

int n, m;
string s = "$", t = "$";
string ans = "";
int dp[3001][3001];

int lcs(int i, int j){
    // cout << i << ", " << j << endl;
    if(i == 0 || j == 0)return 0;
    if(dp[i][j] != -1)return dp[i][j];
    if(s[i] == t[j])
        dp[i][j] = max({1 + lcs(i-1, j-1), lcs(i, j-1), lcs(i-1,j)});
    else 
        dp[i][j] = max(lcs(i-1, j), lcs(i, j-1));
    return dp[i][j];
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string temp;
    cin >> temp;
    s += temp; 
    cin >> temp;
    t += temp;
    // cout << s << endl;
    n = s.size() - 1;
    m = t.size() - 1;

    memset(dp, -1, sizeof(dp));
    lcs(n, m);

    // for(int i = 1; i <= n; ++i){
    //     for(int j = 1; j <= m; ++j){
    //         cout << dp[i][j] << " ";
    //     }cout << endl;
    // }

    string ans = "";
    int i = n, j = m;
    while(true){
        while(dp[i][j] == dp[i][j-1])j--;
        while(dp[i][j] == dp[i-1][j])i--;
        if(s[i] == t[j])
            ans += s[i];
        // cout << i << ", " << j << endl;
        // cout << ans << endl;
        // READ_INT();
        i--;
        j--;
        if(i == 0 || j == 0)break;
    }
    reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}



/* complie flags
-Wall -Wextra -pedantic -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector
*/

Measured memory_bytes: 39244