'use strict';

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var strlist = input.trim().split(' ');
//var strlist = 'Thank you for your mail and your lectures'.split(' ');
var strhash = {};
var maxlen = 0;
var lststr = '';
for (var i in strlist) {
	if (strlist[i] in strhash) {
		strhash[strlist[i]] += 1;
	} else {
		strhash[strlist[i]] = 1;
	}
	if (strlist[i].length > maxlen) {
		lststr = strlist[i];
		maxlen = strlist[i].length;
	}
}
var most = 0;
var mststr = '';
for (var property in strhash) {
	if (strhash[property] > most) {
		mststr = property;
		most = strhash[property];
	}
}
console.log(mststr + ' ' + lststr);