#include <algorithm>
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

int main() {
    unordered_map<string, int> table;
    string frequent;    // 最大頻度
    string longest;     // 最長
    string word;        // 入力
    while (cin >> word) {
        table[word]++;
        if (table[word] > table[frequent]) {
            frequent = word;
        }
        if (word.length() > longest.length()) {
            longest = word;
        }
    }
    cout << frequent << " " << longest << endl;
    return 0;
}
