#include <iostream>
#include <cstring>
using namespace std;
const int MAX_SIZE = 1000;
bool isLetter(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
bool isBigLetter(char c) {
return c >= 'A' && c <= 'Z';
}
bool isSmallLetter(char c) {
return c >= 'a' && c <= 'z';
}
bool checkCaps(char text[]) {
char word[100] = {0};
strcpy(word, text);
int n = strlen(word);
for (int i = 0; i < n; ++i) {
if (isBigLetter(word[i])) {
word[i] = word[i] + ('a' - 'A');
}
}
return (strcmp(word, "caps") == 0);
}
void processWords(char text[], bool &capsLock) {
int n = strlen(text), lettersCount = 0;
bool isWord = false;
for (int i = 0; i <= n; ++i) {
if (isLetter(text[i])) {
if (capsLock) {
if (isSmallLetter(text[i])) {
text[i] = text[i] - ('a' - 'A');
}
} else {
if (isBigLetter(text[i])) {
text[i] = text[i] + ('a' - 'A');
}
}
isWord = true;
++lettersCount;
} else if (isWord) {
char temp = text[i];
text[i] = 0;
//cout << text + i - lettersCount << ", ";
if (checkCaps(text + i - lettersCount)) {
if (capsLock) {
//cout << "MARE ";
capsLock = false;
} else {
//cout << "MICA ";
capsLock = true;
}
strcat(text + i - lettersCount, " ");
strcat(text, text + i);
}
text[i] = temp;
isWord = false;
lettersCount = 0;
}
}
}
int main() {
char text[MAX_SIZE + 1] = {0};
bool capsLock = false;
while (cin.getline(text, MAX_SIZE + 1)) {
processWords(text, capsLock);
cout << text << "\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBNQVhfU0laRSA9IDEwMDA7Cgpib29sIGlzTGV0dGVyKGNoYXIgYykgewoJcmV0dXJuIChjID49ICdhJyAmJiBjIDw9ICd6JykgfHwgKGMgPj0gJ0EnICYmIGMgPD0gJ1onKTsKfQoKYm9vbCBpc0JpZ0xldHRlcihjaGFyIGMpIHsKCXJldHVybiBjID49ICdBJyAmJiBjI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