#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
	string s1,s2,s3;
	char s[5000],c;
	int m1=0,m2=0;
	map<string,int>mp;
	while(c=getchar())
	{
		if(c=='\n')break;
		if(c!=' ')
		{
			s1+=c;
		}
		else
		{
			if(mp.find(s1)==mp.end())mp[s1]=1;
			else mp[s1]++;
			if(mp[s1]>m1)
			{
				m1=mp[s1];
				s2=s1;
			}
			if(s1.size()>m2)
			{
				m2=s1.size();
				s3=s1;
			}
			s1.erase();
		}
	}
	if(mp[s1]>m1)
			{
				m1=mp[s1];
				s2=s1;
			}
			if(s1.size()>m2)
			{
				m2=s1.size();
				s3=s1;
			}
			s1.erase();
	cout<<s2<<" "<<s3<<endl;
	return 0;
}