#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int count_words (string s) //функция подсчитывает слова в строке
{
s+=' ';
int a = 0;
for (size_t i=0; i<s.length(); i++)
if (s[i]==' ') a++;
return a;
}
string * cut_words (string s) //функция разрезает строку на слова и возвращает массив
{
s+=' ';
int c = 0;
int p = 0;
int i=0;
string *s_return = new string [count_words(s)];
while (s.length() != 0)
{
if (s[i] != ' ')
{
c++;
i++;
}
else
{
i=0;
s_return[p] = s.substr(0, c);
s.erase(0, c+1);
c = 0;
p++;
}
}
return s_return;
}
int main ()
{
string s;
getline (cin, s);
string *s_return;
s_return = cut_words(s);
for (int i=0; i<count_words(s); i++)
{
string s_tmp = s_return[i];
if (s_tmp.empty()) //если ячейка пуста, то продолжаем дальше
{
continue;
}
else //а если нет, то ищем перестановки.
{
int p = 0;
for (int j=i+1; j<count_words(s); j++)
{
if ( is_permutation (s_tmp.begin(), s_tmp.end(), s_return[j].begin())) //если перестановка
if (s_tmp.length() == s_return[j].length()) //и если одинаковая длина слов
{
cout<<s_return[j]<<endl; //выводим на экран
s_return[j].clear(); //очищаем строку
p++;
}
}
if (p>=1) cout<<s_tmp<<endl;
}
}
return 0;
}
CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxzdHJpbmc+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgY291bnRfd29yZHMgKHN0cmluZyBzKSAvL9GE0YPQvdC60YbQuNGPINC/0L7QtNGB0YfQuNGC0YvQstCw0LXRgiDRgdC70L7QstCwINCyINGB0YLRgNC+0LrQtQp7CiAgICBzKz0nICc7CiAgICBpbnQgYSA9IDA7CiAgICBmb3IgKHNpemVfdCBpPTA7IGk8cy5sZW5ndGgoKTsgaSsrKQogICAgICAgIGlmIChzW2ldPT0nICcpIGErKzsKICAgIHJldHVybiBhOwp9CnN0cmluZyAqIGN1dF93b3JkcyAoc3RyaW5nIHMpIC8v0YTRg9C90LrRhtC40Y8g0YDQsNC30YDQtdC30LDQtdGCINGB0YLRgNC+0LrRgyDQvdCwINGB0LvQvtCy0LAg0Lgg0LLQvtC30LLRgNCw0YnQsNC10YIg0LzQsNGB0YHQuNCyCnsKICAgIHMrPScgJzsKICAgIGludCBjID0gMDsKICAgIGludCBwID0gMDsKICAgIGludCBpPTA7CiAgICBzdHJpbmcgKnNfcmV0dXJuID0gbmV3IHN0cmluZyBbY291bnRfd29yZHMocyldOwogICAgd2hpbGUgKHMubGVuZ3RoKCkgIT0gMCkKICAgICAgICB7CiAgICAgICAgICAgIGlmIChzW2ldICE9ICcgJykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgYysrOwogICAgICAgICAgICAgICAgaSsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaT0wOwogICAgICAgICAgICAgICAgc19yZXR1cm5bcF0gPSBzLnN1YnN0cigwLCBjKTsKICAgICAgICAgICAgICAgIHMuZXJhc2UoMCwgYysxKTsKICAgICAgICAgICAgICAgIGMgPSAwOwogICAgICAgICAgICAgICAgcCsrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICByZXR1cm4gc19yZXR1cm47Cn0KCmludCBtYWluICgpCnsKICAgIHN0cmluZyBzOwogICAgZ2V0bGluZSAoY2luLCBzKTsKCXN0cmluZyAqc19yZXR1cm47CglzX3JldHVybiA9IGN1dF93b3JkcyhzKTsKCWZvciAoaW50IGk9MDsgaTxjb3VudF93b3JkcyhzKTsgaSsrKQogICAgewogICAgCXN0cmluZyBzX3RtcCA9IHNfcmV0dXJuW2ldOwogICAgICAgIGlmIChzX3RtcC5lbXB0eSgpKQkJCQkJLy/QtdGB0LvQuCDRj9GH0LXQudC60LAg0L/Rg9GB0YLQsCwg0YLQviDQv9GA0L7QtNC+0LvQttCw0LXQvCDQtNCw0LvRjNGI0LUKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICBlbHNlCQkJCS8v0LAg0LXRgdC70Lgg0L3QtdGCLCDRgtC+INC40YnQtdC8INC/0LXRgNC10YHRgtCw0L3QvtCy0LrQuC4KICAgICAgICB7CiAgICAgICAgCWludCBwID0gMDsKICAgICAgICAgICAgZm9yIChpbnQgaj1pKzE7IGo8Y291bnRfd29yZHMocyk7IGorKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYgKCBpc19wZXJtdXRhdGlvbiAoc190bXAuYmVnaW4oKSwgc190bXAuZW5kKCksIHNfcmV0dXJuW2pdLmJlZ2luKCkpKQkvL9C10YHQu9C4INC/0LXRgNC10YHRgtCw0L3QvtCy0LrQsAogICAgICAgICAgICAgICAgICAgIGlmIChzX3RtcC5sZW5ndGgoKSA9PSBzX3JldHVybltqXS5sZW5ndGgoKSkJCS8v0Lgg0LXRgdC70Lgg0L7QtNC40L3QsNC60L7QstCw0Y8g0LTQu9C40L3QsCDRgdC70L7QsgogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgY291dDw8c19yZXR1cm5bal08PGVuZGw7CQkvL9Cy0YvQstC+0LTQuNC8INC90LAg0Y3QutGA0LDQvQogICAgICAgICAgICAgICAgICAgICAgICBzX3JldHVybltqXS5jbGVhcigpOyAvL9C+0YfQuNGJ0LDQtdC8INGB0YLRgNC+0LrRgwogICAgICAgICAgICAgICAgICAgICAgICBwKys7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChwPj0xKSBjb3V0PDxzX3RtcDw8ZW5kbDsJCiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0K