'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(new Array(T+1).fill(0));
  for(let i=1;i<=S;i++){
    for(let j=1;j<=T;j++){
      let cs=s[i-1],ct=t[j-1];
      if(cs===ct)
        dp[i][j]=1+Math.max(dp[i-1][j],dp[i][j-1]);
      else dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
    }
  }
  var ans='';
  var I=S,J=T;
  while(I>0&&J>0){
    if(dp[I][J]===dp[I][J-1])
      J--;
    else if(dp[I][J]===dp[I-1][J])
      I--;
    else if(dp[I][J]===dp[I][J-1]+1){
      ans=s[I-1]+ans;
      J--;
    }else{
      ans=s[I-1]+ans;
    }
  }
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));