#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
  string s[1001], ms, fs;
  int m, c;
  for (int i = 0, m = 0; (c = getchar()) != '\n'; i++){
      cin >> s[i];
      if(s[i].size() > m){
	m = s[i].size();
	ms = s[i];
      }
  }
  for(int i = 0, c = 0; i < 1001; i++){
    for(int j = i + 1; j < 1001; j++){
      if(s[i].compare(s[j]) == 0){
	int nc = 0;
	nc++;
	if(nc > c){
	  c = nc;
	  fs = s[i];
	}
      }
    }
  }
  cout << fs << " " << ms << endl;
  return 0;
}