//RITIK RAI:
//#pragma GCC optimize("O3")
 
/*----------------------------------------------------------------------------------------------------------*/
 
#include<bits/stdc++.h>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<iterator>
 
using namespace std;
 
/*----------------------------------------------------------------------------------------------------------*/
 
#define ll long long int
#define ull unsigned long long int
#define ld long double
 
/*----------------------------------------------------------------------------------------------------------*/
 
#define vll vector<ll>
#define vvll vector<vector<ll>>
 
#define vstr vector<string>
 
#define vi vector<int>
#define vvi vector<vector<int>>
 
#define pb push_back
 
/*----------------------------------------------------------------------------------------------------------*/
 
#define mll map<ll,ll>
 
/*----------------------------------------------------------------------------------------------------------*/
 
#define pll pair<ll,ll>
#define mp make_pair
#define fir first
#define sec second
 
/*----------------------------------------------------------------------------------------------------------*/
 
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bin binary_search
 
/*----------------------------------------------------------------------------------------------------------*/
 
#define vmin *min_element
#define vmax *max_element
#define intg INT_MAX
#define ints INT_MIN
 
/*----------------------------------------------------------------------------------------------------------*/
 
#define mod 1000000007
#define endl '\n'
 
/*----------------------------------------------------------------------------------------------------------*/
 
#define fill0(arr,a,b) for(ll i=a;i<b;i++) arr[i]=0
 
/*----------------------------------------------------------------------------------------------------------*/
 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>b;i--)
 
/*----------------------------------------------------------------------------------------------------------*/
 
#define print1(arr,a,b) for(ll i=a;i<b;i++) cout<<arr[i]<<" "; cout<<endl
#define print(arr,a,b)  for(ll i=a;i<b;i++) cout<<arr[i]<<endl
#define print2d(dp,r,c) for(ll i=0;i<r;i++){for(ll j=0;j<c;j++) cout<<dp[i][j]<<" "; cout<<endl;}
 
/*----------------------------------------------------------------------------------------------------------*/
 
#define ritik ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
 
 
 
/*--------------------------------------------FUNCIONS--------------------------------------------------------------*/
 
 
/*
    ll p=1000000007;
        fac[0] = 1;
        f(i,1,100005)
            fac[i] = (fac[i-1]*i)%p;
*/
 
 
ll power(ll x,ll y,ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
 
ll max3(ll a,ll b,ll c)
{
    return max(max(a,b),c);
}
 
 
/*------------------------------------------GLOBAL VARIABLES----------------------------------------------------------------*/
 
#define maxm 100003
ll fac[300007];
 
/*-----------------------------------------------write your code here-----------------------------------------------------------*/
 
 
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    s1="*"+s1;  s2="*"+s2;
    ll l1=s1.length(),l2=s2.length();
    vector<vector<ll>> dp(l1,vector<ll>(l2));
    f(i,1,l1)
    f(j,1,l2)
    {
        if(s1[i]==s2[j])  dp[i][j]=1+dp[i-1][j-1];
        else  dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
    }
    string ans="";
    ll i=l1-1,j=l2-1;
    while(1)
    {
        if(s1[i]==s2[j]) { ans=s1[i]+ans; i--; j--; }
        else if (dp[i][j-1]>dp[i-1][j]) j--;
        else if (dp[i][j-1]<=dp[i-1][j]) i--;
        if(dp[i][j]<=0) break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 70784