#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct str{
string s;
int n;
};
bool my_greater(const str &a, const str &b){
return a.n < b.n;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string s;
int n;
int count = 0;
vector<str> vec;
while(getline(cin, s)){
n = s.length();
vec.push_back({s, n});
count++;
}
vec.resize(count);
sort(vec.begin(), vec.end(), my_greater);
for(int i = 0; i < count; i++){
if(vec[i].n == vec[0].n || vec[i].n == vec[count - 1].n){
cout << vec[i].s << "\n";
}
}
return 0;
}