#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    ifstream if1("file1.txt");
    ifstream if2("file2.txt");

    string s;

    vector<string> v1;
    while ( if1 >> s ) v1.push_back(s);

    vector<string> v2;
    while ( if2 >> s ) v2.push_back(s);

    vector<string> v3;
    v3.reserve( v1.size() + v2.size() );    // helyet fizikailag lefoglalja,
                                            // de size == 0
    merge( v1.begin(), v1.end(),
           v2.begin(), v2.end(),
           back_inserter(v3));      // v3.push_back(*current)

    for ( int i = 0; i < v3.size(); ++i)
        cout << v3[i] << endl;

    return 0;
}