#include <bits/stdc++.h>

using namespace std;

string s, t;

int main(){
	cin >> s >> t;
	int aux[s.size()+1][t.size()+1];

	for(int i=0; i<=s.size(); i++){
		for(int j=0; j<=t.size(); j++){
			if(i==0 || j==0){
				aux[i][j] = 0;
			}
			else if(s[i-1] == t[j-1]){
				aux[i][j] = aux[i-1][j-1] + 1;
			}
			else{
				aux[i][j] = max(aux[i-1][j], aux[i][j-1]);
			}
		}
	}

	string lcs;
	int i=s.size(), j=t.size();
	while(i!=0 && j!=0){
		if(aux[i][j]-1 == aux[i-1][j-1] && aux[i-1][j] == aux[i-1][j-1] && aux[i][j-1] == aux[i-1][j]){
			lcs = s[i-1] + lcs;
			i--; j--;
		}
		else if(aux[i][j] == aux[i-1][j-1] && aux[i-1][j] == aux[i-1][j-1] && aux[i][j-1] == aux[i-1][j]){
			i--; j--;
		}
		else if(aux[i][j]-1 == aux[i-1][j-1] && aux[i][j-1] == aux[i][j]){
			j--;
		}
		else if(aux[i][j]-1 == aux[i-1][j-1] && aux[i-1][j] == aux[i][j]){
			i--;
		}
	}

	cout << lcs << endl;
}

