a = gets.chomp.split.sort
n = a.size

mwc = 0
mw = mx = a[0]
c = 1
1.upto(n-1) { |i|
  if mx == a[i]
    c += 1
  elsif c > mwc
    mw = mx
    mx = a[i]
    c = 1
  else
    mx = a[i]
    c = 1
  end
}
if c > mwc
  mw = mx
end

lwc = 0
lw = a[0]
a.each { |x|
  if x.length > lwc
    lw = x
    lwc = x.length
  end
}

puts mw + " " + lw