#include<bits/stdc++.h>
using namespace std;
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vl>;
using vii = vector<vi>;
using pii = pair<int, int>;

using vc = vector<char>;
using vcc = vector<vc>;
using vb = vector<bool>;
using vbb = vector<vb>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using vd = vector<double>;
using vdd = vector<vd>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


const int MOD = 1e9 + 7;

vector<pii> prime_factorization(int n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pii> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}
vector<pli> prime_factorization(ll n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pli> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}

// n は 2以上の素数表を返す
vb Primes(int n){
  vector<bool> res(n + 1, true);
  res.at(0) = false; res.at(1) = false;
  for(int i = 2; i <= sqrt(n); i++){
    if(res.at(i)){
      for(int j = 2 * i; j <= n; j += i){
        res.at(j) = false;
      }
    }
  }
  return res;
}
// ===================================================

using vs = vector<string>;
using vss = vector<vs>;

int main(){
  string s, t, res; cin >> s >> t;
  int s_size = s.size(), t_size = t.size();
  vii dp(s_size + 1, vi(t_size + 1, 0));
  /*
  vss dp(s_size + 1, vs(t_size + 1, ""));
  /*
  * dp[i][j] := { s の i番目まで, t の j番目までの最長部分共通文字列 }
  * dp[i][j] = "" (if i == 0 or j == 0)
  * dp[i][j] = { dp[i -1][j - 1] + 'x' (when s[i] = t[j] = x)
  *            { longer( dp[i - 1][j], dp[i][j - 1] ) (when s[i] != t[j])
  *   ---> DP[i][j] = dp[i][j].size();
  */
  for(int i = 1; i <= s_size; i++){
    for(int j = 1; j <= t_size; j++){
      if(s[i - 1] == t[j - 1]){
        dp[i][j] = dp[i - 1][j - 1] + 1;
      }
      else{
        dp[i][j] = MAX(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }
  // size -> string : 復元
  while(s_size > 0 && t_size > 0){
    if(dp[s_size][t_size] == dp[s_size - 1][t_size]) s_size--;
    else if(dp[s_size][t_size] == dp[s_size][t_size - 1]) t_size--;
    else{
      res = s[s_size - 1] + res;
      s_size--;t_size--;
    }
  }
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 35584