#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#define MAX 100000
typedef long long int ll;

using namespace std;

map < string , int > mp;

struct node{
    char st[50];
}a[1005];

int main()
{
    freopen("in.txt","r",stdin);
    char s[10000],str[50];
    while(gets(s)){
        strcat(s," ");
        mp.clear();
        int len=strlen(s);
        int j=0;
        int k=0;
        for(int i=0;i<len;i++){
            if(s[i]==' '){
                str[j]='\0';
                mp[str]++;
                strcpy(a[k++].st,str);
                j=0;
            }
            else{
                str[j++]=s[i];
            }
        }
        int index1,index2,x=0,z=0;
        for(int i=0;i<k;i++){
            int s=strlen(a[i].st);
            if(s>x)x=s,index1=i;
            if(mp[a[i].st]>z)z=mp[a[i].st],index2=i;
        }
        printf("%s %s\n",a[index2].st,a[index1].st);
    }
    return 0;
}