#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
std::vector<std::vector<std::pair<char, int>>> ToVector(std::string& str){
std::vector<std::vector<std::pair<char, int>>> vec;
std::size_t j = 0;
vec.push_back(std::vector < std::pair<char, int>>());
for (std::size_t i = 0; i < str.size(); i++){
if (str[i] == '\n'){
vec.push_back(std::vector < std::pair<char, int>>());
j++;
continue;
}
vec[j].push_back(std::make_pair(str[i], 0));
}
return vec;
}
bool makehoge(std::string& str){
auto vec = ToVector(str);
std::vector<std::size_t> Count;
Count.resize(vec.size());
bool F = true;
char M = 127;
bool F2 = false;
while (1){
F2 = false;
M = 127;
for (std::size_t i = 1; i < Count.size(); i++){
if (Count[i-1] == vec[i-1].size())continue;
if (Count[i] == vec[i].size())continue;
F2 = true;
F &= (vec[i][Count[i]].first == vec[i - 1][Count[i - 1]].first);
M = std::min(M, vec[i][Count[i]].first);
M = std::min(M, vec[i - 1][Count[i - 1]].first);
}
if (F2 == false)break;
if (F == true){
for (auto& o : Count)o++;
}
else{
for (std::size_t i = 0; i < Count.size(); i++){
if (Count[i] == vec[i].size()) continue;
if (M != vec[i][Count[i]].first){
vec[i][Count[i]].second++;
}
else{
Count[i]++;
}
}
}
}
for (std::size_t i = 0; i < vec.size(); i++){
for (std::size_t j = 0; j < vec[i].size(); j++){
for (int k=0; k < vec[i][j].second; k++){
std::cout << ' ';
}
std::cout << vec[i][j].first;
}
std::cout << std::endl;
}
return true;
}
int main(){
std::string str{ "123\n134" };
std::string str2{ "1212\n1322\n1122" };
makehoge(str);
std::cout << std::endl;
makehoge(str2);
std::cout << std::endl;
return 0;
}