#include <iostream>
#include <sstream>
using namespace std;
int main()
{
string s, k;
getline(cin, s);
for (int i = 0; s[i]; i++)
if (s[i] == ',')
s[i] = 32;
istringstream ss(s);
string mas = "", mis = "";
int mad = 0, mid = 1000;
while (ss >> k)
{
if (k.size() > mad)
{
mad = k.size();
mas = k;
}
if (k.size() < mid)
{
mid = k.size();
mis = k;
}
}
cout << mas << "\n"
<< mis;
return 0;
}