#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
// Hàm gộp hai dãy đã sắp xếp
vector<int> merge2Arrays(const vector<int>& a, const vector<int>& b) {
int m = a.size(), n = b.size();
vector<int> res(m + n);
int i = 0, p = 0, q = 0;
while (p < m && q < n) {
if (a[p] <= b[q]) {
res[i++] = a[p++];
} else {
res[i++] = b[q++];
}
}
while (p < m) {
res[i++] = a[p++];
}
while (q < n) {
res[i++] = b[q++];
}
return res;
}
// Hàm gộp k dãy đã sắp xếp
vector<int> mergeKArrays(vector<vector<int>>& arr, int k) {
vector<int> result = arr[0]; // Bắt đầu từ dãy đầu tiên
for (int i = 1; i < k; ++i) {
result = merge2Arrays(result, arr[i]);
}
return result;
}
int main() {
int k;
cin >> k;
cin.ignore(); // Bỏ qua ký tự xuống dòng sau khi nhập k
vector<vector<int>> arr(k);
for (int i = 0; i < k; ++i) {
string line;
getline(cin, line); // Đọc cả dòng
stringstream ss(line);
int num;
while (ss >> num) {
arr[i].push_back(num);
}
}
vector<int> result = mergeKArrays(arr, k);
// In kết quả
for (int x : result) {
cout << x << " ";
}
cout << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgovLyBIw6BtIGfhu5lwIGhhaSBkw6N5IMSRw6Mgc+G6r3AgeOG6v3AKdmVjdG9yPGludD4gbWVyZ2UyQXJyYXlzKGNvbnN0IHZlY3RvcjxpbnQ+JiBhLCBjb25zdCB2ZWN0b3I8aW50PiYgYikgewogICAgaW50IG0gPSBhLnNpemUoKSwgbiA9IGIuc2l6ZSgpOwogICAgdmVjdG9yPGludD4gcmVzKG0gKyBuKTsKICAgIGludCBpID0gMCwgcCA9IDAsIHEgPSAwOwoKICAgIHdoaWxlIChwIDwgbSAmJiBxIDwgbikgewogICAgICAgIGlmIChhW3BdIDw9IGJbcV0pIHsKICAgICAgICAgICAgcmVzW2krK10gPSBhW3ArK107CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzW2krK10gPSBiW3ErK107CiAgICAgICAgfQogICAgfQoKICAgIHdoaWxlIChwIDwgbSkgewogICAgICAgIHJlc1tpKytdID0gYVtwKytdOwogICAgfQoKICAgIHdoaWxlIChxIDwgbikgewogICAgICAgIHJlc1tpKytdID0gYltxKytdOwogICAgfQoKICAgIHJldHVybiByZXM7Cn0KCi8vIEjDoG0gZ+G7mXAgayBkw6N5IMSRw6Mgc+G6r3AgeOG6v3AKdmVjdG9yPGludD4gbWVyZ2VLQXJyYXlzKHZlY3Rvcjx2ZWN0b3I8aW50Pj4mIGFyciwgaW50IGspIHsKICAgIHZlY3RvcjxpbnQ+IHJlc3VsdCA9IGFyclswXTsgLy8gQuG6r3QgxJHhuqd1IHThu6sgZMOjeSDEkeG6p3UgdGnDqm4KCiAgICBmb3IgKGludCBpID0gMTsgaSA8IGs7ICsraSkgewogICAgICAgIHJlc3VsdCA9IG1lcmdlMkFycmF5cyhyZXN1bHQsIGFycltpXSk7CiAgICB9CgogICAgcmV0dXJuIHJlc3VsdDsKfQoKaW50IG1haW4oKSB7CiAgICBpbnQgazsKICAgIGNpbiA+PiBrOwogICAgY2luLmlnbm9yZSgpOyAvLyBC4buPIHF1YSBrw70gdOG7sSB4deG7kW5nIGTDsm5nIHNhdSBraGkgbmjhuq1wIGsKCiAgICB2ZWN0b3I8dmVjdG9yPGludD4+IGFycihrKTsKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IGs7ICsraSkgewogICAgICAgIHN0cmluZyBsaW5lOwogICAgICAgIGdldGxpbmUoY2luLCBsaW5lKTsgLy8gxJDhu41jIGPhuqMgZMOybmcKICAgICAgICBzdHJpbmdzdHJlYW0gc3MobGluZSk7CiAgICAgICAgaW50IG51bTsKICAgICAgICB3aGlsZSAoc3MgPj4gbnVtKSB7CiAgICAgICAgICAgIG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