#include <bits/stdc++.h>
using namespace std;

template<class T> ostream& operator<<(ostream &os, vector<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T> ostream& operator<<(ostream &os, set<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, map<T , R> V){
	os << "[ ";
	for(auto v  : V) os << "(" << v.first << ":" << v.second << ")";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, pair<T , R> V){
	return os << "(" << V.first << "," << V.second << ")";
}

#define cerr cout
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
    clock_t clk=clock();
    #define checktime() cout<<"\nTime Elapsed : "<<float(clock()-clk)/CLOCKS_PER_SEC<<endl
#else
    #define trace(...);
    #define checktime();
#endif
/*---------------------------Defines----------------------*/
typedef long long int ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vbl vector<bool>
#define vvll vector<vll>
#define vld vector<ld>
#define vb vector<bool>
#define vc vector<char>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
/*-----------------------Modular Arithmetic---------------*/
inline int add(int x,int y,int mod){
    x+=y;
    if (x>=mod) return x-mod;
    return x;
}
inline int sub(int x,int y,int mod){
    x-=y;
    if (x<0) return x+mod;
    return x;
}
inline int mul(int x,int y,int mod){
    return (x*1ll*y)%mod;
}
inline int power(int x,int y,int mod){
    int ans=1;
    while(y){
        if (y&1) ans=mul(ans,x,mod);
        x=mul(x,x,mod);
        y>>=1;
    }
    return ans;
}
inline int inv(int x,int mod){
    return power(x,mod-2,mod);
}
/*-----------------------------Code begins----------------------------------*/

bool first(pll p){
    return p.F==0 || p.S==0;
}

void solve(){
    string s,t;cin>>s>>t;
    ll n=s.size(),m=t.size();

    vector<vector<pair<ll,pll>>> dp(n+1,vector<pair<ll,pll>>(m+1,{-(1e9),{0,0}}));
    dp[0][0]={0,{0,0}};
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            if(s[i]==t[j]){
                if(dp[i+1][j+1].F<1+dp[i][j].F) dp[i+1][j+1]={dp[i][j].F+1,{i,j}};
            }
            if(dp[i+1][j].F<=dp[i][j].F) dp[i+1][j]={dp[i][j].F,{i,j}};
            if(dp[i][j+1].F<=dp[i][j].F) dp[i][j+1]={dp[i][j].F,{i,j}};
        }
    }
    ll mx=0;
    pll at;
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=m;j++){
            if(mx<=dp[i][j].F){
                mx=dp[i][j].F;
                at={i,j};
            }
        }
    }
    // trace(dp[4][5]);
    string ans;
    while(!first(at)){
        pll prev=dp[at.F][at.S].S;
        if(prev==make_pair(at.F-1,at.S-1)) ans+=s[at.F-1];
        // trace(at,prev,ans);
        at=prev;
    }
    reverse(all(ans));
    cout<<ans<<"\n";
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<fixed<<setprecision(25);

    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 211456