#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<string>Long, Short;
    Long.push_back("");
    Short.push_back(string(1001, ' '));
    string str;
    while (getline(cin,str)) {
        if (str.size() > Long[0].size()) {
            Long.clear();
            Long.push_back(str);
        }
        else if (str.size() == Long[0].size()) {
            Long.push_back(str);
        }
        if (str.size() < Short[0].size()) {
            Short.clear();
            Short.push_back(str);
        }
        else if (str.size() == Short[0].size()) {
            Short.push_back(str);
        }   
    }
    for (int i = 0; i < Short.size(); ++i) {
        cout << Short[i] << endl;
    }
    for (int i = 0; i < Long.size(); ++i) {
        cout << Long[i] << endl;
    }
}
// 64 位输出请用 printf("%lld")

乱杀