#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
	char ans[50][10000] = {{0}};
	char a[10000] = {0};
	scanf("%[^\n]",a);
	int cnt = 0;
	int mx_len = 0;
	char date[10000] = {0};
	a[strlen(a)] = ' ';
	for(int i = 0,j = 0; i <= strlen(a); i++){
        if(a[i] >= 'a' && a[i] <= 'z' || a[i] >= 'A' && a[i] <= 'Z'){
            ans[cnt][j] = a[i];
            j++;
        }
        else{
            if(mx_len < j){
                strncpy(date,a+i-j,j);
                mx_len = max(mx_len,j);
            }
            cnt++;
            j = 0;
        }
	}
	int check[10000] = {0};
	for(int i = 0; i < cnt; i++){
        for(int j = i; j < cnt; j++){
            if(i != j){
                if(strcmp(ans[i],ans[j]) == 0){
                    fill(ans[j],ans[j]+1000,0);
                    check[i]++;
                }
            }
        }
	}
	mx_len = 0;
	char mx_date[10000] = {0};
	for(int i = 0; i < cnt; i++){
	    if(mx_len < check[i]){
	        strcpy(mx_date,ans[i]);
            mx_len = max(mx_len,check[i]);
	    }
	}
    cout << mx_date << " "<< date << endl;
	return 0;
}