#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <set>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	std::string str;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

	
#if INPUT_FROM_FILE
	std::getline(ifs, str);
#else
	std::getline(std::cin, str);
#endif
	
	std::istringstream stream(str);
	int max_length = 0;
	int max_count = 0;
	std::string longest_str;
	std::string most_frequent_str;
	std::multiset<std::string> mset;

	while(std::getline(stream, str, ' ')){
		if(max_length < str.size()){
			max_length = str.size();
			longest_str = str;
		}
		mset.insert(str);
	}

	for(std::multiset<std::string>::const_iterator it = mset.begin();
		it != mset.end(); it++){
		std::string s = *it;
		int c = mset.count(s);
		if(max_count < c){
			max_count = c;
			most_frequent_str = s;
		}
	}

	std::cout << most_frequent_str << " " << longest_str << std::endl;
	return 0;
}
