#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
map<string, int> words;
char s[32];
while(scanf("%s",s) != EOF) {
if ('A' <= s[0] && s[0] <= 'Z') s[0]=s[0]+'a'-'A';
string word = s;
map<string, int>::iterator p = words.find(word);
if (p != words.end()) {
words[word]++;
} else {
words[word] = 1;
}
}
int maxFreq = 0;
string maxFreqWord = "";
string longestWord = "";
unsigned int longestLen = 0;
for (map<string, int>::iterator p=words.begin(); p!=words.end(); p++) {
if (p->second > maxFreq) {
maxFreq = p->second;
maxFreqWord = p->first;
}
if ((p->first).size() > longestLen) {
longestLen = (p->first).size();
longestWord = p->first;
}
}
cout << maxFreqWord << " " << longestWord << endl;
return 0;
}