#include<bits/stdc++.h>
using namespace std;
typedef map<string,int>M;
int main(void)
{
	string s,t;
	string ss,tt;
	int nn,mm,cnt;
	int i;
	int lMAX,sMAX;
	M mp;
	getline(cin,s);
	s+=' ';
	for(i=0;i<(int)s.size();i++){
		//cout<<s[i]<<endl;
		if(s[i]==' '){
			//cout<<t<<endl;
			mp[t]++;
			t="";
		}
		else	t+=s[i];
	}
	lMAX=sMAX=-1;
	for(auto it=mp.begin();it!=mp.end();it++){
		//cout<<it->first<<" "<<it->second<<endl;
		s=it->first;
		cnt=it->second;
		if(sMAX<cnt){
			sMAX=cnt;
			ss=s;
		}
		if(lMAX<(int)s.size()){
			lMAX=(int)s.size();
			tt=s;
		}
	}
	cout<<ss<<" "<<tt<<endl; 
	return 0;
}
		
		
