#pragma GCC optimize "O2"
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <queue>
// for iota, accumulate, partial_sum
// #include <numeric>
// #include <iomanip>
// #include <fstream>
// #include <deque>
// #include <cmath>
// #include <unordered_map>
// #include <utility>
// #include <unordered_set>
// #include <ctime>
// #include <stack>
// #include <bitset>
// #include <random>
// #include <cstring>
// #include <cassert>
// #include <complex>
using namespace std;
typedef long long int lu;
typedef long long int ll;
typedef long double ld;
#define v vector<ll>
#define vu vector<lu>
#define vvu vector<vector<lu>>
#define vld vector<ld>
#define vs vector<string>
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define puu pair<lu, lu>
#define vpuu vector<pair<lu, lu>>
const lu MOD = 1000000007;
const ld PI = 2 * acos(0.0);
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))

#define all(x) x.begin(), x.end()

v ga(ll n)
{
    v a;
    for (ll i = 0; i < n; i++)
    {
        ll p;
        // scanf("%lld", &p);
        cin >> p;
        a.push_back(p);
    }
    return move(a);
}

vu gau(lu n)
{
    vu a;
    for (lu i = 0; i < n; i++)
    {
        lu p;
        // scanf("%lu", &p);
        cin >> p;
        a.push_back(p);
    }
    return move(a);
}
vs gas(lu n)
{
    vs a;
    for (lu i = 0; i < n; i++)
    {
        string p;
        // scanf("%lu", &p);
        cin >> p;
        a.push_back(p);
    }
    return move(a);
}

template <typename T, typename A>
void pa(vector<T, A> const &a)
{
    for (T p : a)
    {
        // printf("%lu ", a[i]);
        cout << p << " ";
    }
    cout << "\n";
}

void yes()
{
    cout << "YES\n";
}

void no()
{
    cout << "NO\n";
}

void yesno(int f)
{
    if (f)
        yes();
    else
        no();
}

void solve()
{
    string s, t;
    cin >> s >> t;
    lu n, m;
    n = s.size();
    m = t.size();
    s = "-" + s;
    t = "-" + t;
    vector<vu> lcs(n + 1, vu(m + 1, 0));
    string p = "";

    lu ma = 0;
    for (lu i = 1; i <= n; i++)
    {
        for (lu j = 1; j <= m; j++)
        {
            if (i == 1 && j == 1)
            {
                if (s[i] == t[j])
                {
                    lcs[i][j] = 1;
                    ma = 1;
                }
                else
                    lcs[i][j] = 0;
            }
            else if (s[i] == t[j])
            {
                lu val = 1 + lcs[i - 1][j - 1];
                lcs[i][j] = val;
                if (val > ma)
                {
                    ma = val;
                }
            }
            else if (i > 1 && j > 1)
            {
                if (lcs[i - 1][j] > lcs[i][j - 1])
                    lcs[i][j] = lcs[i - 1][j];
                else
                    lcs[i][j] = lcs[i][j - 1];
            }
            else if (i == 1)
                lcs[i][j] = lcs[i][j - 1];
            else if (j == 1)
                lcs[i][j] = lcs[i - 1][j];
        }
    }
    string ans = "";
    lu i = n, j = m;
    while (i > 0 && j > 0)
    {
        if (s[i] == t[j])
        {
            ans = s[i] + ans;
            i--;
            j--;
        }
        else if (lcs[i - 1][j] > lcs[i][j - 1])
        {
            i--;
        }
        else
            j--;
    }

    // for (auto val : lcs)
    // {
    //     for (auto p : val)
    //     {
    //         // if (p.second != "")
    //         // cout << p.second << " ";
    //     }
    //     // cout << endl;
    // }

    cout << ans;
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();
    return 0;
}

Measured memory_bytes: 70784