#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef pair<string, int> PAIR;

int main(){
	vector<PAIR> vec;
	vector<PAIR>::iterator ite;
	string st;
	while(cin >> st){
		ite = vec.begin();
		if(vec.empty()){
			vec.push_back(PAIR(st, 1));
		}else{
			while(1){
				if((*ite).first == st){
					(*ite).second++;
					break;
				}
				ite++;
				if(ite == vec.end()){
					vec.push_back(PAIR(st, 1));
					break;
				}
			}
		}

		vector<PAIR>::iterator max = vec.begin();
		vector<PAIR>::iterator mim = vec.begin();
		for(ite = vec.begin(); ite != vec.end(); ite++){
			if((*max).second < (*ite).second) max = ite;
			if((*mim).second > (*ite).second) mim = ite;
		}

		cout << (*max).first << " " << (*mim).first << endl;

	}
	return 0;
}