#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
#define MOD 1000000007
#define INF 1e18
#include <ctime>
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define rev(i, n, x) for (ll i = n; i > x; i--)
#define all(c) (c).begin(), (c).end()
#define int long long int
#define endl "\n"
#ifdef mishra
#define debug(x) cout << " >> " << #x << ": " << x;
#define debugend() cout << endl;
#define debug1 ;
#define print_time() cout << setprecision(6) << "time: " << (clock() - start) / (double)CLOCKS_PER_SEC << '\n';
#else
#define debug(x) ;
#define debugend() ;
#define debug1 //
#define print_time() ;
#endif

clock_t start;
void FAST(ll argc)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    start = clock();
    if (argc == 2)
        freopen("std2.txt", "r", stdin);
}

/*vector<ll> v;
void seive()
{
    v.pb(2);
    for (int i = 3; i < 100000; i += 2)
    {
        for (int j = 0; j < v.size(); j++)
        {
            if (i % v[j] == 0)
                break;
            if (v[j] * v[j] > i)
            {
                v.pb(i);
                break;
            }
        }
    }
}
/*
void prime_factor(ll x, vector<ll> &r)
{
    ll sqrt_x = sqrt(x);

    for (ll i : v)
    {
        if (i > sqrt_x)
            break;

        if (x % i == 0)
            r.pb(i);

        while (x % i == 0)
        {
            x /= i;
        }
    }

    if (x >= 2)
        r.pb(x);
}
*/
/*
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % MOD;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % MOD;
        y = y >> 1;
        x = (x * x) % MOD;
    }
    return res;
}
*/
/*
inline void dfs(ll curr, ll prev)
{

    for (ll i : a[curr])
        if (i != prev)
            dfs(i, curr);
}
*/
/*
ll multi(ll a, ll b)
{
    return ((a * b) % MOD);
}
*/
//---------------------CODE STARTS HERE---------------------

signed main(char argc, char *argv[])
{
    FAST(argc);

    ll testcase = 1;
    // cin >> testcase;

    while (testcase--)
    {
        int n1, n2;
        string s1, s2;
        cin >> s1 >> s2;
        n1 = s1.size(), n2 = s2.size();
        int dp[n1 + 1][n2 + 1];
        s1.insert(s1.begin(), '1'), s2.insert(s2.begin(), '1'); // 1 based indexing
        rep(i, 0, n1 + 1)
        {
            rep(j, 0, n2 + 1)
            {
                if (i * j == 0)
                    dp[i][j] = 0;
                else if (s1[i] == s2[j])
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                else
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
        //  cout << dp[n1][n2] << endl;
        // debug("aadarsh");
        // debugend();
        // debug1 cout << "aadarsh" << endl;
        // rep(i, 0, n1 + 1)
        // {
        //     rep(j, 0, n2 + 1)
        //             cout
        //         << dp[i][j] << " ";
        //     cout << endl;
        // }
        // cout << endl;
        string ans = "";
        int i = n1, j = n2;
        while (dp[i][j] != 0)
        {
            if (dp[i - 1][j] == dp[i][j - 1] && dp[i][j] > dp[i - 1][j])
            {
                // if (dp[i][j] > dp[i - 1][j - 1])
                    ans.pb(s1[i]);
                i--, j--;
            }
            else if (dp[i - 1][j] > dp[i][j - 1])
                i--;
            else
                j--;
        }
        reverse(ans.begin(), ans.end());
        cout << ans << endl;

        //--------??--------CLEAR VECTORS--------??--------
    }

    //v.clear();
    print_time();
    return 0;
}

Measured memory_bytes: 70656