#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG

int main() {
  string text;
  map<string, int> table;
  string f_word, l_word;
  while (cin >> text) {
    table[text]++;
    if (table[text] > table[f_word])
      f_word = text;
    if (text.size() > l_word.size())
      l_word = text;
  }
  cout<<f_word<<" "<<l_word<<endl;
}

