#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
#define pb push_back
#define N 200001
#define ll long long
#define int long long
#define pi pair<int , int>
#define pip pair<pi ,int>
#define mp make_pair
#define f first
#define s second
#define mod 998244353
int32_t main(){
   ios_base::sync_with_stdio(false);
      cin.tie(NULL);
    cout.tie(NULL);


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                int php[4000] , cdc[8000], cdm[8000];
//                for(int j=0;j<5;j++){
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//for(int i=0;i<2000;i++)php[i/10]=1;
//                }
//
// vector<int> ab;
// vector<int> ab1(1000);
// vector<int> ab2;
// vector<int> ab3;
// vector<int> ab4;
// vector<int> ab5;
// string abcd="bdcccebcaca kjbcbsnklnslknvksn  nidcldklcnlsn";
// string abcd1="bdcccebcaca kjbcbsnklnslknvksn  nidcldklcnlsn cbcksknlsnv";
// string abcd2="bdcccebcaca kjbcbsnklnslknvksn  nidcldklcnlsn kjeaebbaekcmaekes";
//
//
// char abcde[1000];
// int mfch=0;
// int abcdefg[1000];
// int abcg[1000];
// int abcfg[1000];

////////////////////////////////////////////////////////////////////////////////////////////////////////



//    ll t;
//    cin>>t;
//    while(t--)
        {
      int n ;
      string s , t;
      cin>>s>>t;
      int m = t.length();
      n= s.length();

      vector<vector<int>>dp( n+1 , vector<int>(m+1 , 0));

      for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]= max(dp[i][j-1] , dp[i-1][j-1]+1);
            }
            else dp[i][j]=max(dp[i-1][j] , dp[i][j-1]);
        }
      }
      //cout<<dp[n][m]<<endl;

       int index = dp[n][m];
string X=s , Y=t;
   // Create a character array to store the lcs string
   char lcs[index+1];
   lcs[index] = '\0'; // Set the terminating character

   // Start from the right-most-bottom-most corner and
   // one by one store characters in lcs[]
   int i = n, j = m;
   while (i > 0 && j > 0)
   {
      // If current character in X[] and Y are same, then
      // current character is part of LCS
      if (X[i-1] == Y[j-1])
      {
          lcs[index-1] = X[i-1]; // Put current character in result
          i--; j--; index--;     // reduce values of i, j and index
      }

      // If not same, then find the larger of two and
      // go in the direction of larger value
      else if (dp[i-1][j] > dp[i][j-1])
         i--;
      else
         j--;
   }
   for(int i=0;i<dp[n][m] ;i++)cout<<lcs[i];
   return 0;




/*
      string ans="";
      int x=dp[n][m];

int i=n , j=m;
      while(i>0 && j>0){
        while(dp[i-1][j]==x && i>0)i--;
        while(dp[i][j-1]==x && j>0)j--;
if(i==0 || j==0)break;
        ans+=s[i-1];
        i--;
        j--;
        x=dp[i][j];

      }
      if(ans.size()==0){
        cout<<" ";
        return 0;
      }
      reverse(ans.begin() , ans.end());
      cout<<ans;
      */


    }

}




Measured memory_bytes: 73616