#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

struct Inf
{
      char save[35];
}inf[1100];

bool cmp(struct Inf a,struct Inf b)
{
      return strcmp(a.save,b.save)<0;
}
int main()
{
      int num=0,maxn=0,flag2;
      char ans2[38],last[39];

      while(cin>>inf[num].save)
      {
           
            int len=strlen(inf[num].save);

            if(len>maxn)
            {
                  maxn=len;
                  flag2=num;
            }
            num++;
      }
      strcpy(ans2,inf[flag2].save);
      sort(inf,inf+num,cmp);

      int sum=1;
      flag2=0;
      int Max=1;
      strcpy(last,inf[0].save);
     
      for(int i=1;i<num;i++)
      {
            if(strcmp(inf[i].save,last)==0)
                  sum++;
            else
            {
                  if(sum>Max)
                  {
                        Max=sum;
                        flag2=i-1;
                  }
                  sum=1;

            }
            strcpy(last,inf[i].save);
      }

      if(sum>Max)
         flag2=num-1;



     cout<<inf[flag2].save<<" "<<ans2;


      return 0;
}