#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll
//#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
template<class T> inline bool chmax(T & x, T const & y){ return x<y ? x=y,true : false; }
template<class T> inline bool chmin(T & x, T const & y){ return x>y ? x=y,true : false; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif
// ll const mod = 1000000007;
// ll const inf = 1LL<<60;

/*
  ch は小さいほうが良い
 */

struct Trie {
    int ctoi(char c){
        return isupper(c) ? c-'A' : c-'a'+26;
    }
    struct Node {
        int val;
        Node * ch[26*2];
        Node() : val(0) {
            for(auto & p : ch) p = nullptr;
        }
        ~Node(){
            for(auto & p : ch) if(p != nullptr) delete p;
        }
    };
    Node *r;

    Node* insert(string const &s){
        auto p = s.begin();
        auto cur = r;
        while(1){
            if(p == s.end()){
                return cur;
            } else {
                auto &nxt = cur->ch[ctoi(*p)];
                if(nxt == nullptr) nxt = new Node();
                cur = nxt;
                ++p;
            }
        }
    }
    bool erase(string const &s){
        auto p = s.begin();
        auto cur = r;
        while(1){
            if(p == s.end()) return cur->val > 0 ? (cur->val--, true) : false;
            auto &nxt = cur->ch[ctoi(*p)];
            if(nxt == nullptr) return false;
            cur = nxt;
            ++p;
        }
    }
    Node* find(string const& s){
        auto p = s.begin();
        auto cur = r;
        while(1){
            if(p == s.end()) return cur;
            auto &nxt = cur->ch[ctoi(*p)];
            if(nxt == nullptr) return nullptr;
            cur = nxt;
            ++p;
        }
    }
    Trie() : r(new Node()) {}
    ~Trie() { delete r; }
};

int main(){
    Trie t;
    string s;
    string freq;
    string aaa;
    int freq_c = 0;
    while(cin >> s){
        auto res = t.find(s);
        Trie::Node * p = res ? res : t.insert(s);
        p->val++;
        if(freq_c < p->val){
            freq = s;
            freq_c = p->val;
        }
        if(aaa.size() < s.size()){
            aaa = s;
        }
    }
    cout << freq << " " << aaa << endl;
}

Measured memory_bytes: 1232