#include <bits/stdc++.h>
using namespace std;
int main(void){
   std::deque<string> deq;
   string s,tmps,tmpss;
   int count,max,length;
   count = 0;
   max = 0;
   length = 0;
   while (cin >> s) {
       deq.emplace_back(s);
   }
   for (int i=0;i<deq.size();i++) {
       for (int j=0;j<deq.size();j++) {
           if (deq[i]==deq[j]) {
               count++;
           }
           if (count>max) {
               max = count;
               tmps = deq[i];
           }
           if (deq[i].size()>length) {
               length = deq[i].size();
               tmpss = deq[i];
           }
       }
       count = 0;
   }
   cout << tmps << " " << tmpss << endl;
}

