#include<iostream>
#include <stdio.h>
#include<string>
using namespace std;
string s[1000], t,ma,hi; int i=0,j[1000],times=0;
int main() {
	while (cin>>s[i])
	{
		for (int q=0; q < i; q++) {
			if (s[i] == s[q]) { j[q]++; }if (j[q] > times) { hi = s[q]; times = j[q]; }
	}
		if (ma.size() < s[i].size())ma = s[i];
		i++;
	}
	cout << hi << " " << ma<<endl;
	return 0;
}
