#include<stdio.h>
#include<string.h>

char str[1005][1005];

int main() {
    int n = 0;
    while (gets(str[n])) n++;
    int min = strlen(str[0]), max = min;
    for (int i = 0; i < n; i++)
        if (strlen(str[i]) > max) max = strlen(str[i]);
        else if (strlen(str[i]) < min) min = strlen(str[i]);

    for (int i = 0; i < n; i++)
        if (strlen(str[i]) == min) printf("%s\n", str[i]);

    for (int i = 0; i < n; i++)
        if (strlen(str[i]) == max) printf("%s\n", str[i]);

    return 0;
}