/*
    LIFE WOULD BE SO BEAUTIFUL IF BRUTE WORKED EVERYTIME
    */
    #include <bits/stdc++.h>
    #include <string.h>
    #define int long long
    #define MAX (int)1e5
    #define itn int
    #define inf 1e9
    #define mod 1000000007
    #define pb push_back
    #define all(x) x.begin(),x.end()
    #define mk make_pair
    #define sitr set<int> :: iterator
    #define mitr map<int,int> :: iterator
    #define pii pair<int,int>
    #define vii vector<pii>
    #define vi vector<int>
    #define sortall(x) sort(x.begin(),x.end());
    #define fori(i,n) for(int i=0;i<n;i++)
    #define test int t;cin>>t;while(t--)
    #define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
    using namespace std;
    const int N = 5000007;
    int spf[N];
    void SPF()
    {
        spf[0] = 1;
        spf[1] = 1;
        for(int i=2;i<=(int)5e6;i++)
        {
            if(spf[i] == 0)
            {
                for(int j=i;j<=(int)5e6;j+=i)
                {
                    if(spf[j] == 0)
                        spf[j] = i;
                }
            }
        }
    }
    int n;
    vii a(MAX);
    bool alreadychanged(int n)
    {
        if(a[n].second != 0)
            return true;
        return false;
    }

    int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}

    int32_t main(){
        //fast;
        string a,b;
        cin>>a>>b;

        int n = a.length();
        int m = b.length();

        int v[n][m];
        int ans[n][m];
        memset(v,0,sizeof(v));
        if(a[0] == b[0])
        {
            v[0][0] = 1;
            ans[0][0] = 2;
        }
        else
        {
            v[0][0] = 0;
            ans[0][0] = 0;
        }

        for(int i=1;i<m;i++)
        {
            if(a[0] == b[i])
            {
                v[0][i] = 1;
                ans[0][i] = 2;
            }
            else
            {
                v[0][i] = v[0][i-1];
                ans[0][i] = 0;
            }
        }



        for(int i=1;i<n;i++)
        {
            if(a[i] == b[0])
            {
                v[i][0] = 1;
                ans[i][0] = 2;
            }
            else
            {
                v[i][0] = v[i-1][0];
                ans[i][0] = 1;
            }
        }

        for(int i=1;i<n;i++)
        {
            for(int j=1;j<m;j++)
            {
                if(a[i] == b[j])
                {
                    v[i][j] = v[i-1][j-1]+1;
                    ans[i][j] = 2;
                }
                else
                {
                    if(max(v[i-1][j],v[i][j-1]) == v[i-1][j])
                        ans[i][j] = 1;
                    else
                        ans[i][j] = 0;
                    v[i][j] = max(v[i-1][j],v[i][j-1]);
                }
            }
        }
        int len = v[n-1][m-1];
        //cout<<len;
        int i = n-1;
        int j = m-1;
        string f = "";
        while(f.length() < len) {
            if(ans[i][j] == 2)
            {
                f += a[i];
                i--;
                j--;
            }
            else if(ans[i][j] == 0)
            {
                j--;
            }
            else
            {
                i--;
            }
        }


        reverse(all(f));
        cout<<f;
        return 0;
    }


Measured memory_bytes: 142464