let hash = Hashtbl.create 32;;

let update x =
  if Hashtbl.mem hash x then
    Hashtbl.replace hash x ((Hashtbl.find hash x)+1)
  else
    Hashtbl.add hash x 1
;;

let max_len  max s =
  let len = String.length s in
  if len > (fst max) then (len, s) else max
;;

let () =
  let s = read_line ()
          |> Str.split (Str.regexp " ") and
      max = ref (0, "") and
      freq = ref (0, "")
  in
  List.iter (fun x -> max := max_len (!max) x;update x) s;
  Hashtbl.iter (fun key value -> if value > (fst (!freq)) then freq := (value, key)) hash;
  Printf.printf "%s %s\n" (snd (!freq)) (snd (!max))
;;