#include <iostream>
#include <string>
#include <map>

int main() {
  std::string s;
  std::map<std::string, int> m;

  while (std::cin >> s) {
    decltype(m)::iterator it = m.find(s);

    if (it == m.end()) {
      m.insert(std::make_pair(s, 1));
    } else {
      it->second++;
    }
  }

  int mode = 0;
  decltype(m)::iterator modePair;
  int maxLen = 0;
  decltype(m)::iterator maxLenPair;

  for (decltype(m)::iterator i = m.begin(); i != m.end(); ++i) {
    if (mode < i->second) {
      mode = i->second;
      modePair = i;
    }

    if (maxLen < i->first.length()) {
      maxLen = i->first.length();
      maxLenPair = i;
    }
  }

  std::cout << modePair->first << " " << maxLenPair->first << std::endl;


  return 0;
}

