#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define mp make_pair
using namespace std;
const int N = 3030;
char s[N], t[N];
int dp[N][N];
pii from[N][N];
bool flag[N][N];
void print(int i, int j)
{
if (i == -1 && j == -1)
return ;
print(from[i][j].first, from[i][j].second);
if (s[i] == t[j])
putchar(s[i]);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin >> (s + 1) >> (t + 1);
int lens = strlen(s + 1), lent = strlen(t + 1);
for (int i = 0;i <= lens;i++)
for (int j = 0;j <= lent;j++)
from[i][j].first = -1, from[i][j].second = -1;
for (int i = 1;i <= lens;i++)
for (int j = 1;j <= lent;j++)
{
if (dp[i-1][j] > dp[i][j-1])
dp[i][j] = dp[i-1][j], from[i][j] = mp(i-1,j);
else
dp[i][j] = dp[i][j-1], from[i][j] = mp(i,j-1);
if (s[i] == t[j])
dp[i][j] = dp[i-1][j-1], from[i][j] = mp(i-1,j-1);
}
print(lens,lent);
return 0;
}