#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <string>
#include <map>
using namespace std;

int main(void){
	map<string, int> table;
	string word, frequent, longest;
	int N = 0;
	while(cin >> word){
		table[word] += 1;
		if(table[word] > N){
			N = table[word];
			frequent = word;
		}

		if(word.size() > longest.size()){
			longest = word;
		}
	}

	cout << frequent << " " << longest << endl;
	
    return 0;
}