#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int l;
#define fastIO              ios::sync_with_stdio(false), cin.tie(0)
#define pf                  push_front
#define pb                  push_back
#define popb                pop_back()
#define popf                pop_front()
#define loop(i,n)           for(int i=0;i<n;i++)
#define loop1(i,n)           for(int i=1;i<n;i++)
#define loops(i,x,n)        for(int i=x;i<n;i++)
#define loopr(i,n)          for(int i=n-1;i>=0;i--)
#define loop1e(i,n)          for(int i=1;i<=n;i++)
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long>
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define INT_BITS 32
#define  st                  l t; cin>>t;
#define  sn                  l n; cin>>n;
#define all(x) x.begin(),x.end()
//#define  unordered_map<l,l>  u;
#define MOD1 1000
int unboundedKnapsack(int k, int arr[],int n) {
    bool dp[n+1][k+1];
    for (int i = 0; i < n+1; i++)
        dp[i][0] = true;
     for (int i = 1; i <k+1; i++)
        dp[0][i] = false;
    for(int i=1;i<n+1;i++)
    {
        for(int j=1;j<k+1;j++)
        {
            if(arr[i-1]<=j)
            dp[i][j] = (dp[i][j-arr[i-1]]||dp[i-1][j]);
            else
            dp[i][j] = dp[i-1][j];
        }
    }
    int ans;
    for(int i=0;i<k+1;i++)
    {
        if(dp[n][i]==true)
        {ans = i;
       // cout<<k<<" ";
        }
       // cout<<"\n";
            }
return ans;


}
long getWays(int n, long c[],int m) {
    long dp[m+1][n+1]={0};
    for(int i=0;i<m+1;i++)
    {
        for(int j=0;j<n+1;j++)
        {
            if(j==0)
            dp[i][j]=1;
            else if( c[i-1]<=j) {
                dp[i][j] = dp[i][j-c[i-1]]+dp[i-1][j];
            }
            else {
            dp[i][j] = dp[i-1][j];
            }
        }
    }
return dp[m][n];


}
int ways(int a[],int n,int s)
{
    int dp[n+1][s+1];
    for(int i=0;i<n+1;i++)
    {
        for(int j=0;j<s+1;j++)
        {
            if(j==0)
                dp[i][j] =1;
            else if(i==0&&j>0)
                dp[i][j]=0;
            else if(a[i-1]<=j)
                dp[i][j] = dp[i-1][j]+dp[i][j-a[i-1]];
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    return dp[n][s];
}
bool no(int n)
{
    while(n>0)
    {
        l m = n%10;
        if(m!=4&&m!=7)
            return false;
        n=n/10;
    }
    return true;
}
void fun(l a)
{
    if(a>0)
    {
        fun(--a);
            cout<<a<<" "<<"\n";
        fun(--a);
    }
    return ;
}
l lcs(string x,string y, l n,l m)
{
    l dp[n+1][m+1];
    for(l i=0;i<n+1;i++)
    {
        for(l j=0;j<m+1;j++)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            else{
            if(x[i-1]==y[j-1])
            {
                dp[i][j] = 1+dp[i-1][j-1];
            }
            else
            dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    l i=n,j=m;
    int index = dp[n][m];
   string s;
   //s[index] = '\0';
    while(i>0&&j>0)
    {
        if(x[i-1]==y[j-1])
        {
             s.push_back(x[i-1]);
            i--;
            j--;
        }
       else
       {if(dp[i-1][j]>dp[i][j-1])
            i--;
        else
            j--;
       }
    }
     reverse(all(s));
    cout<<s;
return 0;
}
int main()
{
    fastIO;
  string x,y;
  cin>>x>>y;
  lcs(x,y,x.size(),y.size());
    return 0;
}


Measured memory_bytes: 73984