#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
#define mp make_pair
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power_mod(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define outaa(a, m, n) rep(i, m) {rep(j, n) cout << a[i][j] << " "; cout << endl;} cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl

//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always
//product of minimum 9 prime numbers is above 1e9

const int MAX = 3007;
pair<int, pii> dp[MAX][MAX];
//int dp[MAX][MAX];
int main() {
    
    
    string s, t; cin >> s >> t;
    int table[26][2] = {0};
    rep(i, SZ(s)) table[s[i] - 'a'][0]++;
    rep(i, SZ(s)) table[t[i] - 'a'][1]++;
    if (SZ(s) == 1) {
        if (table[s[0] - 'a'][1]) out(s[0]);
        else out("");
        return 0;
    } else if (SZ(t) == 1) {
        if (table[t[0] - 'a'][0]) out(t[0]);
        else out("");
        return 0;
    }
   
    rep(i, MAX) dp[i][0] = mp(0, pii(i, 0)); //1にしてた... 片方空
    rep(j, MAX) dp[0][j] = mp(0, pii(0, j));
    dp[0][0] = mp(0, pii(0, 0));
    
    
    rep3(i, 1, SZ(s) + 1) rep3(j, 1, SZ(t) + 1) {
        if (dp[i][j - 1].F < dp[i - 1][j].F) {
            dp[i][j] = mp(dp[i - 1][j].F, mp(i - 1, j));
        } else {
            dp[i][j] = mp(dp[i][j - 1].F, mp(i, j - 1));
        }
        if (s[i - 1] == t[j - 1] && dp[i][j].F < dp[i - 1][j - 1].F + 1) {
            dp[i][j] = mp(dp[i - 1][j - 1].F + 1, mp(i - 1, j - 1));
        }
        
    
    }
    /*
    out("");
    rep(i, SZ(s) + 1) {rep(j, SZ(t) + 1) cout << dp[i][j].F << " "; cout << endl;}
    out("");
    */
    
    
    /*
    rep(i, MAX) dp[i][0] = 0;
    rep(j, MAX) dp[0][j] = 0;
    
    rep3(i, 1, SZ(s) + 1) rep3(j, 1, SZ(t) + 1) {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        if (s[i - 1] == t[j - 1]) chmax(dp[i][j], dp[i - 1][j - 1] + 1);
        
    }
    
    rep(i, SZ(s)) {rep(j, SZ(t)) cout << dp[i][j] << " "; cout << endl;}
    
    */
    //どのタイミングでi-1,j-1 -> i,jになったか
    
    string u;
    int y = SZ(s), x = SZ(t);
    int tmpy = y, tmpx = x;
    while (1) {
        y = dp[tmpy][tmpx].S.F; x = dp[tmpy][tmpx].S.S;
        //out(y << " " << x << " " << tmpy << " " << tmpx);
        if (y == tmpy - 1 && x == tmpx - 1) u += s[y];
        if (tmpy == y && tmpx == x) break;
        tmpy = y; tmpx = x;
        
    }
    
    
    reverse(all(u));
    out(u);
    
}


Measured memory_bytes: 105984