#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
int main() {
  unordered_map<string,int> count;
  unordered_map<string,int> length;
  string word;
  int max1 = 0;
  int max2 = 0;
  string answer1, answer2;

  while (cin >> word) { // 入力がある限り読み込む
    count[word] += 1;
    length[word] = word.size();
    if (count[word] > max1) {
      max1 = count[word];
      answer1 = word;
    }
    if (length[word] > max2) {
      max2 = length[word];
      answer2 = word;
    }
    
  }

  cout << answer1 << " " << answer2 << endl;
 }
