'use strict';
(function(input){
  input=input.trim().split(/\n/);
  const s=input[0];
  const S=s.length;
  const t=input[1];
  const T=t.length;
  const dp=new Array(S+1).fill('場所取り').map(x=>new Array(T+1).fill(0));
  //console.log(dp);
  for(let i=0;i<S;i++){
    for(let j=0;j<T;j++){
      let cs=s[i];
      let ct=t[j];
      if(cs===ct){
        dp[i+1][j+1]=dp[i][j]+1;
      }else{
        dp[i+1][j+1]=Math.max(dp[i][j+1],dp[i+1][j]);
      }
    }
  }
  console.log(dp);
  var ans='';
  var I=S,J=T;
  while(I>0&&J>0){
    //console.log(I,J);
    if(dp[I][J]===dp[I][J-1])
      J--;
    else if(dp[I][J]===dp[I-1][J])
      I--;
    else{
      ans=s[I-1]+ans;
      I--;
      J--;
    }
  }
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));
