#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
typedef vector<point> polygon;
#define X real()
#define Y imag()
#define angle(a) ( atan((a.imag()),a.real() )
#define dot(a, b) (conj(a) * (b)).real()
#define cross(a, b) (conj(a) * (b)).imag()
const double pi = acos(-1.0);
const double EPS=(1e-7);
typedef tuple <ld, ld, ld> line;

line lineeq(point x, point y)
{
    ll a = y.Y - x.Y;
    ll b = x.X - y.X;
    ll c = -a * x.X - b * x.Y;
    ll gcd = abs(__gcd(a, __gcd(b, c)));
    if(a < 0 || (a == 0 && b < 0))
        gcd *= -1;
    a /= gcd;
    b /= gcd;
    c /= gcd;
    return line(a, b, c);
}
point Getpoint(line l1, line l2)
{
    ld y = (get<0>(l1) * get<2>(l2) - get<0>(l2) * get<2>(l1)) / (get<0>(l2) * get<1>(l1) - get<0>(l1) * get<1>(l2));
    ld x = -1 * (get<1>(l1) * y + get<2>(l1)) / get<0>(l1);
    return point(x, y);
}

bool OnRay(point a, point b, point c)
{

    return dot(b - a, c - a) > EPS;
}

ld dist(point p, point q)
{
    return (p.X - q.X) * (p.X - q.X) + (p.Y - q.Y) * (p.Y - q.Y);
}
const ld angle = 90*pi/180;
point rotateArroundPoint(point p, point a)
{
    return (p - a) * polar((ld) 1, angle) + a;
}
/*
vector<ll>prime_fac;
void primeFactors(ll n)
{
    while (n%2 == 0)
    {
        prime_fac.push_back(2);
        n = n/2;
    }

    for (ll i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            prime_fac.push_back(i);
            n = n/i;
        }
    }
    if (n > 2)
        prime_fac.push_back(n);
}
*/

ll m=1e9+7;
ll fast_power(ll x, ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return (fast_power(x, y/2)%m*fast_power(x, y/2))%m;
    else
        return (x%m*fast_power(x, y/2)%m*fast_power(x, y/2))%m;
}




/*
ll fac[(int)1e6];
ll mod=1e9+7;
void fact(ll n)
{
 fac[0]=1;
 for(ll i=1;i<n;i++)
        fac[i]=(fac[i-1]*i)%mod;
}
*/

/*
bool prime[1000005];
void SieveOfEratosthenes(ll n)
{

    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
*/



bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i*i <= n; i++)
        if (n % i == 0)
            return false;

    return true;
}
vector<ll>v;
void printPrime(int n)
{
    for (int i = 2; i <= n; i++)
    {
        if (isPrime(i))
            v.push_back(i);
    }
}


/*
vector<ll>v;
void divesors(ll a)
{
    for(ll i=1;i*i<=a ;i++)
    {
        if(a%i==0)
        {

            if((a/i)==i)
            {

                v.push_back(i);
            }
            else
            {
                v.push_back(i);
                v.push_back(a/i);

            }
        }

    }
}
*/

/*
ld arr[10005][10005];
void Pascal(int n)
{




    for (int line = 0; line < n; line++)
    {

        for (int i = 0; i <= line; i++)
        {

        if (line == i || i == 0)
            arr[line][i] = 1;

        else
            arr[line][i] = arr[line - 1][i - 1] +
                            arr[line - 1][i];

        }

    }
}
*/

string a , b;
//vector<char>v;
int dp[3005][3005];

int solve(int i , int j)
{
    if(i==a.size() || j==b.size())
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    if(a[i]==b[j])
    {
       return dp[i][j]=1+solve(i+1,j+1);
    }
    else
        return dp[i][j]=max(solve(i+1,j),solve(i,j+1));
}

void build(int i , int j)
{
    if(i==a.size()||j==b.size())
        return ;
    if(a[i]==b[j])
    {
        cout<<a[i];
        build(i+1,j+1);
        return;

    }
    if  (solve(i + 1, j)==dp[i][j])
     build(i+1,j);
    else
        build(i,j+1);


}

int main()
{
    memset(dp,-1,sizeof dp);
    cin >> a >> b;
    //cout<<solve(0,0)<<endl;
    solve(0,0);
    build(0,0);

    return 0;
}

/*for(ll i=0;i<a.size();i++)
    {
        for(ll j=0;j<b.size();j++)
        {
            build(i,j);
        }
    }*/



/*for(ll i =0;i<a.size();i++)
    {
        for(ll j=0;j<b.size();j++)
        {
            cout<<dp[i][j]<< " ";
        }
        cout<<endl;
    }*/


Measured memory_bytes: 35840