#if 0

#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

map<string, int> M;

int main() {
  string word, long_word, freq_word;
  int cnt = 0, length = 0;
  while (cin >> word) {
    if (M.count(word))
      M[word]++;
    else
      M[word] = 1;
    if (M[word] > cnt) {
      cnt = M[word];
      freq_word = word;
    }
    if (word.length() > length) {
      length = word.length();
      long_word = word;
    }
  }
  cout << freq_word << ' ' << long_word << endl;
}

