
// ConsoleApplication3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <list>
#include <string>
#include <set>
#include <iostream>
#include <map>
#include <sstream>

using namespace std;

template<typename T>list<T> merge(list<T> &a, list<T> &b)
{
    list<T>r;
        while (!a.empty() && !b.empty())
        {
            if (a.front() < b.front())
            {
                r.push_back(a.front());
                a.pop_front();
            }
            else
            {
                r.push_back(b.front());
                b.pop_front();
            }
        }

        while (!a.empty()) {
            r.push_back(a.front());
            a.pop_front();
        }

        while (!b.empty()) {
            r.push_back(b.front());
            b.pop_front();
        }
        return r;
}


template<typename T>
list<T> mergeSort(const list<T>&l) {

    if (l.empty()) return l;


    list<list<T>> ll;
    for (auto && i : l) {
        ll.push_back(list<T>());
        ll.back().push_back(i);
    }

    while (ll.size()>=2)
    {
        ll.push_back(merge(ll.front(), *(++ll.begin())));
        ll.pop_front();
        ll.pop_front();
    }
    return ll.front();
}

int main() {
    string s;
    list<string> ls;

    while (getline(cin, s) && !s.empty())
    {
        ls.push_back(s);
    }

    ls = mergeSort(ls);

    for (auto && i : ls)
    {
        cout << i << endl;
    }


    return 0;
}

int main2() {
    string line;
    getline(cin, line);

    istringstream is(line);

    map<string, int> m;

    for (string word; is >> word;) {
        ++m[word];
    }

    cout << m.size() << endl;

    for (auto && i : m)
    {
        cout << i.first << ": " << i.second << endl;
    }

    return 0;
}

int main1()
{
    multiset<string> l;

    for (string s; cin >> s && s != "end";) {
        l.insert(s);
    }
   
   
    while (!l.empty())
    {

        cout << *l.begin() << endl;
        l.erase(l.begin());
    }
   
    /*
    for (auto i = l.begin(); i != l.end(); i++) {
        cout << *i << endl;
    }
    */
     


    return 0;
}
