let memoize n f =
  let dp = Hashtbl.create n in
  let rec get x =
    try Hashtbl.find dp x with
    | Not_found ->
        let result = f get x in
        Hashtbl.add dp x result;
        result in get

let () =
  let s = read_line () in
  let t = read_line () in
  let dp = memoize (String.length s * String.length t) @@ fun dp -> function
    | (-1, _) -> (0, [])
    | (_, -1) -> (0, [])
    | (i, j) ->
        if s.[i] = t.[j] then
          let (l, cs) = dp (i - 1, j - 1) in
          (l + 1, s.[i] :: cs)
        else
          let (l, cs) = dp (i, j - 1) in
          let (l', cs') = dp (i - 1, j) in
          if l <= l' then (l', cs') else (l, cs) in
  (List.iter print_char @@ List.rev @@ snd @@ dp (String.length s - 1, String.length t - 1));
  print_newline () 

