/*AOJ 0029*/

#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){

	vector<string> data;

	char str[35];

	while(cin>>str){
		data.push_back(str);
	}

	int max=0;
	int maxNum = 0;
	int sum=0;

	for(int i=0;i<data.size();i++){
		sum = 0;
		for(int j=i+1;j<data.size();j++){
			if(data.at(i) == data.at(j)){
				sum++;
			}
		}
		if(max<=sum){
			max = sum;
			maxNum = i;
		}
	}

	cout<<data.at(maxNum)<<endl;

	max = 0;
	maxNum = 0;

	for(int i=0;i<data.size();i++){
		if(max <= data.at(i).size()){
			max = data.at(i).size();
			maxNum = i;
		}
	}

	cout<<data.at(maxNum)<<endl;


	return 0;
}