#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
 string s, max("");
 map<string, int> m;
 map<int, string> x;

 while(cin>>s){
  if(s.size() > max.size())
  max = s;
  m[s]++;
 }

 for(map<string, int>::iterator it = m.begin(); it != m.end(); it++){
  x[(*it).second] = (*it).first;
  cout<<(*it).first;
 }

 cout<<(*x.rbegin()).second<<" "<<max<<endl;
 return 0;
}