#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <chrono>
  
typedef struct LettersInfo {
    std::string letters;
    unsigned int count;??°
} lettersInfo_s;
  
int main()
{
    std::string paramStr;
    std::getline(std::cin, paramStr);
  
    std::vector<lettersInfo_s*> lettersList;
  
    std::string letters;
    std::istringstream stream(paramStr);
  
    unsigned int maxLength = 0;
    std::string maxLengthStr;
  
    while (std::getline(stream, letters, ' ')) {
        unsigned int len = letters.size();
        if ( len != 0) {
            if ( maxLength < len ) {
                maxLengthStr = letters;
                maxLength = len;
            }
 
            unsigned int loopCount;
            for (loopCount = 0; loopCount < lettersList.size(); loopCount++) {
                if ( lettersList[loopCount]->letters == letters ) {
                    ++lettersList[loopCount]->count;
                    break;
                }
            }
 
            if (loopCount == lettersList.size()) {
                lettersInfo_s* plettersInfo = new lettersInfo_s();
                plettersInfo->letters = letters;
                ++plettersInfo->count;
                lettersList.push_back(plettersInfo);
            }
        }
    }
  
    unsigned int maxCount = 0;
    std::string maxCountStr;
    while( lettersList.size() > 0 ) {
 
        lettersInfo_s* plettersInfo = lettersList.back();
 
        unsigned int count = plettersInfo->count;
        if (maxCount < count) {
            maxCountStr = plettersInfo->letters;
            maxCount = count;
        }
        delete plettersInfo;
        lettersList.pop_back();
    }
  
    std::cout << maxCountStr << " " << maxLengthStr << std::endl;
  
    return 0;
}