#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;

int main() 
{
    string s;
    pair<string,int> p;
    vector<string> v;
    vector<string> u;
    while(cin >> s){
        v.push_back(s);
        bool e = true;
        for(int i = 0; i < u.size(); i++){
            if(u[i] == s){
                e = false;
            }
        }
        if(e) u.push_back(s);
    }
    int n = u.size();

    int cnt[n];
    for(int i = 0; i < n; i++){
        cnt[i] = 0;
    }
    int l = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < v.size(); j++){
            if(u[i] == v[j]){
                cnt[i]++;
            }
            int m = v[j].size();
            l = max(l,m);
        }
    }
    int k = 0;
    for(int i = 0; i < n; i++){
        k = max(k,cnt[i]);
    }
    for(int i = 0; i < n; i++){
        if(cnt[i] == k){
            cout << u[i] << ' ';
        }
    }
    for(int i = 0; i < n; i++){
        if(u[i].size() == l){
            cout << u[i] << endl;
        }
    }
}
