#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	string str, longest, s, most;
	int m=0, count=0;
	vector<string> vs;
	vector<int>vi;
	getline(cin, str);
	for(int i=0; i<str.length(); i++){
		if(str[i]!=' ' && str[i]!='\n'){
			s+=str[i];
		}
		else{
			vs.push_back(s);
			if(s.length()>m){
				m=s.length();
				longest=s;
			}
			s="";
		}
	}
	if(s.length()>m){
		m=s.length();
		longest=s;
	}
	m=0;
	for(int i=0; i<vs.size()-1; i++){
		count=0;
		for(int j=i+1; j<vs.size(); j++){
			if(vs[i]==vs[j])
				count++;
		}
		if(count>m){
			m=count;
			most=vs[i];
		}
	}
	cout<<most<<" "<<longest<<endl;
	return 0;
}


