#include<bits/stdc++.h>
#define next_permutation np //next_permutation(s.begin(),s.end())or arr,arr+3
//qsort( str, size, sizeof( str[0] ), compare ); for strings
// ceil/floor funtion
//upper_bound() return an iterator(important);
//map<pair<int, int>, int> vis;vos({0,0},1) used for positon ;//pair<int ,int >cur={0,0};
//to get 3/2 ceil value ==2 use a=3,b=2;(b+a-1)/2
// a string can be converted into
//Note that the actual problem is to divide the string into two subsequences that both of them are non-decreasing. 
//You can note that this is true because you cannot change the relative order of the elements colored in the same color, but you can write down subsequences of different colors in any order you want.
//agar 1111111 hogaya toh all increasing 
//vector<pair<int, int>> a(n);
    	//for (int i = 0; i < n; ++i) {
    	//	cin >> a[i].first >> a[i].second;
    	//}
    	//sort(a.begin(), a.end());
    	
    	
    	//prime factor
    	/*for(i=2;i*i<n&&k<2;i++)
           {
               if(n%i==0)
               {
                   arr[k]=i;
                   k=k+1;
                   n=n/i;
               }
               
           }*/
           /*
           
           complexity ke maa ki chutttt
           jo idea aa raha hai use implement kar 
           complexity ke maa ki chuut*/
           //fast exponention a^10000=b//logn time/////
           /*while(t--)
     {
        ll n,i,j,k=0,x,y,f=0;
        cin >>n;
        cin >>x;
        
       for(i=1;i<n;i++)
      {
          cin >>y;
          if(x*y>0)x=max(x,y);
          else
          {
              k=k+x;
              x=y;
          }
      }
      k=k+x;
      
      cout<<k<<endl;
     */
     /* for(i=0;i<n/2;i++)
        {
            l=p[i].first+1;
            r=p[i].second+k;
        pref[l]=pref[l]+1;
            pref[r+1]=pref[r+1]-1;
       }
       //Q is l r x
              1 2 3
              2 5 2      
              use this technique+prefix sum
     
     
     
     for(i=2;i<=2*k;i++)
       {
           sum=sum+pref[i];
           pref[i]=sum;
       }
         */ 
/*




for(i=0;i<n;i++)
    sort(v[i].begin(),v[i].end());
     for(i=1;i<n;i++)
     {
         for(j=0;j<v[i].size();j++)
         
         {
            auto it=find(v[i-1].begin(),v[i-1].end(),v[i][j]);
            if(it !=v[i-1].end())
            {
                ans++;
            v[i-1].erase(it);
            }
             
             
         }
     }
     */
#define ll long long
#define pb push_back
#define mp make_pair

/*


PPPPPPPRRRRRRRRRREEEEEEEEEFIXXXXXX SSSSSSSSSSSSUUUUUUUUUUMMMMMMMMMM*/
/*DIV 2 KE 2 MAX SAWAL KARNE hai
        DIV 3 KE MAX 3 SAWAL KARNE HAI
        LUNCHTIME/COOKOFF KE 2 MIN KARNE HAI
        LONG KE 3 MIN KARNE HAI*/
        /*SAWAL PADHE KE BAAD PHELE CONLUSION/FIGUREOUT KAR SAKTA NIKAL KE N=1,N=2,N=0,YE NAHI KE SOLVE KARNE 
        LAG JAY
        KYA KYA POSSIBLE VALUES HO SAKTE HAI
        DIMAG LAGA 
        K*L KO MAX SE MIN TAK PAUCHANA HAI 
        AUR YE MAT SUCH KE NAHI HO SAKTA*/

ll power(ll x,ll b)
{
    ll res=1;
    if(b==0)
    return 1;
    while(b>0)
    {
      if(b%2!=0)
      res=(res*x);
      b=b/2;
      x=(x*x);
      
    }
    return res;
}
 int gcd(int a, int b) 
         { 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
}
 /*for(i=0;i<n-1;i++)
       {
           if(arr[i]==arr[i+1])
           {
               c++;
           }
           else
           {
               v.pb(mp(arr[i],c));
               c=1;
           }
       }
  */
       


  
ll M = 1e9 + 7;
/*ll fact[N], inv[N];
 
void pre()
{
    fact[0] = 1; inv[0] = 1;
    for(ll i=1;i<N;i++)
    {
        fact[i] = (fact[i-1]*i)%M;
        inv[i] = power(fact[i],M-2);
    }
    
}
 
ll C(ll n,ll r)
{
    ll ans = ((fact[n]*inv[r])%M + M)%M;/////counting nCr aCb;
    ans = ((ans*inv[n-r])%M + M)%M;
    return ans;
}
/*


FFFFFIIIIINNNNDDDDDD function in c/++++++
nlogn;

*/
ll min(ll a,ll b)
{
    if(a>b)
    return b;
    else
    return a;
}
 


        
        /*FFFFFIIIIINNNNDDDDDD erase function usee kar vector m,e*/  
    /*ll c(ll r,ll lc,ll b)
    {
        ll total=r;
        total=r-(b-1);
        ll divi=r/lc;
        ll pdt =divi*lc;

        if(divi!=0)
        {
            total=total-(divi-1)*b;
                    total =total-min(r-pdt+1,b);
            
        }
        return total;
    }
   ll k(ll r,ll lc,ll b)
    {
        ll total=r;
        total=total-min(r,(b-1));
        ll divi=r/lc;
        ll pdt =divi*lc;

        if(divi!=0)
        {
            total=total-(divi-1)*b;
                    total =total-min(r-pdt+1,b);
            
        }
        return total;
    }*/
    /*1ST AND 2ND PROBLEM ARE JUST WHAT U CAN OBSERVE */
      /*EXAMLE LIKE x%a%b!=x%b%a
      hame yeh toh pata hai ke saraa loop toh nahi chalana 
      isley hame cases hatane honge 
      PRINCILE OF INCLUSIVE OR EXCLUSIVE
      
      toh
      SMALL CASES KE LEYE RUNN KAR PURA LOOP 
      PATTEN APNE AAP MIL JAYGA
      LIKE (L,R)
      ===(R)CASES -(L-1)CASES;
      */
     
   
    	
using namespace std;

vector<ll>g;
void bin(ll n) 
{ 
    /* step 1 */
    if (n > 1) 
        bin(n/2); 
  
    /* step 2 */
    g.pb(n%2);
    //cout << n % 2; 
} 











int main()
{
   string s1,s2;
   cin>>s1>>s2;
   ll i,j,n1=s1.length(),n2=s2.length();
   ll dp[n1+1][n2+1]={0};
   for(i=0;i<=n1;i++)
   {
       for(j=0;j<=n2;j++)
       {
           if(i==0||j==0)
           {
               dp[i][j]=0;
           }
           else if(s1[i-1]==s2[j-1])
           {
               dp[i][j]=1+dp[i-1][j-1];
               
           }
           else
           {
               dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
           }
           
       }
   }
   i=n1;j=n2;
   string s="";
   //cout<<dp[n1][n2];
   while(i>0&&j>0)
   {
       
       if(dp[i][j]==dp[i][j-1])
       {
           j--;
       }
       else if(dp[i][j]==dp[i-1][j])
       {
          i--;  
       }
       else
       {
          s=s1[i-1]+s;
           i--,j--;
       }
   }
   
   cout<<s;

   
    
    
    
    
}



Measured memory_bytes: 70656