#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <bitset>
#include <climits>
#include <cstdio>
#include <cstdlib>
 
using namespace std;
 
// ================ Typedefs ================
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
typedef pair<int, pii> ppiii;
typedef pair<int, pll> ppill;
typedef pair<ll, pii> plii;
typedef pair<ll,pll> plll;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
typedef vector<vpii> vvpii;
typedef vector<vpil> vvpil;
typedef vector<vpli> vvpli;
typedef vector<vpll> vvpll;
typedef map<int, int> mii;
typedef map<int, long> mil;
typedef map<string, int> msi;
typedef map<string, long> msl;
 
// =================== MACROS ===================
#define fastIO          std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
#define pb              push_back
#define eb              emplace_back
#define mp              make_pair
#define prt(x)          cout << x << "\n";
#define nl              cout << "\n";
#define sz(A)           (int)A.size()
#define all(A)          A.begin(), A.end()
#define x               first
#define y               second
#define rep(i, n)       for(size_t i = 0; i < n; ++i)
#define repr(i, n)      for(size_t i = n - 1; i >= 0; --i)
#define REP(i, s, e)    for(size_t i = s; i <= e; ++i)
#define REPR(i, s, e)   for(size_t i = e; i >= s; --i)
#define ip(n)           int n; cin >> n;
#define ipvi(A, n)      vector<int> A(n); for(int i=0; i<n; i++){cin >> A[i];}
#define ipvl(A, n)      vector<long long> A(n); for(int i=0; i<n; i++){cin >> A[i];}
#define opvec(A)        for(int i = 0; i < sz(A); i++){cout << A[i] << " ";} cout << endl;
#define nontestOpen     int test_no = 1; {
#define testOpen        int t = 1; cin >> t; for(int test_no = 1; test_no <= t; ++test_no){
#define testEnd         }
 
// Min - Max
template<typename T, typename U> 
static inline void amin(T &x, U y){if (y < x) x = y;} 
template<typename T, typename U> 
static inline void amax(T &x, U y){if (x < y) x = y;}
 
int max(int a, int b, int c){
    int mx = a;
    if(b > mx) mx = b;
    if(c > mx) mx = c;
    return mx;
}
 
#define deb(x) cout << #x << " : " << x << " ";
 
int main(){
    string s, t;
    cin >> s >> t;
 
    int n1 = s.size();
    int n2 = t.size();
    int dp[n1 + 1][n2 + 1];
    // dp[n][m] => length of LCS ending index <= at n in s1 and <= m in s2
 
    for(int i = 1; i <= n2; i++) dp[0][i] = 0;
    for(int i = 1; i <= n1; i++) dp[i][0] = 0;
    dp[0][0] = 0;
 
    for(int i = 1; i <= n1; i++){
        for(int j = 1; j <= n2; j++){
            dp[i][j] = max(dp[i-1][j], dp[i][j-1], dp[i-1][j-1] + (s[i - 1] == t[j-1] ? 1 : 0));
        }
    }
 
    int i = n1;
    int j = n2;
    bool found = false;
    string sub = "";
    while(!found){
        if(i > 0 && dp[i][j] == dp[i-1][j]) i--;
        else if(j > 0 && dp[i][j] == dp[i][j-1]) j--;
        else if(i > 0 && j > 0 && s[i-1] == t[j-1]){
            sub += s[i-1];
            --i; --j;
        }
        else found = true;
    }
 
    reverse(all(sub));
    cout << sub << endl;
    
    return 0;
}

Measured memory_bytes: 35456