#!/usr/bin/ruby

input = gets.split
max_a = input.inject(Hash.new(0)){|h,i| h[i] += 1;h}
max_b = input.inject(Hash.new(0)){|h,i| h[i] = i.length;h}
max_b = max_b.to_a.sort{|x| x[1]}[0][0]
puts "#{max_a.max[0]} #{max_b}"