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

class word_cnt{
public:
  int cnt;
  string word;

  word_cnt() {
    cnt = 0;
  }

  bool operator < (const word_cnt& right) const {
    return cnt < right.cnt;
  }

};

int main() {

  vector<word_cnt> words;
  word_cnt add;
  string input;

  int len_max = 0;
  string word_max;

  while(cin >> input) {

    for ( int i = 0; i < input.size(); i++ ) {

      if ( input[i] >= 'A' && input[i] <= 'Z' ) input[i] -= ( 'A' - 'a' );

    }

    bool flag = true;
    for ( int i = 0; i < words.size(); i++ ) {

      if ( words[i].word == input ) {
	words[i].cnt++;
	flag = false;
	break;
      }

    }

    if ( flag ) {

      add.cnt = 1;
      add.word = input;
      words.push_back(add);

    }

    if ( len_max < input.size() ) {
      len_max = input.size();
      word_max = input;
    }

  }

  sort( words.begin(), words.end() );

  cout << words[ words.size()-1 ].word << " " << word_max << endl;

  return 0;
}