#include<bits/stdc++.h>
#define ll long long int
#define inf 1000000000000
#define MOD 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define for0(i, n) for (int i = 0; i < n; i++)
#define tc(t) int t; cin >> t; while (t--)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ps(x,y)         fixed<<setprecision(y)<<x
using namespace std;
/*int dp[100001][3];
int vacation(int mat[][3], int prev, int curr, int n)
{
	if (curr == n)
		return 0;
	/*if (dp[curr][prev] != -1)
		return dp[curr][prev];
	if (dp[curr][prev] != -1)
	{
		return dp[curr][prev];
	}
	int res = 0;
	int demo = 0;
	for (int j = 0; j < 3; j++)
	{
		if (j != prev)
		{
			demo = mat[curr][j] + vacation(mat, j, curr + 1, n);
			res = max(res, demo);
		}

	}
	return dp[curr][prev] = res;
}
int main()
{
	IOS
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int mat[n][3];
	int arr[n];
	for (int i = 0; i < 100001; i++)
		for (int j = 0; j < 3; j++)
			dp[i][j] = -1;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
			cin >> mat[i][j];
	}
	int res = 0;
	for (int i = 0; i < 3; i++)
	{
		int demo = mat[0][i] + vacation(mat, i, 1, n);
		res = max(demo, res);
	}
	//res = vacation(mat, -1, 0, n);
	cout << res << endl;
}
*/
/*#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll arr[100007][3];
ll n;
ll dp[100007][3];
ll recur(ll i,ll j){
    ll sum=0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    else if(i==n)
        return 0;
    for(int x=0;x<3;x++){
        if(x!=j)
        sum=max(sum,arr[i][j]+recur(i+1,j));}
    dp[i][j]=sum;
    return dp[i][j];
}
int main(){
    cin>>n;
    ll maxi=0;
    for(ll i=0;i<n;i++){
    for(ll p=0;p<3;p++){
        cin>>arr[i][p];}}
    memset(dp,-1,sizeof(dp));
    for (int i = 0; i < 3; i++)
	{
		maxi = max(arr[0][i] + recur(1,i), maxi);
	}
    cout<<maxi<<endl;
    return 0;
}

int dp[100007];
ll arr[100007];
int recur(ll i,ll n,ll k){
ll mini=INT_MAX;
 if(dp[i]!=-1){
   return dp[i]; }
 else if(i>=n)
    dp[i]=INT_MAX;
 else if(i==n-1)
    dp[i]=0;
 else{
    for(ll j=1;j<=k;j++){
        mini=min(mini,recur(i+j,n,k)+abs(arr[i+j]-arr[i]));
    }
    dp[i]= mini;
 }
 return dp[i];
}
int main(){
    ll n,k;
    cin>>n>>k;
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<recur(0,n,k)<<endl;
    return 0;
}

ll per[101];
ll up[101];
ll lo[101];
ll n,m;
int main(){
    ll t;
    cin>>t;
    while(t--){
        cin>>n>>m;
        for(ll i=0;i<n;i++)
            cin>>per[i]>>lo[i]>>up[i];
        ll low=m,high=m,prev=0;
        bool flag=true;
       for(ll i=0;i<n;i++){
            high+=per[i]-prev;
            low-=per[i]-prev;
        if(low>up[i] || high<lo[i]){
                flag=false;
           break;

        }
        else{
            low=max(lo[i],low);
            high=min(up[i],high);
            prev=per[i];
           }
       }
       if(flag==true)
          cout<<"YES"<<endl;
       else
          cout<<"NO"<<endl;
    }
    return 0;
}int n=3;
 int a[]={1,7,10};
 int sum=0;
 int *dp=new int[17];
int mincoin(int am){
    if(am==0)
        return 0;
//else if(am<0)
       // return 0;
    if(dp[am]!=INT_MAX)
        return dp[am];
    int mini=INT_MAX;
    for(int i=0;i<n;i++){
        if(am-a[i]>=0)
          {mini=min(mini,mincoin(am-a[i])+1);
          dp[am]=mini;
          }}
    return dp[am];
}
/*int buttomup(int am,int a[],int n){
    int *dp=new int[am+1];
    for(int i=0;i<=am;i++)
        dp[i]=INT_MAX;
    dp[0]=0;
    for(int i=0;i<n;i++)
        dp[a[i]]=1;
    for(int amo=1;amo<=am;amo++){
        for(int i=0;i<n;i++){
            if(amo-a[i]>=0){
                int lala=dp[amo-a[i]];
                 if(lala!=INT_MAX)
                  dp[amo]=min(dp[amo],lala+1);
        }
    }
    }
    return dp[am];
}
int main(){

    int amount=15;
    for(int i=0;i<=amount;i++)
        dp[i]=INT_MAX;
    cout<<mincoin(amount);
    return 0;
}

//knapsack problem

int dp[40][6];
int napsack(int cap,int wt[],int price[],int n){

    if(n==0 || cap<=0)
        return 0;
    if(dp[cap][n]!=-1)
        return dp[cap][n];
    else if(wt[n-1]>cap){
        dp[cap][n]=napsack(cap,wt,price,n-1);
    }
    else
        dp[cap][n]= max(napsack(cap-wt[n-1],wt,price,n-1)+price[n-1],napsack(cap,wt,price,n-1));
    return dp[cap][n];
}
int buttom(int cap,int wt[],int price[],int n){

    //
    //if(dp[cap][n]!=-1)
       // return dp[cap][n];
      for(int i=0;i<=n;i++){
 for(int j=0;j<=cap;j++){
                if(i==0 || j==0)
                    dp[i][j]=0;
                else if(wt[i-1]<=j)
                  dp[i][j]=max(price[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
                else
                   dp[i][j]=dp[i-1][j];
            }
        }
    return dp[n][cap];
}
int main(){
    int n=4;
    int wt[]={2,7,3,4};
    int price[]={5,20,20,10};
    int cap=11;
      memset(dp,-1,sizeof(dp));
    cout<<napsack(cap,wt,price,n);
}

*/

int main(){
    string s,t;
    cin>>s>>t;
    int m=s.size();
    int n=t.size();
    int L[m+1][n+1];
    int i,j;
    for(i=0;i<=m;i++){
        for(j=0;j<=n;j++){
            if(i==0 || j==0)
              L[i][j]=0;
            else if(s[i-1]==t[j-1])
              L[i][j]=1+L[i-1][j-1];
            else
                L[i][j]=max(L[i][j-1],L[i-1][j]);
        }
    }
    int index=L[m][n];
    char a[index+1];
    a[index]='\0';
    i=m;j=n;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            a[index-1]=s[i-1];
            i--;j--;index--;
        }
        else if(L[i-1][j]>L[i][j-1])
            i--;
        else
            j--;
    }
    cout<<a<<endl;
   return 0;
}


Measured memory_bytes: 35456