
let max_str slst = 
  snd @@ List.fold_left (fun (mx, s) (x, y) -> if mx < x then (x, y) else (mx, s)) (0,"") @@ List.map (fun x -> (String.length x, x)) slst

let mf_str slst = 
  let tbl = Hashtbl.create 1000 in
  List.iter (fun x -> if Hashtbl.mem tbl x then Hashtbl.add tbl x (Hashtbl.find tbl x + 1) else Hashtbl.add tbl x 1) slst;
  fst @@ Hashtbl.fold (fun x y (s, n) -> if y >= n then (x, y) else (s, n)) tbl ("",0)

let _ =
  let slst = Str.split (Str.regexp " ") (read_line ()) in
  Printf.printf "%s %s\n" (mf_str slst) (max_str slst)