/******
author :- Mahmoud Tarek.
*******/

#include<bits/stdc++.h>

using namespace std ;

#define rg register
#define dbg(v) cerr << #v << " " << v ;
typedef long long ll ;

string a, b ;
int n, m, idx ;
int mem[4000][4000] ;
char ans[4000] ;

int gen(int i, int j){
if(i == n || j == m){
    return 0;
}
int & ret = mem[i][j] ;
if(~ret) return ret ;
ret = 0 ;
if(a[i] == b[j]){
    ret = 1 + gen(i + 1, j + 1) ;
}
int mx = max(gen(i + 1, j), gen(i, j + 1)) ;
ret = max(ret, mx) ;
return ret ;
}

bool prn = 0 ;

void print(int i, int j){
if(i == n || j == m){
    if(!prn){
        for(int k = 0 ; k < idx ; k++) cout << ans[k] ;
        prn = 1 ;
    }
    return;
}
int ret = gen(i, j) ;
if(ret == 1 + gen(i + 1, j + 1)){
    ans[idx++] = a[i] ;
    print(i + 1, j + 1) ;
    idx--;
}

if(ret == gen(i + 1, j)){
    print(i + 1, j) ;
}

if(ret == gen(i, j + 1)){
    print(i, j + 1) ;
}

}

int main() {
//    freopen("in.txt", "r", stdin) ;
      cin >> a >> b ;
      n = a.size(), m = b.size() ;
      memset(mem, -1, sizeof mem) ;
      gen(0, 0) ;
      print(0, 0) ;
}

/*
  Empty set of troubles.
*/
