#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct Sentence {
  string s;
  int len = 0;
  int n = 0;
};

int main() {
  Sentence a[1000];
  string e;

  int j = 0;
  while (cin >> e) {
    for (int i = 0; i < 1000; i++) {
      if (e == a[i].s) {
        a[i].s = e;
        a[i].len = e.size();
        a[i].n++;
      } else if (i == 999) {
        a[j].s = e;
        a[j].len = e.size();
        a[j].n++;
      }
    }

    j++;
  }

  int maxi_n = 0, maxi_len = 0;
  for (int i = 0; i < 1000; i++) {
    if (a[i].n > maxi_n) maxi_n = i;
    if (a[i].len > maxi_len) maxi_len = i;
  }

  cout << a[maxi_n].s << " " << a[maxi_len].s << endl;
}
