#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;

int main()
{
	int longest=0;
	string str,tmp="",freq="";
	vector<string> strs;
	map<string,int> m;
	
	getline(cin,str);

	for(int i=0;i<str.size(); ++i){
		if((str[i] != ' ' )&&(i != str.size()-1)){
			tmp += str[i];
		}else{
			strs.push_back(tmp);
			tmp = "";
		}
	}
	
	for(int i=0;i<strs.size();++i){
		if(strs[i].size() > strs[longest].size())
			longest = i;
		
		bool flag = false;
		for(map<string,int>::iterator it = m.begin();it != m.end();++it){
			if(strs[i] == it->first){
				flag == true;
				it->second++;
			}
		}
		if(flag == false)
			m.insert(make_pair<string,int>(strs[i],0));
	}

	for(map<string,int>::iterator it = m.begin();it != m.end();++it){
		if(it->second > freq.size())
			freq = it->first;
	}
	
	cout << freq << " " << strs[longest] << endl;
	
	return 0;
}