#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main(void)
{
	string str, lon = "", most = "";
	map <string, int> count;
	while (cin >> str)
	{
		if (str.size() > lon.size()) lon = str;
		count[str]++;
		if (count[most] < count[str]) most = str;
	}
	cout << most << " " << lon << endl;
	return 0;
}
