#include <string>
#include <map>
#include <iostream>
using namespace std;
int main() 
{
	map<string,int> table;
	string word,frequent,longest;
	size_t N=0;
	while(cin>>word)
	{
		table[word]++;
		if(table[word]>N)
		{
			N=table[word];
			frequent=word;
		}
		if(word.size()>longest.size())
			longest=word;
	}
	cout<<frequent<<" "<<longest<<endl;
}