import std.algorithm, std.stdio, std.string;

string longer(string x, string y) {
  if (x.length < y.length) return y;
  return x;
}

void main() {
  const s = readln.chomp;
  const t = readln.chomp;
  
  struct A { string ans; long last_si = -1; }
  
  auto dp0 = new A[s.length];
  auto dp1 = new A[s.length];
  
  foreach (long ti; 0..t.length) {
    foreach (long si; 0..s.length) {
      dp1[si] = dp0[si];
      
      if (si >= 1) {
        const a = dp1[si], b = dp1[si-1];
        if (a.ans.length < b.ans.length || a.ans.length == b.ans.length && a.last_si > b.last_si) {
          dp1[si] = b;
        }
      }
      if (si > dp1[si].last_si && s[si] == t[ti]) {
        dp1[si].ans    ~= s[si];
        dp1[si].last_si = si;
      }
    }
    swap(dp0, dp1);
    dp1[] = A();
  }
  dp0[$-1].ans.writeln;
} 