#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string, int> table;
int main()
{
  string /*入力用*/ word, /*最大頻度*/ frequent, /*最長*/ longest;
  size_t N = 0; /*文字列frequentの頻度*/
  while (cin >> word)
  {
    table[word] += 1;
    // table[word] を一つ増やす
    if(table[word] > N){
      N = table[word];
      frequent = word;
    }
    // table[word] がN より大きければ，N とfrequent を更新
    if(word.size() > longest.size()){
      longest = word;
    }
    // word.size() > longest.size() ならlongest を更新
  }
  cout << frequent << " " << longest << endl;
  //frequent とlongest を出力
}
