function main() {
  var
  i,
  word, longer, words,
  max, maxStr,
  words = input[0].split(' '),
  len = words.length,
  dict = {};
  for(i = 0; i < len; i++) {
    word = words[i].toLowerCase();
    dict[word] = (dict[word] || 0) + 1;
  }
  max = 0;
  longer = '';
  Object.keys(dict).forEach(function(word) {
    if(dict[word] > max) {
      max = dict[word];
      maxStr = word;
    }
    if(word.length > longer.length) {
      longer = word;
    }
  });
  console.log('%s %s', maxStr, longer);
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});