#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;
  unordered_map<string, int> cnt;
  vector<string> v;

  while (cin >> s) {
    cnt[s] += 1;
    v.push_back(s);
  }

  int max_freq = 0;
  int max_len = 0;

  for (auto p: cnt) {
    max_freq = max(max_freq, p.second);
    max_len = max(max_len, (int)p.first.size());
  }

  for (auto p: cnt) {
    if (p.second == max_freq) {
      cout << p.first << ' ';
    }
  }

  for (auto p: cnt) {
    if (p.first.size() == max_len) {
      cout << p.first << endl;
    }
  }
}

