#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
 
string word;
string Min;
int divideIdx[2];
 
void combination(int idx, int cnt)
{
    if(cnt == 2)
    {
        string first = word.substr(0, divideIdx[0]+1);
        string second = word.substr(divideIdx[0]+1, divideIdx[1]-divideIdx[0]);
        string third = word.substr(divideIdx[1]+1);
        
        reverse(first.begin(), first.end());
        reverse(second.begin(), second.end());
        reverse(third.begin(), third.end());
        
        string temp = first;
        temp += second;
        temp += third;
        
        if(Min > temp)
        {
            Min = temp;
        }
        
        return;
    }
    
    for(int i = idx; i < word.size()-1; i++)
    {
        divideIdx[cnt] = i;
        combination(i+1, cnt+1);
    }
}
 
int main(void)
{
//    freopen("B1251_input.txt", "r", stdin);
    
    cin >> word;
    
    for(int i = 0; i < word.size(); i++)
    {
        Min += "z";
    }
    
    combination(00);
    
    cout << Min;
    
    return 0;
}
cs

+ Recent posts