#include<bits/stdc++.h>

using namespace std ;
string s , s2 ;

int l , l2 ;
const int MAXN = 3001 ;
int dp[MAXN][MAXN] ;

string co ;
void lcs()
{
    for (int i=0;i<=l;i++)
    {

        for (int j=0;j<=l2;j++)
        {
            if(i==0 || j==0)
            {

                dp[i][j] = 0 ;
            }
            else if(s[i-1]==s2[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);

        }
    }

    int x  = l  , y=  l2 ;
    bool track = true ;

    while(dp[x][y] !=0 )
    {
        int ma = max(dp[x-1][y-1],max(dp[x][y-1],dp[x-1][y]));
        if( ma< dp[x][y])
        {
            co += s[x-1] ;
            x-- ;
            y-- ;
        }

        else if(dp[x-1][y-1] == ma)
        {
            x-- ;
            y-- ;
        }
        else if (dp[x][y-1] == ma)
        {

            y--;
        }
        else if(dp[x-1][y] == ma)
        {
            x--;
        }

    }




}


int main()
{


    cin>> s>>s2 ;
    l = s.length() ;
    l2 = s2.length();

    lcs();
    reverse(co.begin(),co.end()) ;

    cout<<co ;



}
