# https://atcoder.jp/contests/dp/tasks/dp_f

S = gets.chomp
T = gets.chomp

def replace_next_larger(enum, value, last_index = nil)
  # Off the end?
  if enum.empty? or (value > enum[-1])
    enum << value
    return enum.size - 1
  end

  # Binary search for the insertion point
  last_index ||= enum.size
  first_index = 0
  while first_index <= last_index
    i = (first_index + last_index) >> 1

    found = enum[i]

    return nil if value == found

    if value > found
      first_index = i + 1
    else
      last_index = i - 1
    end
  end

  # The insertion point is in first_index; overwrite the next larger
  # value.
  enum[first_index] = value
  first_index
end


def position_hash(enum, interval)
  string = enum.kind_of?(String)
  hash = Hash.new { |h, k| h[k] = [] }
  interval.each do |i|
    k = string ? enum[i, 1] : enum[i]
    hash[k] << i
  end
  hash
end

def lcs(a, b)
  a_start = b_start = 0
  a_finish = a.size - 1
  b_finish = b.size - 1
  vector = []

  # Prune off any common elements at the beginning...
  while (a_start <= a_finish) and (b_start <= b_finish) and (a[a_start] == b[b_start])
    vector[a_start] = b_start
    a_start += 1
    b_start += 1
  end
  b_start = a_start

  # Now the end...
  while (a_start <= a_finish) and (b_start <= b_finish) and (a[a_finish] == b[b_finish])
    vector[a_finish] = b_finish
    a_finish -= 1
    b_finish -= 1
  end

  # Now, compute the equivalence classes of positions of elements.
  b_matches = position_hash(b, b_start..b_finish)

  thresh = []
  links  = []
  string = a.kind_of?(String)

  (a_start..a_finish).each do |i|
    ai = string ? a[i, 1] : a[i]
    bm = b_matches[ai]
    k = nil
    bm.reverse_each do |j|
      if k and (thresh[k] > j) and (thresh[k - 1] < j)
        thresh[k] = j
      else
        k = replace_next_larger(thresh, j, k)
      end
      links[k] = [k.positive? ? links[k - 1] : nil, i, j] unless k.nil?
    end
  end

  unless thresh.empty?
    link = links[thresh.size - 1]
    until link.nil?
      vector[link[1]] = link[2]
      link = link[0]
    end
  end

  vector
end

lcs(S, T).each_with_index do |e, i|
  print S[i] unless e.nil?
end
