#include<bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////*kedar1514*////////////////////////////////////////////////(Template Start)*****
#define endl "\n"
#define ll long long
#define fo(i,n)                     for(i=0;i<n;i++)
#define Fo(i,n)                     for(i=1;i<=n;i++)
#define si(x)                       scanf("%d",&x)
#define sl(x)                       scanf("%lld",&x)
#define ss(s)                       scanf("%s",s)
#define pi(x)                       printf("%d\n",x)
#define pl(x)                       printf("%lld\n",x)
#define ps(s)                       printf("%s\n",s)
#define all(x)                      x.begin(),x.end()
#define allr(x)                     x.rbegin(),x.rend()
#define sortAll(x)                  sort(all(x))   
#define clearAll(arr)               memset(arr,0,sizeof(arr))
#define deb(sum)                    cout<<"deb = "<<sum<<endl;
#define pb                          push_back
#define mp                          make_pair
#define F                           first
#define S                           second
#define PI                          3.1415926535897932384626
typedef pair<int, int>              pii;
typedef pair<long long, long long>  pll;
typedef vector<int>                 vi;
typedef vector<long long>           vl;
typedef vector<pii>                 vpii;
typedef vector<pll>                 vpll;
#define kedar ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll powerMod(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
	if (n & 1)
	  res = (res * x) % mod;
	x = (x * x) % mod;
	n >>= 1;
  }
  return res;
}

ll power(ll x, ll n) {
  ll res = 1;
  while (n) {
	if (n & 1)
	  res = (res * x);
	x = (x * x);
	n >>= 1;
  }
  return res;
}

int gcd(int A, int B) {
    if(B==0)
        return A;
    else
        return gcd(B, A % B);
}
////////////////////////////////////////////////*kedar1514*////////////////////////////////////////////////(Template ends)*****
//  <<,
//  , cout<<<<endl;
 
/*string lcs(string s, string t, int n, int m)
{
  string ans ="";
  if(n==0 || m==0)
  {
    return ans;
  }
  if(dp[n][m]!='1')
  {
    return dp[n];
  }
  if(s[n-1]==t[m-1])
  {
    ans += s[n-1];
    ans += lcs(s, t, n-1, m-1); 
    return dp[n] = ans;
  }
  else
  {
    string temps = lcs(s, t, n-1, m);
    int ss=temps.size();
    string tempr = lcs(s, t, n, m-1);
    int r=tempr.size();
    if(ss>=r)
    {
      ans += temps;
    }
    else if(r>ss)
    {
      ans += tempr;
    }
  }
  return dp[n] = ans;
}*/
 
void solve()
{
  string s;
  string t;
  cin>>s>>t;
  int n=s.size()+1;
  int m=t.size()+1;
  int dp[n][m];
  memset(dp,0,sizeof(dp));
  for (int i = 1; i < n; i++)
  {
    for (int j = 1; j < m; j++)
    {
      if(s[i-1]==t[j-1])
      {
        dp[i][j] = 1 + dp[i-1][j-1];
      }
      else
      {
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
    }
  }
  int i=n;
  int j=m;
  string ans;
  while(i>0 && j>0)
  {
    if(s[i-1]==t[j-1])
    {
      ans.push_back(s[i-1]);
      --i;
      --j;
    }
    else
    {
      if(dp[i][j-1]>dp[i-1][j])
      {
        j--;
      }
      else
      {
        i--;
      }
    }
  }
  reverse(all(ans));
  ans.pop_back();
  cout<<ans;
}

int main(){
    kedar;
// <<
//  <<,
//  ,

    ll t=1;
    //cin>>t;
    while(t--)
    {     
        solve();
    }
    return 0;
}// <<
//  <<,
//  ,


Measured memory_bytes: 35456