#include <iostream>
#include <cstring>
using namespace std;
const int MAX_SIZE = 2000;
const int LAST_LETTER = 'Z';
const int CASE_DIFFERENCE = 'a' - 'A';
bool isIntresting(int fr[]) {
for (int i = 'A'; i <= 'Z'; ++i) {
if (fr[i] == 2) {
return true;
}
}
return false;
}
void reverseWord(char text[], int startPos, int lastPos) {
int halfPos = (lastPos + startPos - 1) / 2;
for (int i = startPos; i <= halfPos; ++i) {
char aux = text[i];
text[i] = text[lastPos + startPos - i];
text[lastPos + startPos - i] = aux;
}
}
bool isLetter(char c) {
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
}
void resetToZero(int fr[]) {
for (int i = 'A'; i <= 'Z'; ++i) {
fr[i] = 0;
}
}
void countFrequency(int fr[], int c) {
if ('A' <= c && c <= 'Z') {
++fr[c];
return;
}
++fr[c - CASE_DIFFERENCE];
}
void transformText(char text[]) {
int length = strlen(text), fr[LAST_LETTER + 1] = {0};
int startPos = 0;
bool prevLetter = false;
for (int i = 0; i <= length; ++i) {
if (isLetter(text[i])) {
countFrequency(fr, text[i]);
prevLetter = true;
} else {
if (prevLetter) {
if (isIntresting(fr)) {
reverseWord(text, startPos, i - 1);
}
resetToZero(fr);
}
prevLetter = false;
startPos = i + 1;
}
}
}
int main() {
char text[MAX_SIZE + 1];
while (cin.getline(text, MAX_SIZE + 1)) {
transformText(text);
cout << text << '\n';
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBNQVhfU0laRSA9IDIwMDA7CmNvbnN0IGludCBMQVNUX0xFVFRFUiA9ICdaJzsKY29uc3QgaW50IENBU0VfRElGRkVSRU5DRSA9ICdhJyAtICdBJzsKCmJvb2wgaXNJbnRyZXN0aW5nKGludCBmcltdKSB7CiAgICBmb3IgKGludCBpID0gJ0EnOyBpIDw9ICdaJzsgKytpKSB7CiAgICAgICAgaWYgKGZyW2ldID09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b3IgKGludCBpID0gMDsgaSA8PSBsZW5ndGg7ICsraSkgewogICAgICAgIGlmIChpc0xldHRlcih0ZXh0W2ldKSkgewogICAgICAgICAgICBjb3VudEZyZXF1ZW5jeShmciwgdGV4dFtpXSk7CiAgICAgICAgICAgIHByZXZMZXR0ZXIgPSB0cnVlOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGlmIChwcmV2TGV0dGVyKSB7CiAgICAgICAgICAgIAlpZiAoaXNJbnRyZXN0aW5nKGZyKSkgewogICAgICAgICAgICAgICAgCXJldmVyc2VXb3JkKHRleHQsIHN0YXJ0UG9zLCBpIC0gMSk7CiAgICAgICAgICAgIAl9CiAgICAgICAgICAgICAgICByZXNldFRvWmVybyhmcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcHJldkxldHRlciA9IGZhbHNlOwogICAgICAgICAgICBzdGFydFBvcyA9IGkgKyAxOwogICAgICAgIH0KICAgICAgICAKICAgIH0KfQoKaW50IG1haW4oKSB7CiAgICBjaGFyIHRleHRbTUFYX1NJWkUgKyAxXTsKICAgIHdoaWxlIChjaW4uZ2V0bGluZSh0ZXh0LCBNQVhfU0laRSArIDEpKSB7CiAgICAgICAgdHJhbnNmb3JtVGV4dCh0ZXh0KTsKICAgICAgICBjb3V0IDw8IHRleHQgPDwgJ1xuJzsKICAgIH0KICAgIHJldHVybiAwOwp9