OIG I - sor

// https://szkopul.edu.pl/problemset/problem/ERz8Uez5UFnNbPH2Jn965eZ3/site/?key=statement

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);

    int n;
    std::cin >> n;

    std::vector<std::string> v(n);

    for (int i = 0; i < n; i++) {
        std::cin >> v[i];
    }

    std::sort(v.begin(), v.end(), [](std::string& a, std::string& b) {
        if (a.size() < b.size()) {
            return true;
        } else if (a.size() == b.size()) {
            return a < b;
        } else {
            return false;
        }
    });

    for (const auto& s : v) {
        std::cout << s << '\n';
    }

    return 0;
}