#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(ll key, ll value){
      this->key = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

typedef pair<int, string> P;

/*
void long_search(const string& s, const string& t, const int st_start, vector<string>& dp1, vector<string>& dp2){

  if(st_start+1 <= s.size() + t.size() + 2) long_search(s, t, st_start+1, dp1, dp2);
  
  int hight = min(st_start+1, (int)s.size());
  for(int s_start=max(0, st_start-(int)t.size()+1); s_start<hight; ++s_start){
    int t_start = st_start-s_start;

    if(s[s_start] == t[t_start]){
      dp2[s_start] = s[s_start] + dp2[s_start+1];
    }else if(dp1[s_start].size() > dp1[s_start+1].size()){
      dp2[s_start] = dp1[s_start];
    }else{
      dp2[s_start] = dp1[s_start+1];
    }
    swap(dp1[s_start], dp2[s_start]);
  }
  swap(dp1[hight], dp2[hight]);

  return;
}
*/
void long_search(const string& s, const string& t, const int& s_size, const int& t_size, const int st_start, vector<P>& dp1, vector<P>& dp2){

  if(st_start+1 <= s_size + t_size + 2) long_search(s, t, s_size, t_size, st_start+1, dp1, dp2);
  
  int hight = min(st_start+1, s_size);
  for(int s_start=max(0, st_start-t_size+1); s_start<hight; ++s_start){
    int t_start = st_start-s_start;

    if(s[s_start] == t[t_start]){
      dp2[s_start].first = 1 + dp2[s_start+1].first;
      dp2[s_start].second = s[s_start] + dp2[s_start+1].second;
    }else if(dp1[s_start].first > dp1[s_start+1].first){
      dp2[s_start] = dp1[s_start];
    }else{
      dp2[s_start] = dp1[s_start+1];
    }
    swap(dp1[s_start], dp2[s_start]);
  }
  swap(dp1[hight], dp2[hight]);

  return;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string s, t;
  cin >> s >> t;
  if(s.size() > t.size()) swap(s, t);
  /*
  vector<string> dp1(s.size()+2, "");
  vector<string> dp2(s.size()+2, "");
  long_search(s, t, 0, dp1, dp2);
  */
  vector<P> dp1(s.size()+2, P(0, ""));
  vector<P> dp2(s.size()+2, P(0, ""));
  long_search(s, t, (int)s.size(), (int)t.size(), 0, dp1, dp2);

  cout << dp1[0].second << "\n";

  return 0;
}

Measured memory_bytes: 12032