#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
typedef pair<int,string> P;;
int main(){
    string str;
    getline(cin,str);
    vector<P> ans(1000);
    bool flag = true;
    int tmp_first = 0,tmp_end = 0,pos = 0;
    rep(i,str.size()){
        if(str[i] == ' ' || i == str.size()-1) {
            string tmp = str.substr(tmp_first,tmp_end);
            ans[pos].first = tmp.size();
            ans[pos].second = tmp;
            flag = true;
            pos++;
            tmp_end = 0;
        }
        else {
            if(flag == true){
                tmp_first = i;
                flag = false;
            }
        }
        tmp_end++;
    }
    int cnt1 = 0;
    int cnt2 = 0;
    string str_ans1,str_ans2;
    rep(i,pos) {
        int tmp_cnt = 0;
        rep(j,pos) {
            if(ans[i].second == ans[j].second) tmp_cnt++;
        }
        if(tmp_cnt > cnt1) {
            cnt1 = tmp_cnt;
            str_ans1 = ans[i].second;
        }
        //cout << ans[i].second << " " << ans[i].first  << endl;
        if(ans[i].first > cnt2){
            cnt2 = ans[i].first;
            str_ans2 = ans[i].second;
        }
    }
    cout << str_ans1 << " " << str_ans2 << endl;
    return 0;
}
