#include <iostream>
#include <string>
#include <map>

using namespace std;
int main()
{
	map<string,int> table;
	string S;
	int mostAppear = 0;
	string mostAppearW;
	int maxSize = 0;
	string maxSizeW;
	while(cin >> S)
	{
		if (table.count(S))
		{
			table[S]++;
		}
		else
		{
			table[S] = 1;
		}

		if (table[S] > mostAppear)
		{
			mostAppear = table[S];
			mostAppearW = S;
		}		

		if (S.size() > maxSize)
		{
			maxSize = S.size();
			maxSizeW = S;
		}
	}

	cout << mostAppearW << " " << maxSizeW << endl;

	return 0;
}
