/*
 * zyrch - Rupanshu Yadav
 */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
 
#define forn(i,a,b) for (int i = (a); i < ll(b); ++i)
#define fo(i,a) forn(i,0,ll(a))
#define rforn(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define ro(i,a) rforn(i,0,a)
#define trav(a,x) for (auto& a: x)
 
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
 
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first

ll mod = 1000000007;
inline int fast_expo(int base,int power,int modulo=mod){
    base%=modulo;
    if (base<0) base+=modulo;
    ll x=base,cnt=power,ans=1;
    while(cnt){
        if (cnt&1) ans=(ans*x)%modulo;
        x=(x*x)%modulo;
        cnt>>=1;
    }
    return ans;
}
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
const ll INF = 1e11;
//=========================CODE STARTS HERE=============================//

int main() {
	fast_cin();
 
	string a, b;
	cin >> a >> b;
	
	ll dp[a.length()][b.length()];
	ll n = a.length(), m = b.length();
	
	dp[0][0] = a[0] == b[0];
	
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			
			if(i == 0 && j == 0) {
				continue;
			}
			
			if (i == 0) {
				if (a[0] == b[j])dp[i][j] = 1;
				else {
					dp[i][j] = dp[i][j - 1];
				}continue;
			}
			
			if (j == 0) {
				if (a[i] == b[j])dp[i][j] = 1;
				else {
					dp[i][j] = dp[i - 1][j];
				}
				continue;
			}
			
			if (a[i]==b[j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
				continue;
			}
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	
	//fo(i, n){fo(j, m){cout << dp[i][j] << " "; } cout << endl;}
	
	string ans = "";
	for (int i = n - 1; i > -1;) {
		for (int j = m - 1; j > -1;) {
		//	debug(i,j);
			if (i == 0 && j == 0) break;
			
			if (i == 0) {
				if (dp[i][j] - dp[i][j - 1] == 1) {
					ans += b[j];
				}
				j--;
				continue;
			}else if (j == 0) {
				if (dp[i][j] - dp[i - 1][j] == 1) {
					ans += a[i];
				}
				--i;
				continue;
			}
			
			
			
			if (dp[i][j] - dp[i - 1][j - 1] == 1 && dp[i][j] - dp[i - 1][j] == 1 && dp[i][j] - dp[i][j - 1] == 1) {
				ans += a[i];
				j--;
				i--;
			}else {
				//debug(dp[i - 1][j] > dp[i][j - 1], dp[i - 1][j] , dp[i][j - 1]);
				if (dp[i - 1][j] > dp[i][j - 1]) {
				//	debug("er", i, j);
					i--;
				//	debug("re", i, j);
				}else {
					j--;
				}
			}
			
			
		}
		break;
	} 
	
	if (a[0] == b[0]) ans += a[0];
	
	////cout << dp[n- 1][m -1]<< endl;

	ro(i, ans.length()) {
		cout << ans[i];
	}cout << endl;
		
	
    return 0;
}


Measured memory_bytes: 70656