#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i ,a,b) for(int i = a;i<b;i++)
#define rloop(i,a,b) for(int i = a ; i>b;i--)
#define loopll(i,a,b) for( long long int i = a; i<b;i++)
#define rloopll(i,a,b) for(long long int i = a; i>b;i--)
#define eb emplace_back
#define pii pair<int ,int>
#define pll pair<ll ,ll>
#define mk make_pair
#define intmin INT_MIN
#define intmax INT_MAX
#define cout(x) cout<<x<<" ";
using namespace std;
void vec(vector<int> & v){

    for(int i = 0;i<v.size() ; i++){
        cout<<v[i]<< " ";
    }
    cout<<endl;
}
void vec_ll(vector<long long int> & v){

    for(int i = 0;i<v.size() ; i++){
        cout<<v[i]<< " ";
    }
    cout<<endl;
}
int parsestring(string temp){
    int num= 0;
    int digs = temp.size() - 1;
    for(int i = 0 ;i<=digs;i++){
        num += pow(10 , digs -i)*(temp[i] - '0');
    }
    return num;
}

int mindig(string & s){
    int temp = INT_MAX;
//    int index = -1;
    for(int i = 0;i<s.size() ; i++){
        if(temp > s[i] - '0'){
            temp = s[i] - '0';
//            index = i;
        }
    }
    return temp;
}
//}
ll power(ll base ,ll exp){
    ll ans = 1;
    for(ll i = 1;i<=exp ; i++){
        ans *= base;
    }
    return ans;
}
//}
//
void factor(ll n ,set<ll> &s ){
        ll x = 2;
        while(n!= 1){
            if(n%x == 0){
                s.insert(x);
                n/= x;
            }
            else{
                x++;
            }
        }
    }

bool prime(int n){
    bool ok = true;
    for(int i = 2 ; i*i <= n ; i++){
        if(n%i == 0){ok =false ; break;}
    }
    return ok;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s, t;
    cin>>s>>t;
    vector<vector<pair<int ,pair<int , int>>>> dp(s.size()+1 , vector<pair<int ,pair<int ,int>>>(t.size()+1 , mk(0 ,mk(0,0))));

    for(int i = 1;i<=s.size();i++){
        for(int j = 1;j<=t.size() ;j++){
            if(s[i-1] == t[j-1]){
                dp[i][j].first = dp[i-1][j-1].first + 1;
                (dp[i][j].second).first = -1;
                (dp[i][j].second).second = -1;
            }
            else{
                if(dp[i-1][j].first > dp[i][j-1].first){
                    dp[i][j].first = dp[i-1][j].first ;
                    (dp[i][j].second).first = -1;
                    (dp[i][j].second).second = 0;
                }
                else{
                    dp[i][j].first = dp[i][j-1].first;
                    (dp[i][j].second).first = 0;
                    (dp[i][j].second).second = -1;
                }
            }
        }
    }
//    for(int i = 0;i<=s.size() ; i++){
//        for(int j = 0;j<=t.size() ;j++){
//            cout<<dp[i][j].first<< "(" << (dp[i][j].second).first<< " "<<(dp[i][j].second).second << ")"<< " " ;
//        }
//        cout<<endl;
//    }
    string ans = "";
    int i = s.size() , j = t.size();
    while(i > 0 && j > 0){
//        cout<<i<< "  "<< j<<endl;
        int x = (dp[i][j].second).first;
        int y = (dp[i][j].second).second;
        if(x == -1 && y == -1){
            ans += s[i-1];
            i--;
            j--;
        }
        else{
            i +=  x;
            j += y;
        }
    }
    reverse(ans.begin() , ans.end());
    cout<<ans<<endl;
}


Measured memory_bytes: 108940