#include <bits/stdc++.h>

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}


template<class Iterator>
size_t lcs(Iterator s_first, Iterator s_last, Iterator t_first, Iterator t_last) {
    const size_t s_len = distance(s_first, s_last);
    const size_t t_len = distance(t_first, t_last);

    size_t** dp = new size_t*[s_len + 1];
    for (size_t i = 0; i < s_len + 1; ++i) {
        dp[i] = new size_t[t_len + 1]();
    }

    for (int i = s_len - 1; i >= 0; --i) {
        for (int j = t_len - 1; j >= 0; --j) {
            if (*(s_first + i) == *(t_first + j)) {
                dp[i][j] = 1 + dp[i + 1][j + 1];
            } else {
                dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
            }
            //printf("dp[%d][%d] = %d\n", i, j, dp[i][j]);
        }
    }

    size_t result = dp[0][0];

    for (size_t i = 0; i < s_len + 1; ++i) {
        delete [] dp[i];
    }
    delete [] dp;

    return result;
}

template<class Iterator>
vector<pair<size_t, size_t> > construct_lcs(Iterator s_first, Iterator s_last, Iterator t_first, Iterator t_last) {
    const size_t s_len = distance(s_first, s_last);
    const size_t t_len = distance(t_first, t_last);

    size_t** dp = new size_t*[s_len + 1];
    for (size_t i = 0; i < s_len + 1; ++i) {
        dp[i] = new size_t[t_len + 1]();
    }

    for (int i = s_len - 1; i >= 0; --i) {
        for (int j = t_len - 1; j >= 0; --j) {
            if (*(s_first + i) == *(t_first + j)) {
                dp[i][j] = 1 + dp[i + 1][j + 1];
            } else {
                dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }

    vector<pair<size_t, size_t> > result;
    size_t x = 0;
    size_t y = 0;
    while (x < s_len && y < t_len) {
        if (dp[x][y] == dp[x + 1][y]) {
            ++x;
        } else if (dp[x][y] == dp[x][y + 1]) {
            ++y;
        } else {
            result.push_back(pair<size_t, size_t>(x, y));
            ++x;
            ++y;
        }
    }

    for (size_t i = 0; i < s_len + 1; ++i) {
        delete [] dp[i];
    }
    delete [] dp;

    return result;
}

int main(void)
{
    string s, t;
    cin >> s >> t;
    //cout << lcs(all(s), all(t)) << endl;
    auto v = construct_lcs(all(s), all(t));
    REP(i, v.size()) {
        cout << s[v[i].first];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 70784