// 131A - cAPS lOCK
// http://codeforces.com/problemset/problem/131/A

function main() {
    let s = read();
    let ans = s;
    if (s.length === 1 || s.substring(1, s.length) === s.substring(1, s.length).toUpperCase()) {
        ans = "";
        for (let i = 0; i < s.length; i++) {
            if (s[i] === s[i].toUpperCase()) {
                ans += s[i].toLowerCase();
            } else {
                ans += s[i].toUpperCase();
            }
        }
    }
    writeline(ans);
    return 0;
}

var input = "";
var read;
var writeline = (x) => process.stdout.write(x + "\n");
var write = (x) => process.stdout.write(x);
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", (chunk) => input += chunk);
process.stdin.on("end", () => {
    input = input.trim().split(/\s+/);
    read = () => input.shift();
    process.exit(main() || 0);
});

function isCompleteCaps(word) {
    return word.toUpperCase() == word;
}

function isPartialCaps(word) {
    var first = word[0];
    var rest = word.slice(1);
    return (
        first.toLowerCase() == word[0] && rest.toUpperCase() == word.slice(1)
    );
}

function removeCapsLock(word) {
    if (isPartialCaps(word)) {
        var first = word[0];
        var rest = word.slice(1);
        return first.toUpperCase() + rest.toLowerCase();
    } else if (isCompleteCaps(word)) {
        var first = word[0];
        var rest = word.slice(1);
        return first.toLowerCase() + rest.toLowerCase();
    }
    return word;
}

var input = readline();
// // var input = 'cAPS';
// // var input = 'Lock';
// // var input = 'cAPSlOCK';
// // var input = 'CAPs';
// // var input = 'LoCK';
// var input = 'OOPS';

print(removeCapsLock(input));
// console.log(removeCapsLock(input));

function isStringUppercase (string) {
  return string.toUpperCase() === string;
}

function isFirstLetterLowerCase (string) {
  return string.charAt(0).toLowerCase() === string.charAt(0);
}

function isWrongCase(string) {
  var wrongCase = false;

  if (isFirstLetterLowerCase(string) && isStringUppercase(string.slice(1))) {
    wrongCase = true;
  } else if (isStringUppercase(string)) {
    wrongCase = true;
  }

  return wrongCase;
}

function invertWrongCaseString (string) {
  if (isWrongCase(string)) {
    return string.split("").map(function (item) {
      if (item.toLowerCase() === item) {
        return item.toUpperCase();
      } else {
        return item.toLowerCase();
      }
    }).join("");
  } else {
    return string;
  }
}

var input = readline();

var output = invertWrongCaseString.call(null, input);

write(output);

var word = readline();
var result = word[0].toUpperCase() + word.slice(1).toLowerCase();

if ( word === (word[0].toLowerCase() + word.slice(1).toUpperCase())) {
    print(result);
} else if (word === word.toUpperCase()) {
    print(word.toLowerCase())
} else print(word)

var word = readline();

if (word.match(/^[A-Z]+$/)) {
    print(word.toLowerCase());
} else if (word.match(/^[a-z][A-Z]*$/)) {
    print(word[0].toUpperCase() + word.slice(1).toLowerCase());
} else {
    print(word);
}

function isLowerCase(symbol) {
    if (symbol === symbol.toLowerCase()) {
        return true;
    }
}

function isWrong(str) {
    if (str.length === 1) {
        return true;
    }
    for (var i = 1; i < str.length; i++) {
        if (isLowerCase(str[i])) {
            return false;
        }
    }
    return true;
}

function changeCase(str) {
    return str.split('').map(function (s) {
        return isLowerCase(s) ? s.toUpperCase() : s.toLowerCase();
    }).join('');
}

var str = readline();
if (isWrong(str)) {
    str = changeCase(str);
}
print(str);

var word = readline();
print((word.substr(1) == word.substr(1).toUpperCase())?
    (word[0]==word[0].toLowerCase()?word[0].toUpperCase()+ word.substr(1).toLowerCase():
    word.toLowerCase()): word);

  var line = readline()

  var result = ''

  var isAllUpperCase = line.toUpperCase() === line
  var firstLetter = line[0]
  var firstLetterIsLowerCase = firstLetter.toLowerCase() === firstLetter
  var restOfString = line.substr(1)
  var restOfStringisUppercase = restOfString.toUpperCase() === restOfString
  if (isAllUpperCase) {
    result = line.toLowerCase()
  } else if (restOfString && firstLetterIsLowerCase && restOfStringisUppercase) {
    result = firstLetter.toUpperCase() + restOfString.toLowerCase()
  } else if (restOfString && !restOfStringisUppercase) {
    result = line
  } else {
    for (var i = 0; i < line.length; i++) {
      var letter = line.charAt(i)
      // console.log(letter)
      if (letter.toUpperCase() === line.charAt(i)) {
        result += letter.toLowerCase()
      } else {
        result += letter.toUpperCase()
      }
    }
  }

  print(result)

//var n = readline().split(' ').map(Number);

var str = readline();
var firstIsLower = false,
    otherIsUpper = true;

if (str[0] == str[0].toLowerCase()) {
    firstIsLower = true;
}

for (var i = 1; i < str.length; i++) {
    if (str[i] == str[i].toLowerCase()) {
        otherIsUpper = false;
    }
}

if (firstIsLower && otherIsUpper) {
    str = str.toLowerCase();
    print(str[0].toUpperCase() + str.substr(1));
}
else if (!firstIsLower && otherIsUpper) {
    print(str.toLowerCase());
}
else {
    print(str);
}

// http://codeforces.com/problemset/problem/131/A

//Input: The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
var word = readline();

var caps = 0;

// case where it's all CAPS
if ( 97 > word.charCodeAt(0))
{
	caps++;
	for (var i = 1; i < word.length; i++)
	{
		if (97 > word.charCodeAt(i))
			caps++;
	}

	if (caps == word.length)
		word = word.toLowerCase();
}
// case where the first is not caps but the rest is
else
{
	for (var i = 1; i < word.length; i++)
	{
		if (97 > word.charCodeAt(i))
			caps++;
	}

	if (caps == word.length-1)
		word = word.substr(0,1).toUpperCase() + word.substr(1,word.length-1).toLowerCase();
}

//Output: Print the result of the given word's processing.
print(word);

var string = readline();

function checkUpperCase(str){
    for (var i = 0; i < str.length; i++){
       if (str[i] !== str[i].toUpperCase()){
           return false;
       }
    }
    return true;
}

if(string.length === 1 && string === string.toLowerCase()) {
    string = string.toUpperCase();
} else if (string.length === 1 && string === string.toUpperCase()){
    string = string.toLowerCase();
} else if(checkUpperCase(string)){
    string = string.toLowerCase();
} else if (string[0] === string[0].toLowerCase() && checkUpperCase(string.substring(1))) {
    string = string[0].toUpperCase() + string.substring(1).toLowerCase();
}

print(string);

var word = readline();

if(word == word.toUpperCase())
	word = word.toLowerCase();
else if((word.slice(0,1) == word.slice(0,1).toLowerCase()) && (word.slice(1) == word.slice(1).toUpperCase()))
	word = word.slice(0,1).toUpperCase() + word.slice(1).toLowerCase();

print(word);

const input = readline()

if(input == input.toUpperCase() ) {
    print(`${input.toLowerCase()}`)
} else if(/^[a-z][A-Z]+$/.test(input)) {
    print(`${input[0].toUpperCase()}${input.substring(1).toLowerCase()}`)
} else if(input.length == 1) {
    print(input.toUpperCase())
} else {
    print(input)
}

	var input = readline();
	if (input == input.toUpperCase()){print(input.toLowerCase());}
	else if (input.slice(1) == input.slice(1).toUpperCase()){
		print(  input[0].toUpperCase() + input.slice(1).toLowerCase()  );}else{print(input);}

'use strict';
const str = readline();
const isCaps = function(char) {
    return char == char.toUpperCase();
}

let caps = true;

str.split('').slice(1).map(function(char){
    if(!isCaps(char)) {
       caps = false;
    }
})

if(caps) {
    let firstChar = str[0].toUpperCase();

    if(isCaps(str[0])) {
        firstChar = str[0].toLowerCase();
    }

    write(firstChar + str.substr(1).toLowerCase());
} else {
    write(str);
}

'use strict';

// let inpFileStrArr = `
// Lock
// `.trim().split('\n'), inpFileCounter = 0;
// function readline() {
//   return inpFileStrArr[inpFileCounter++];
// }
// function print(x) {
//   console.log(x);
// }

var isLower = function isLower(x) {
  return x === x.toLowerCase();
};
var isUpper = function isUpper(x) {
  return x === x.toUpperCase();
};
var convert = function convert(str) {
  return str.split('').map(function (x) {
    return isUpper(x) ? x.toLowerCase() : x.toUpperCase();
  }).join('');
};

var str = readline().trim();

var allCaps = isUpper(str);

var onlyFirstLower = isLower(str[0]) && isUpper(str.slice(1));

print(allCaps || onlyFirstLower ? convert(str) : str);

var str = readline();
a = str.split('');
var f = false;
var res = '';

for (var i = 1; i < a.length; i++) {
    if (a[i] != a[i].toUpperCase()) {
        print(str);
        f = true;
        break;
    } else res += a[i].toLowerCase();
}

if (!f) {
    if (a[0].toUpperCase() == a[0])
       print(a[0].toLowerCase() + res);
    else print(a[0].toUpperCase() + res);
}

var string = readline();
var changed = "";
var count = 0;
var firstLetter = false;

for (var i=0; i<string.length; i++) {
	if (i < 1) {
		if (string.charAt(i) == string.charAt(i).toLowerCase()) {
			firstLetter = true;
		} else {
			count++;
		}
	} else {
		if (string.charAt(i) == string.charAt(i).toUpperCase()) {
			count++;
		}
	}
}

if (count == string.length-1 && firstLetter) {
	for (var i=0; i<string.length; i++) {
		if (i < 1) {
			changed = string.charAt(i).toUpperCase();
		} else {
			changed += string.charAt(i).toLowerCase();
		}
	}
} else if (count == string.length) {
	for (var i=0; i<string.length; i++) {
			changed += string.charAt(i).toLowerCase();
	}
} else {
	changed = string;
}

print(changed);

var w = readline(),
	c = w.charAt(0),
	rest = w.substr(1)

if (rest == rest.toUpperCase()) {
	print((c.toUpperCase() == c ? c.toLowerCase() : c.toUpperCase()) + rest.toLowerCase())
} else {
	print(w)
}

function isCaps(letter) {
  return letter === letter.toUpperCase();
}

function solve(word) {
  var firstLetter = word[0];
  var restWord = word.slice(1, word.length);

  if (!isCaps(firstLetter) && isCaps(restWord)) {
    return firstLetter.toUpperCase() + restWord.toLowerCase();
  } else if (isCaps(word)) {
    return word.toLowerCase();
  } else {
    return word;
  }
}

print(solve(readline()));

s = readline()

    if (s === s.toUpperCase())
       print(s.toLowerCase())
     else if(s === s[0].toLowerCase()+s.slice(1).toUpperCase())
       print(s[0].toUpperCase()+s.slice(1).toLowerCase())
       else
      print(s)

var word = readline();
if (word[0] == word[0].toLowerCase() && word.slice(1) == word.slice(1).toUpperCase()) {
	print(word[0].toUpperCase() + word.slice(1).toLowerCase());
} else if(word == word.toUpperCase()){
	print(word.toLowerCase())
} else print(word);

;(function () {
	var str = readline();

	function isUpper (l) { return l === l.toUpperCase(); }
	function toggle (str) { return str.split('').map(function (l) { return isUpper(l) ? l.toLowerCase() : l.toUpperCase() }).join(''); }
	function isUpperString (str) { if (str.length < 2) return true; return !str.split('').slice(1).filter(function(l) { return !isUpper(l); }).length;}

	print(isUpperString(str) ? toggle(str) : str);

}).call(this);

var str = readline();
var l = str.length;
var mode;
for(var i = 1; i < l; ++i)
{
        if(str[i] >= "a" && str[i] <= "z")
        {
            mode = "none";
            break;
        }
}

if(mode == "none")
{
    print(str);
}
else
{
    mode = false;
    if(str[0] >= "a" && str[0] <= "z")
    {
        mode = true;
    }
    str = str.toLowerCase();
    if(mode)
    {
        var new_str = str[0];
        new_str = new_str.toUpperCase();
        new_str += str.substr(1);
        str = new_str;
    }
    print(str);
}

function unintentionallCaps(s) {
    return (s.substring(1, s.length) == s.substring(1, s.length).toUpperCase());
}

function isLowerCase(s) {
    return (s == s.toLowerCase());
}

function capitalizeFirstLetter(s) {
    return (s[0].toUpperCase().concat(s.substring(1, s.length).toLowerCase()));
}

var s = readline();

if (unintentionallCaps(s)) {
    print(isLowerCase(s[0]) ? capitalizeFirstLetter(s) : s.toLowerCase());
} else {
    print(s);
}

//var array = readline().split(" ").map(item => +item);
var line = readline(),
    regex = /^[a-z]?[A-Z]+$/g;

if (line.length === 1 && line.charCodeAt(0) >= 97) {
    print(String.fromCharCode(line.charCodeAt(i) - 32));
} else if (regex.test(line)) {
    var first = true,
        ans = "";

    for(var i = 0; i < line.length; i++) {
        if(line.charCodeAt(i) >= 97) {
            ans += String.fromCharCode(line.charCodeAt(i) - 32);
        } else {
            ans += String.fromCharCode(line.charCodeAt(i) + 32);
        }
    }

    print(ans);
} else {
    print(line);
}

//print((i - 1).toString());

str = readline();
if(str.length == str.replace(/[^A-Z]/g, "").length){print(str.toLowerCase())}
else if(str.length - 1 == str.slice(1).replace(/[^A-Z]/g, "").length)
{str = str.toLowerCase();
print(str.charAt(0).toUpperCase() + str.slice(1))}
else print(str);

s=readline()
if(s.toUpperCase()==s){
	s=s.toLowerCase();
}
else if(s==s[0].toLowerCase()+s.substr(1).toUpperCase()){
	s=s[0].toUpperCase()+s.substr(1).toLowerCase();
}
print(s);

var s = readline();
if(s === s.toUpperCase()){
    print(s.toLowerCase());
}
else if(s === s[0].toLowerCase() + s.slice(1).toUpperCase()){
    print(s[0].toUpperCase() + s.slice(1).toLowerCase());
}
else print(s);

var input = readline();
var primera = input.substring(1);
var mayus = primera.toUpperCase();
	if (input[0] === input[0].toUpperCase()){
		r = input[0].toLowerCase();
	}else {r = input[0].toUpperCase();}

	if ( mayus === primera ) {
		input = r + primera.toLowerCase();
	}
write(input);

var word = readline();

if(word.match(/^[A-Z]+$/)){
    word = word.toLowerCase();
}else if(word.match(/^[a-z][A-Z]*$/)){
    word = word.charAt(0).toUpperCase().concat(word.substr(1).toLowerCase());
}

print(word);

//var input = "A";
//var index = 0;
//
//function readline(){
//    var data = input.split('\n');
//    if(index < data.length)
//        return data[index++];
//}
//
//function print(output){
//    console.log(output);
//}

function main(){
    var str = readline();
    var reg = /\b([a-z]{1})([A-Z]{0,})\b/;
    if(reg.test(str)){
        var ans = str.replace(reg, function(match, p1, p2){
            return p1.toUpperCase() + p2.toLowerCase();
        });
    }else{
        reg = /\b([A-Z]{1,})\b/;
        ans = str.replace(reg, function(match){
            return match.toLowerCase();
        });
    }
    print(ans);
}
main();

    var input = readline()
    if (input === input.toUpperCase()) print(input.toLowerCase())
    else {
        var a = input[0]
        input = input.slice(1,input.length)
        if(input == input.toUpperCase()) print(a.toUpperCase() + input.toLowerCase())
        else {
            print(a + input)
        }
    }

var word = readline();

var head = word[0];
var tail = word.substring(1);

if (word == word.toUpperCase()) {
	word = word.toLowerCase();
} else if (head == head.toLowerCase() && tail == tail.toUpperCase()) {
	word = head.toUpperCase() + tail.toLowerCase();
}

print(word);

var _text = readline();
var text = _text.split('');
var textWithout1 = [...text];
	textWithout1.shift();
var isAccidentally  = true;
var isUpper = false;

var isUpperCase = function(letter){
	var character = letter.charAt(0);
	return character == character.toUpperCase();
};

for(var i = 0; i < textWithout1.length; i ++){
	if(!isUpperCase(textWithout1[i])){
		isAccidentally = false;
		print(_text);
		break;
	}
}

if(isUpperCase(text[0])){
	isUpper = true;
}

if(isAccidentally){
	var ans = text.map(function(letter, i){
		if(i == 0 && !isUpper){
			return letter.toUpperCase();
		}else{
			return letter.toLowerCase();
		}
	});

	print(ans.join(''));
}

var s = readline();
var subString = s.substring(1);
var subStringUpper = subString.toUpperCase();
if (subString == subStringUpper) {
    var swappedFirstChar = s[0].toUpperCase();
    if (swappedFirstChar == s[0]) {
        swappedFirstChar = swappedFirstChar.toLowerCase();
    }
    print(swappedFirstChar+subStringUpper.toLowerCase());
}
else {
    print(s);
}

function Capital(letter){
	return letter === letter.toUpperCase();
}

function program(input){
	var FirstLetter = input[0]
	var resword = input.slice(1,input.length);

 	if(!Capital(FirstLetter) && Capital(resword)){
 		return FirstLetter.toUpperCase() + resword.toLowerCase()
 	}
 	else if(Capital(input)){
 		return input.toLowerCase();
 	}
 	else{
 		return input
 	}

}
var input = readline();
print(program(input))

var str = readline();
var reg = /[a-z]+?/;
if (reg.test(str[0])&&reg.test(str.slice(1))==false)
print(str[0].toUpperCase()+str.slice(1).toLowerCase());
else if (reg.test(str)==false) print(str.toLowerCase());
else print(str);

function main() {
    var s = readline();
    if(s.length <= 1) {
        if(s === s.toLowerCase()) {
            s = s.toUpperCase();
        } else {
            s = s.toLowerCase();
        }
        print(s);
    } else {
        var i;
        for(i = 1 ; i < s.length ; i++) {
            if(s.charAt(i) !== s.charAt(i).toUpperCase()) {
                break;
            }
        }
        if(i === s.length) {
            var out = "";
            for(i = 0 ; i < s.length ; i++) {
                if(s.charAt(i) === s.charAt(i).toUpperCase()) {
                    out += s.charAt(i).toLowerCase();
                } else {
                    out += s.charAt(i).toUpperCase();
                }
            }
            print(out);
        } else {
            print(s);
        }
    }
}

main();

function capsLock(text){
    textAr = text[0].split("");
    var newAr = [], contain=false;
    notFirstChar = text[0].substr(1,(textAr.length - 1));
    if (text[0] == text[0].toUpperCase()){
        return text[0].toLowerCase();
    } else if (text[0] == text[0].toLowerCase() && textAr.length!=1){
        return text[0]
    }
    else if (notFirstChar == notFirstChar.toUpperCase() || notFirstChar == notFirstChar.toLowerCase()) {
      contain = true;
    }
    if(contain) {
      for (var i = 0; i<textAr.length; i++) {
          if(i==0){
              newAr.push(textAr[i].toUpperCase());
          }else{
              newAr.push(textAr[i].toLowerCase());
          }
      }

    return newAr.toString().replace(/,/g , "");
    }else{
        return text[0];
    }
    contain = false;
}

while(input = readline()){
    text=input.split(" ").map(function(x) { return x; });
    print(capsLock(text));
}

var inputStr = readline();

function isAllSymInCap(str) {
  var result = true;
  for (var i = 0; i < str.length; i++) {
    if (str.charAt(i) == str.charAt(i).toLowerCase()) {
      result = false;
      break;
    }
  }

  return result;
}

function isFirstInLowerAndOtherInUpper(str) {
  var result = true;

  if (str.charAt(0) == str.charAt(0).toLowerCase()) {
    for (var i = 1; i < str.length; i++) {
      if (str.charAt(i) == str.charAt(i).toLowerCase()) {
        result = false;
        break;
      }
    }
  } else {
    result = false;
  }

  return result;
}

function revertCase(str) {
  var newStr = '';

  for (var i = 0; i < str.length; i++) {
    if (str.charAt(i) == str.charAt(i).toLowerCase()) {
      newStr += (str.charAt(i).toUpperCase().toString());
    } else if (str.charAt(i) < str.charAt(i).toLowerCase()) {
      newStr += (str.charAt(i).toLowerCase().toString());
    }
  }

  return newStr;
}

if (isAllSymInCap(inputStr) || isFirstInLowerAndOtherInUpper(inputStr)) {
  print(revertCase(inputStr));
} else {
  print(inputStr);
}

function isupper(c) {
    return !(c.charCodeAt(0) & 0x20);
}

function othercase(c) {
    return String.fromCharCode(c.charCodeAt(0) ^ 0x20);
}
line = readline();
allcaps = line.split('').slice(1).every(isupper);
if (allcaps) {
    line = line.split('').map(othercase).join('');
}
print(line);

//TAG: regex

function main() {
	var textLine = readline();
	if (/^[a-z].*/.test(textLine) && !/^[a-z].*[a-z]+.*/.test(textLine)) {
		textLine = textLine.substring(0, 1).toUpperCase() + textLine.substring(1).toLowerCase();
	} else if (/^[A-Z].*/.test(textLine) && !/^[A-Z].*[a-z]+.*/.test(textLine)) {
		textLine = textLine.toLowerCase();
	}
	print(textLine);
}

main();

function main() {
	var textLine = readline();		//.split(' ');
	if (textLine.match(/^[a-z].*/) && !textLine.match(/^[a-z].*[a-z]+.*/)) {
		textLine = textLine.substring(0, 1).toUpperCase() + textLine.substring(1).toLowerCase();
	} else if (textLine.match(/^[A-Z].*/) && !textLine.match(/^[A-Z].*[a-z]+.*/)) {
		textLine = textLine.toLowerCase();
	}
	print(textLine);
}

main();

var input = readline();

var strUp = input.toUpperCase();

if(input === strUp)
    print(input.toLowerCase());
else if(input === input[0] + input.substr(1).toUpperCase() )
    print(input[0].toUpperCase() + input.substr(1).toLowerCase())
else print(input)

var text=readline();
var change=false;
function isLowerCase(c) {
    if(c>='a' && c<='z')
        return true;
    else
        return false;
}
var i;
var change=true;
if(isLowerCase(text[0])){
    i=1;
}
else{
    i=0;
}
for(;i<text.length;i++){
    if(isLowerCase(text[i])){
        change=false;
        break;
    }
}
if(change){
    var res='';
    for(i=0;i<text.length;i++){
        if(isLowerCase(text[i])){
            res+=text[i].toUpperCase();
        }
        else{
            res+=text[i].toLowerCase();
        }
    }
}
else
    res=text;
print(res);

function check(word) {
    if (word.length <= 1)
        return true;
    var res = true;
    for (var i = 1; i < word.length && res; i++) {
        if (word[i] !== word[i].toUpperCase())
            res = false;
    }
    return res;
}
var word = readline();
if (check(word)) {
    word = word.split('')
               .map(e => (e === e.toUpperCase())
                            ? e.toLowerCase()
                            : e.toUpperCase())
               .join('');
}
print(word);

var word = readline().split(''),
    willChange = false;
for (var i = 0; i < word.length; i++) {
    if (word[i] == word[i].toUpperCase()) {
        willChange = true;
    } else {
        willChange = false;
        break;
    }
}

if (willChange == false) {
    for (var j = 0; j < word.length - 1; j++) {
        if (word[0] == word[0].toLowerCase() && word[j + 1] == word[j + 1].toUpperCase()) {
            willChange = true;
        } else {
            willChange = false;
            break;
        }
    }
}

if (word.length == 1) {
    if (word[0] == word[0].toLowerCase()) {
        willChange = true;
    }
}

if (willChange) {
    for (var a = 0; a < word.length; a++) {
        if (word[a] == word[a].toLowerCase()) {
            word[a] = word[a].toUpperCase();
        } else {
            word[a] = word[a].toLowerCase();
        }
    }
}

print(word.join(''));

var str = readline(),
    flag = true,
    res = '';

function isUpper(s) {
    return s === s.toUpperCase() ? true : false;
}

for (var i = 1; i < str.length; i++) {
    if (!isUpper(str[i])) flag = false;
}

if (flag) {
    for (var i = 0; i < str.length; i++) {
        var s = str[i];
        if (isUpper(s)) {
            s = s.toLowerCase();
        } else {
            s = s.toUpperCase();
        }
        res += s;
    }

    print(res);
} else {
    print(str);
}

var str = readline(),
    flag = true,
    res = '';

function isUpper(s) {
    return s === s.toUpperCase() ? true : false;
}

for (var i = 1; i < str.length; i++) {
    if (!isUpper(str[i])) flag = false;
}

if (flag) {
    for (var i = 0; i < str.length; i++) {
        var s = str[i];
        res += isUpper(s) ? s.toLowerCase() : s.toUpperCase();
    }

    print(res);
} else {
    print(str);
}

function checkToNonDetermineToCondition(str)
{
	str = str.split('');
    var res = true;
    for (var i = 1; i <= str.length - 1; i++)
    {
        if ('A'.charCodeAt(0) <= str[i].charCodeAt(0) && str[i].charCodeAt(0) <= 'Z'.charCodeAt(0)) res = true;
        else {
            res = false;
            break;
        }

    }
    if (res)
    {
        for (i = 0; i <= str.length - 1; i++)
		{
			if ('A'.charCodeAt(0) <= str[i].charCodeAt(0) && str[i].charCodeAt(0) <= 'Z'.charCodeAt(0)) str[i] = str[i].toLowerCase();
			else str[i] = str[i].toUpperCase();
		}
    }
    return str.join('');
}
{
    var input = readline();
    print(checkToNonDetermineToCondition(input));
}

data = readline();
if (doesMatch(data))
{
    print(changedCaseString(data));
}
else
{
   print(data);
}

function doesMatch(data)
{
    upperCaseAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    lowerCaseAlphabet = "abcdefghijklmnopqrstuvwxyz"

    stringLength = data.length;
    flag = true;
    for(index = 1; index < stringLength; index++)
        {
            if (lowerCaseAlphabet.indexOf(data[index]) !== -1)
                {
                    flag = false;
                    break;
                }
        }

   if (lowerCaseAlphabet.indexOf(data[0]) !== -1 ||  upperCaseAlphabet.indexOf(data[0]) !== -1)
   {
       if (flag)
       {
           return true;
       }
   }
   return false;
}

function changedCaseString(data)
{
    result = '';
    for(index = 0; index < data.length; index++)
    {
        if (data[index] === data[index].toLowerCase())
        {
           result += data[index].toUpperCase();
        }
        else
        {
            result += data[index].toLowerCase();
        }
    }
    return result
}

var s = readline();
var s1,s2;
var f = 1;
for(var i = 1; i < s.length; i++){
	if(s.charCodeAt(i) >=97 && s.charCodeAt(i) <= 122){
		f = 0;
		break;
	}
}
if(s.length==1){
	if(s.charCodeAt(0) >=97 && s.charCodeAt(0) <= 122)
		print(s.toUpperCase());
	else
		print(s.toLowerCase());
}
else if(f){
	if(s.charCodeAt(0) >=65 && s.charCodeAt(0) <= 90)
		print(s.toLowerCase());
	else{
		s1 = s.slice(0,1).toUpperCase();
		s2 = s.slice(1,s.length).toLowerCase();
		print(s1+s2);
	}

}
else
	print(s);

var s = readline().split( '' );
print(
    s.every( function(s) { return s === s.toUpperCase(); } ) || s.every( function(s, i) { return !i && s === s.toLowerCase() || i && s === s.toUpperCase(); } )
        ? s.map( function(s) { return s === s.toLowerCase() ? s.toUpperCase() : s.toLowerCase(); } ).join( '' )
        : s.join( '' )
);

var word = readline();
var result = '';

if(word.length === 1) {
         if(isLowerCase(word)) {
            result = word.toUpperCase();
         }
         else {
            result = word.toLowerCase();
         }
   }

if(word.length > 1) {

   var wrngWrd = true;

   for(var i = 1; i < word.length; i++) {
      if(isLowerCase(word[i])) {
         wrngWrd = false;
         break;
      }
   }

   if(! wrngWrd) {
      result = word;
   }

   else {
      result = convrtWrd(word);
   }
}

print(result);

function isLowerCase(chrctr){
   return chrctr.toLowerCase() === chrctr;
}

function convrtWrd (word) {
   result = '';
   if(isLowerCase(word[0])) {
      result += word[0].toUpperCase();
      result += word.slice(1).toLowerCase();
   }
   else {
      result = word.toLowerCase();
   }
   return result;
}

var word=readline().split('');

var flg= false;
for(var i=1;i<word.length;i++){
	if( !(word[i]>='A'&&word[i]<='Z') ){
		flg=true;
	}
}

if(!flg){
	if(word[0]>='A'&&word[0]<='Z'){
		word[0]=word[0].toLowerCase();
	}else{
		word[0]=word[0].toUpperCase();
	}

	for(var i=1; i<word.length; i++){
		word[i]=word[i].toLowerCase();
	}
}
print(word.join(''));

var str = readline();
var mayus = str.toUpperCase();
if(str==mayus){
    print(str.toLowerCase());
}else{
    if(str[0]!=mayus[0] && str.slice(1)==mayus.slice(1)){
        print(str[0].toUpperCase()+str.toLowerCase().slice(1));
    }else{
        print(str)
    }
}

var inp = readline(),
    valid = true,
    el = '';

for(var i=1; i<=inp.length-1; i++) {
    el = inp[i];
    if(el.charCodeAt(0) < 65 || el.charCodeAt(0) > 90) valid = false;
}

if(valid) {

    if(inp[0].charCodeAt(0) >= 65 && inp[0].charCodeAt(0) <= 90) {
        inp = inp.toLowerCase().split('');
        inp[0] = inp[0].toLowerCase();
    } else {
        inp = inp.toLowerCase().split('');
        inp[0] = inp[0].toUpperCase();
    }

    inp = inp.join('');
}

print(inp);

(function main() {
    var inWord = readline(),
        result = inWord;

    function isCaps(word) {
        return !!word.match(/^.[A-Z]*$/g);
    }

    function fix(word) {
        var firstChar = word.charAt(0);
        if (firstChar.match(/[A-Z]/)) {
            firstChar = firstChar.toLowerCase();
        } else {
            firstChar = firstChar.toUpperCase();
        }

        return firstChar + word.slice(1).toLowerCase();
    }

    if (isCaps(inWord)) {
        result = fix(inWord);
    }

    print(result);
})();

const input = [];

function splbsi(line) {
  return line.split(" ").map((x) => parseInt(x));
}

const readLine = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

readLine.on("line", (line) => {
  input.push(line);
});

readLine.on("close", () => {
  const str = input[0];

  if (str === str.toUpperCase()) {
    console.log(str.toLowerCase());
    return;
  }

  if (
    str[0].toLowerCase() === str[0] &&
    str.slice(1).toUpperCase() === str.slice(1)
  ) {
    console.log(`${str[0].toUpperCase()}${str.slice(1).toLowerCase()}`);
    return;
  }

  console.log(str);
});

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let currentLine = 0;
let inputString = "";

process.stdin.on("data", (raw_data) => {
  inputString += raw_data;
});

process.stdin.on("end", (_) => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readLine() {
  return inputString[currentLine++];
}

/******** Main function*************/

function isLowerCase(str) {
  return str == str.toLowerCase() && str != str.toUpperCase();
}

function main() {
  var str = readLine().split("");
  var string = str.join("");
  var Fstr = str[0];
  var EFstr = str.slice(1);

  var count = 0;
  var eFstrCount = 0;

  for (var i = 0; i < EFstr.length; i++) {
    if (isLowerCase(EFstr[i]) === false) {
      eFstrCount++;
    }
  }

  for (var j = 0; j < str.length; j++) {
    if (isLowerCase(str[j]) === false) {
      count++;
    }
  }

  if (eFstrCount == EFstr.length && isLowerCase(Fstr)) {
    console.log(Fstr.toUpperCase() + EFstr.join("").toLowerCase());
  } else if (count === str.length) {
    console.log(string.toLowerCase());
  } else {
    console.log(string);
  }
}

// either it only contains uppercase letters;
// or all letters except for the first one are uppercase.

let fs = require("fs");

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0;
});
for (let i = 0; i < txt.length; i ++) {
    doit(txt[i]);

}

function doit(str) {
    let tab =str.split("").filter(data=>{return data.length>0});
    let stab=[]
    tab.forEach(data => {
        if(data.charCodeAt()<97){
            stab.push("U");
        }else{
            stab.push("L")
        }
    });
    let r=stab.filter(data=>{return data=="L"}).length
    if(r==0 ||(r==1 && stab[0]=="L")){
        tab.forEach((data,index)=>{
            if(data.charCodeAt()<97){
                stab[index]=data.toLowerCase()
            }else{
                stab[index]=data.toUpperCase()
            }
        })
        console.log(stab.join(""));

    }else{
        console.log(str);

    }

}

var word = readline(),
    res = '';

if ( word[0] && ((word[0].toLowerCase() == word[0] && isAllUpper(word.substring(1, word.length))) || isAllUpper(word)) ) {
    res = swapUpperLowerCase(word);
} else {
    res = word;
}

print( res );

function isAllUpper(word) {
    for (var i = 0; i < word.length; i++) {
        if ( word[i].toUpperCase() != word[i] ) {
            return false;
        }
    }

    return true;
}

function swapUpperLowerCase(word) {
    var res = '';

    for (var i = 0; i < word.length; i++) {
        if ( word[i].toLowerCase() == word[i] ) {
            res += word[i].toUpperCase();
        } else {
            res += word[i].toLowerCase();
        }
    }

    return res;
}

var s = readline();
var s1, s2;

if ((s1 = s) === s.toUpperCase())
	print(s1.toLowerCase());
else if (s[0] === s[0].toLowerCase() && (s2 = s.substring(1)) === s.substring(1).toUpperCase())
	print(s[0].toUpperCase() + s2.toLowerCase());
else
	print (s);

var txt = readline();
var k = txt;
if(/^([a-z]{1})([A-Z]*)$/.test(txt)) {
    txt = txt.toLowerCase();
    k = txt.replace(txt[0], txt[0].toUpperCase());
}
if(/^[A-Z]+$/.test(txt)) {
k = txt.replace(/^[A-Z]+$/, txt.toLowerCase());
}
print(k);

var txt = readline();
var k = txt.split('');
var a = k.sort();
var l;
if(txt.length>1){

 if(a[0] >= "A" && a[a.length-1] <= "Z") {
    txt = txt.toLowerCase();
}
else if(txt[0]>= "a"  && a[a.length-2] <= "Z") {
    txt = txt.toLowerCase();
    l = txt[0].toUpperCase();
    txt = txt.replace(txt[0], l);
    }
}
else {
    if(txt[0]>= "A"  && a[0] <= "Z"){
        txt = txt.toLowerCase();
    }
    else
        txt = txt.toUpperCase();
}

print(txt);

var w = readline();
function isUp(ch) {
    if (ch == ch.toUpperCase()) {
        return true;
       }
    return false;
}

if (w.length>1&&!isUp(w[0]) && isUp(w[1])){
    if (w.toUpperCase().substring(1) == w.substring(1)){
        w = w[0].toUpperCase() + w.toLowerCase().substring(1);

    }
}
if (w.toUpperCase() === w) {
    w = w.toLowerCase()
}else if (w.length === 1){
    if (w.toUpperCase() === w){
        w = w.toLowerCase();
    }else{
        w = w.toUpperCase();
    }
}
write(w)

var word = readline(), counter = 0;

if( word.charAt(0) < "a" ){
	for(i = 1; i < word.length; i++){
		if( word.charAt(i) < "a" ){
			counter++;
		}
	}
	if( counter+1 == word.length ){
		write(word.toLowerCase());
	}
	else{
		write(word);
	}
}
else{
	for(i = 1; i < word.length; i++){
		if( word.charAt(i) < "a" ){
			counter++;
		}
	}
	if( counter+1 == word.length ){
		write(word.charAt(0).toUpperCase());
		write(word.substring(1).toLowerCase());
	}
	else{
		write(word);
	}
}

  var word = readline();
  if(word.length==1){
    print(word === word.toUpperCase()? word.toLowerCase() : word.toUpperCase());
  } else if(word === word.toUpperCase()){
    print(word.toLowerCase());
  } else{
    var first = word.substring(0,1);
    var rest = word.substring(1);
    if(rest === rest.toUpperCase()){
      print(first.toUpperCase()+rest.toLowerCase());
    } else {
      print(word);
    }
  }

var lee = readline();

if (lee.slice(1) == lee.slice(1).toUpperCase() && lee[0] == lee[0].toLowerCase()) {
	print(lee[0].toUpperCase() + lee.slice(1).toLowerCase());
} else if(lee == lee.toUpperCase()) {
	print(lee.toLowerCase());
} else {
    print(lee);
}

'use strict';

/*let input = `
cAPS
`.trim().split('\n');
function print(output) {
	console.log(output);
}
function readline() {
	return input.shift();
}*/

//code

var upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split('');
var lowerCase = "abcdefghijklmnopqrstuvwxyz".split('');

var str = readline();
var strArr = str.split(''),
    i = void 0;
for (i = 1; i < strArr.length; i++) {
	if (upperCase.indexOf(strArr[i]) === -1) {
		break;
	}
}
if (i === strArr.length) {
	var newArr = [];
	for (var j = 0; j < strArr.length; j++) {
		if (lowerCase.indexOf(strArr[j]) !== -1) {
			newArr.push(upperCase[lowerCase.indexOf(strArr[j])]);
		} else {
			newArr.push(lowerCase[upperCase.indexOf(strArr[j])]);
		}
	}
	print(newArr.join(''));
} else {
	print(str);
}

(function main() {
    var line = readline();

    if (line === line.toUpperCase()){

        print(line.toLowerCase());
    } else {

        var first = line[0];
        var rest = line.slice(1, line.length);
        if ((first === first.toLowerCase()) && (rest == rest.toUpperCase())){
            print(first.toUpperCase() + rest.toLowerCase());
        } else {
            print(line);
        }
    }

    return 0;
})();

let readline = require('readline');
let rl = readline.createInterface({
	input: process.stdin,
	output: process.stdout
});

rl.on('line', function(line) {
	capsLock(line);
	rl.close();
});

let capsLock = (input) => {
	if (checkStr(input.substring(1))) {
		let firstChar = input.charAt(0);
		checkStr(firstChar) ? (firstChar = firstChar.toLowerCase()) : (firstChar = firstChar.toUpperCase());
		console.log(firstChar + '' + input.substring(1).toLowerCase());
	} else {
		console.log(input);
	}
};

let checkStr = (str) => {
	return str === str.toUpperCase();
};

var n = readline();
var c = n.substring(1);
var p = c.toUpperCase();
if (n[0] === n[0].toUpperCase()) r = n[0].toLowerCase();
else r = n[0].toUpperCase();
if ( p === c ) {
    n = r + c.toLowerCase();
}
write(n);

var n = readline();

var on = true;

for (var i = 1; i < n.length; ++i) {
    if (n[i] != n[i].toUpperCase()) {
        on = false;
        break;
    }
}

var n0 = n[0].toLowerCase();

if (on) {
    if (n0 == n[0])
        print(n[0].toUpperCase() + n.substring(1).toLowerCase());
    else
        print(n0 + n.substring(1).toLowerCase());
} else {
    print(n);
}

function main(){

var line = readline();

var a = line.slice(1);
var b = a.toUpperCase();
var c = a.toLowerCase();
var d = "";
var e = line[0];

if(line.slice(1)===b){
    if(line[0]===e.toUpperCase()){
	d+=e.toLowerCase()+c;
	print(d);
	return;
    }else{
	d+=e.toUpperCase()+c;
	print(d);
	return;
    }
}

print(line);
}

main();

"use strict";

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

readline.on('line', line => {
    readline.close(), console.log(capsLocks(line));
});
const capsLocks = (word) => {
    const upperCase = /^[A-ZÑ]+$/g;

    if (word.length > 1) {
        const first = word.charAt(0);
        const last = word.slice(1);

        if (upperCase.test(word))
            return word.toLowerCase();
        else if (upperCase.test(last) && !upperCase.test(first))
            return first.toUpperCase() + last.toLowerCase();
        else
            return word;
    }
    else
        if (!upperCase.test(word))
            return word.toUpperCase();
        else
            return word.toLowerCase();
}

var input = readline();

var arr = input.split('');
var lowerCaseFlag = false;
var upperCaseFlag = false;
var firstLowerCase = false;

if (arr[0] == arr[0].toLowerCase())
    firstLowerCase = true;

for (var i = 1; i < arr.length; i++) {
    if (arr[i] == arr[i].toLowerCase())
        lowerCaseFlag = true;
    if (arr[i] == arr[i].toUpperCase())
        upperCaseFlag = true;
}

var change = false;
if (firstLowerCase && upperCaseFlag && !lowerCaseFlag) change = true;
else if (!firstLowerCase && upperCaseFlag && !lowerCaseFlag) change = true;
else if (firstLowerCase && !upperCaseFlag && !lowerCaseFlag) change = true;
else if (!firstLowerCase && !upperCaseFlag && !lowerCaseFlag) change = true;

if (change) {
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] == arr[i].toLowerCase())
            arr[i] = arr[i].toUpperCase();
        else if (arr[i] == arr[i].toUpperCase())
            arr[i] = arr[i].toLowerCase();
    }
}
write(arr.join(''));

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

readline.on('line', line => {
    readline.close(), console.log(capsLocks(line));
});
const capsLocks = (word) => {
    const upperCase = /^[A-ZÑ]+$/g;

    if (word.length > 1)
        if (upperCase.test(word))
            return word.toLowerCase();
        else if (upperCase.test(word.slice(1)) && !upperCase.test(word.charAt(0)))
            return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
        else
            return word;
    else
        if (!upperCase.test(word))
            return word.toUpperCase();
        else
            return word.toLowerCase();
}

var s = readline();
var u = true;
for(var i=1; i<s.length; i++){
    if(s[i]!==s[i].toUpperCase()){
        print(s);
        u = false;
        break;
    }
}
var f = s[0]===s[0].toUpperCase() ? s[0].toLowerCase() : s[0].toUpperCase();
if(u) print(f + s.slice(1).toLowerCase());

var s = readline()
var b = s

if(s[0].toLowerCase() + s.slice(1, s.length).toUpperCase() == b){
    s = s[0].toUpperCase() + b.slice(1,s.length).toLowerCase()
    print(s)
}else if (b == s.toUpperCase()){
    print(b.toLowerCase())
}else{
    print(b)
}

var word = readline();

var A = 'A'.codePointAt(0);
var Z = 'Z'.codePointAt(0);
var delta = 'a'.codePointAt(0) - A;

var upper = true;
for (var i = 1; i < word.length; i++) {
    var c = word.codePointAt(i);
    if (c < A || c > Z) {
        upper = false;
        break;
    }
}
if (upper) {
    var r = word.codePointAt(0);
    if (r < A || r > Z) {
        r -= delta;
    } else {
        r += delta;
    }
    r = String.fromCodePoint(r);
    for (var i = 1; i < word.length; i++) {
        r += String.fromCodePoint(word.codePointAt(i) + delta);
    }
    print(r);
} else {
    print(word);
}

function readNums() {
    return readline().split(' ').map(v => v - 0);
}

print(wrongCaps(readline()));

function wrongCaps(word){
	if(/^[A-Z]*$/.test(word)){
		return word.toLowerCase();
	} else if (/^[a-z]{1}[A-Z]*$/.test(word)){
		var firstChar = word.slice(0,1).toUpperCase();
		var otherChars = word.slice(1).toLowerCase();
		return firstChar+otherChars;
	} else{
		return word;
	}
}

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

const isCapitalize = ch => ch === ch.toUpperCase();

readLine.on('close', () => {
  const str = input[0];
  let flag = true;

  if (str.length === 1) {
    if (!isCapitalize(str[0]))
     console.log(str.toUpperCase());
    else
      console.log(str.toLowerCase());
    return
  }

  for (let i = 1; i < str.length; i += 1) if(!isCapitalize(str[i])) flag = false;

  if (flag) {
    if (isCapitalize(str[0]))
      console.log(str[0].toLowerCase() + str.slice(1).toLowerCase());
    else
      console.log(str[0].toUpperCase() + str.slice(1).toLowerCase());
    return;
  }

  console.log(str);
});

// wHAT DO WE NEED cAPS LOCK FOR?

// Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.

// Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:

//     either it only contains uppercase letters;
//     or all letters except for the first one are uppercase.

// In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.

// Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.

// Input
// The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.

// Output
// Print the result of the given word's processing.

var s = readline()
var len = s.length
var sb = s.substring(1,len)

function isL (x){
    return x === x.toLowerCase()
}

function isU (x){
    return x === x.toUpperCase()
}

if ((len === 1 && isU(s)) || isU(s)){
    print(s.toLowerCase())
}
else if (isL(s[0]) && isU(sb)){
    print(s[0].toUpperCase()+sb.toLowerCase())
}else {
    print(s)
}

function isCompleteCaps(word) {
    return word.toUpperCase() == word;
}

function isPartialCaps(word) {
    var first = word[0];
    var rest = word.slice(1);
    return (
        first.toLowerCase() == word[0] && rest.toUpperCase() == word.slice(1)
    );
}

function removeCapsLock(word) {
    if (isPartialCaps(word)) {
        var first = word[0];
        var rest = word.slice(1);
        return first.toUpperCase() + rest.toLowerCase();
    } else if (isCompleteCaps(word)) {
        var first = word[0];
        var rest = word.slice(1);
        return first.toLowerCase() + rest.toLowerCase();
    }
    return word;
}

var input = readline();

print(removeCapsLock(input));

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let a = readLine();
  if (a.toUpperCase() === a) {
    console.log(a.toLowerCase());
  } else if (a[0].toLowerCase() + a.substring(1).toUpperCase() === a) {
    console.log(a[0].toUpperCase() + a.substring(1).toLowerCase());
  } else {
    console.log(a);
  }
}

eil = readline();
neil = eil.substr(1);
ueil = neil.toUpperCase();
if (eil[0] == eil[0].toUpperCase()) r = eil[0].toLowerCase();
else r = eil[0].toUpperCase();
if (ueil == neil){
	eil = r + neil.toLowerCase();
}
write(eil);

var input = readline();
if (input.slice(1) == input.slice(1).toUpperCase()){
	print(  input[0].toUpperCase() + input.slice(1).toLowerCase()  );

} else {
	print(input);
}

var s = readline()
var b = s

if(b == s.toUpperCase() || s[0].toLowerCase() + s.slice(1, s.length).toUpperCase() == b){
    s = s[0].toUpperCase() + b.slice(1,s.length).toLowerCase()
    print(s)
}else{
    print(b)
}

var str = readline();
var reg = /[a-z]+?/;
if (reg.test(str[0])&&reg.test(str.slice(1))==false||reg.test(str)==false)
print(str[0].toUpperCase()+str.slice(1).toLowerCase());
else
print(str);

var string = readline();

for (var i=0; i<string.length; i++) {
	if (i < 1) {
		string[i] = string.charAt(i).toUpperCase();
	} else {
		string[i] == string.charAt(i).toLowerCase();
	}
}

print(string);

var w = readline();
function isUp(ch) {
    if (ch == ch.toUpperCase()) {
        return true;
       }
    return false;
}

if (w.length>1&&!isUp(w[0]) && isUp(w[1])){
    if (w.toUpperCase().substring(1) == w.substring(1)){
        w = w[0].toUpperCase() + w.toLowerCase().substring(1);

    }
}
if (w.toUpperCase() == w) {
    w = w.toLowerCase()
}
if (w.length === 1){
    if (w.toUpperCase() == w){
        w = w.toLowerCase();
    }else{
        w = w.toUpperCase();
    }
}
write(w)

var str = readline();

 if (str.search(/[A-Z]/)>0){
	print(str[0].toUpperCase()+str.slice(1).toLowerCase());
	}

	else if(str.search(/[A-Z]/)==0 && str.slice(1).search(/[A-Z]/>0)){
	print(str[0].toUpperCase()+str.slice(1).toLowerCase());
	}

function Caps(word)
{
    var i = 0;
    word = word.split('');
    word[0] = word[0].toUpperCase();
    while (i < word.length)
    {
        word[i] = word[i].toLowerCase();
        i++;
    }
    return word.join('');
}

{
    var input = readline();
    print(Caps(input));
}

data = readline();
if (doesMatch(data))
{
    print(data[0].toUpperCase() + data.slice(1).toLowerCase());
}
else
{
   print(data);
}

function doesMatch(data)
{
    upperCaseAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    lowerCaseAlphabet = "abcdefghijklmnopqrstuvwxyz"

    stringLength = data.length;
    flag = true;
    for(index = 1; index < stringLength; index++)
        {
            if (lowerCaseAlphabet.indexOf(data[index]) !== -1)
                {
                    flag = false;
                    break;
                }
        }

   if (lowerCaseAlphabet.indexOf(data[0]) !== -1 ||  upperCaseAlphabet.indexOf(data[0]) !== -1)
   {
       if (flag)
       {
           return true;
       }
   }
   return false;
}

const input = readline()

if(input == input.toUpperCase() || /^[a-z][A-Z]*$/.test(input)) {
    print(`{input[0].toUpperCase()}${input.slice(1).toLowerCase()}`)
} else {
    print(input)
}

  var word = readline();
  if(word.length==1){
    print(word);
  } else if(word === word.toUpperCase()){
    print(word.toLowerCase());
  } else{
    var first = word.substring(0,1);
    var rest = word.substring(1);
    if(rest === rest.toUpperCase()){
      print(first.toUpperCase()+rest.toLowerCase());
    } else {
      print(word);
    }
  }

var word = readline();
if (word[0].toLowerCase() && !word.slice(1).toUpperCase()) {
	print(word[0].toUpperCase() + word.slice(1).toLowerCase());
} else print(word);

var word = readline().split(''),
    willChange = false;
for (var i = 0; i < word.length; i++) {
    if (word[i] == word[i].toUpperCase()) {
        willChange = true;
    } else {
        willChange = false;
        break;
    }
}

for (var j = 0; j < word.length - 1; j++) {
    if (word[0] == word[0].toLowerCase() && word[j + 1] == word[j + 1].toUpperCase()) {
        willChange = true;
    } else {
        willChange = false;
        break;
    }
}

if(willChange){
    word[0] = word[0].toUpperCase();
    for (var a = 0; a < word.length - 1; a++) {
        word[a+1] = word[a+1].toLowerCase();
    }
}
print(word.join(''));

function main() {
    var s = readline();
    if(s.length <= 1) {
        print(s.toUpperCase());
    } else {
        var i;
        for(i = 1 ; i < s.length ; i++) {
            if(s.charAt(i) !== s.charAt(i).toUpperCase()) {
                break;
            }
        }
        if(i === s.length) {
            var out = "";
            for(i = 0 ; i < s.length ; i++) {
                if(s.charAt(i) === s.charAt(i).toUpperCase()) {
                    out += s.charAt(i).toLowerCase();
                } else {
                    out += s.charAt(i).toUpperCase();
                }
            }
            print(out);
        } else {
            print(s);
        }
    }
}

main();

var word = readline();
var result = '';

if(word.length === 1) {
         if(!isLowerCase(word)) {
            result = word.toLowerCase();
         }
         else {
            result = word;
         }
   }

if(word.length > 1) {

   var wrngWrd = true;

   for(var i = 1; i < word.length; i++) {
      if(isLowerCase(word[i])) {
         wrngWrd = false;
         break;
      }
   }

   if(! wrngWrd) {
      result = word;
   }

   else {
      result = convrtWrd(word);
   }
}

print(result);

function isLowerCase(chrctr){
   return chrctr.toLowerCase() === chrctr;
}

function convrtWrd (word) {
   result = '';
   if(isLowerCase(word[0])) {
      result += word[0].toUpperCase();
      result += word.slice(1).toLowerCase();
   }
   else {
      result = word.toLowerCase();
   }
   return result;
}

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

// single line input
readline.on('line', line => {
    readline.close(), console.log(capsLocks(line));
});
const capsLocks = (word) => {
    const upperCase = /^[A-ZÑ]+$/g;

    if (upperCase.test(word))
        return word.charAt(0) + word.slice(1).toLowerCase();
    else if (upperCase.test(word.slice(1)) && !upperCase.test(word.charAt(0)))
        return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
    else
        return word;
}

data = readline();
if (doesMatch(data))
{
    print(data.toLowerCase());
}
else
{
   print(data);
}

function doesMatch(data)
{
    upperCaseAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    lowerCaseAlphabet = "abcdefghijklmnopqrstuvwxyz"

    stringLength = data.length;
    flag = true;
    for(index = 1; index < stringLength; index++)
        {
            if (lowerCaseAlphabet.indexOf(data[index]) !== -1)
                {
                    flag = false;
                    break;
                }
        }

   if (lowerCaseAlphabet.indexOf(data[0]) !== -1 ||  upperCaseAlphabet.indexOf(data[0]) !== -1)
   {
       if (flag)
       {
           return true;
       }
   }
   return false;
}

var str = readline(),
    flag = true,
    res = str[0].toUpperCase();

function isUpper(s) {
    return s === s.toUpperCase() ? true : false;
}

for (var i = 1; i < str.length; i++) {
    if (!isUpper(str[i])) flag = false;
}

if (flag) {

    for (var i = 1; i < str.length; i++) {
        if (isUpper(str[i])) s = str[i].toLowerCase();
        res += s;
    }

    print(res);
}

//var input = "CaPS";
//var index = 0;
//
//function readline(){
//    var data = input.split('\n');
//    if(index < data.length)
//        return data[index++];
//}
//
//function print(output){
//    console.log(output);
//}

function main(){
    var str = readline();
    var reg = /\b([a-z]{1})([A-Z]{1,})\b/;
    var ans = str.replace(reg, function(match, p1, p2){
        return p1.toUpperCase() + p2.toLowerCase();
    });
    reg = /\b([A-Z]{1,})\b/;
    ans = ans.replace(reg, function(match, p1){
        return match.toLowerCase();
    });
    print(ans);
}
main();

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

const isCapitalize = ch => ch === ch.toUpperCase();

readLine.on('close', () => {
  const str = input[0];
  let flag = true;

  if (str.length === 1) {console.log(str); return}

  for (let i = 1; i < str.length; i += 1) if(!isCapitalize(str[i])) flag = false;

  if (flag) {
    console.log(str[0].toUpperCase() + str.slice(1).toLowerCase());
    return;
  }

  console.log(str);
});

var str = readline();
print(str[0].toUpperCase()+str.slice(1).toLowerCase());

'use strict';
const str = readline();
const isCaps = function(char) {
    return char === char.toUpperCase();
}

let caps = true;

str.split('').slice(1).map(function(char){
    if(!isCaps(char)) {
       caps = false;
    }
})

if(caps) {
    write(str[0].toUpperCase() + str.substr(1).toLowerCase());
} else {
    write(str);
}

var word = readline().split(''),
    willChange = false;

for (var j = 0; j < word.length - 1; j++) {
    if (word[0] == word[0].toLowerCase() && word[j + 1] == word[j + 1].toUpperCase()) {
        willChange = true;
    } else {
        willChange = false;
        break;
    }
}

for (var i = 0; i < word.length; i++) {
    if (word[i] == word[i].toUpperCase()) {
        willChange = true;
    } else {
        willChange = false;
        break;
    }
}

if(willChange){
    word[0] = word[0].toUpperCase();
    for (var a = 0; a < word.length - 1; a++) {
        word[a+1] = word[a+1].toLowerCase();
    }
}
print(word.join(''));

(function main() {

    var inWord = readline(),
        result = inWord;

    function isCaps(word) {
        return !!word.match(/^.[A-Z]+$/g);
    }

    function fix(word) {
        var firstChar = word.charAt(0);
        if (firstChar.match(/[A-Z]/)) {
            firstChar = firstChar.toLowerCase();
        } else {
            firstChar = firstChar.toUpperCase();
        }

        return firstChar + word.slice(1).toLowerCase();
    }

    if (isCaps(inWord)) {
        result = fix(inWord);
    }

    print(result);
})();

const input = readline()

if(input == input.toUpperCase() || /^[a-z][A-Z]*$/.test(input)) {
    print(`{input[0].toUpperCase()}${input.slice(1).toLowerCase()}`)
}
print(input)

var s = readline();
var u = true;
for(var i=1; i<s.length; i++){
    if(s[i]!==s[i].toUpperCase()){
        print(s);
        u = false;
        break;
    }
}
var f = s[0]===s[0].toUpperCase() ? s[0].toLowerCase() : s[0].toUpperCase();
if(u) print(f + s.slice(1));

function capsLock(text){
    textAr = text[0].split("");
    var newAr = [], contain=false;
    notFirstChar = text[0].substr(1,(textAr.length - 1));
    if (text[0] == text[0].toUpperCase()){
        return text[0].toLowerCase();
    }else if (notFirstChar == notFirstChar.toUpperCase() || notFirstChar == notFirstChar.toLowerCase()) {
      contain = true;
    }
    if(contain) {
      for (var i = 0; i<textAr.length; i++) {
          if(i==0){
              newAr.push(textAr[i].toUpperCase());
          }else{
              newAr.push(textAr[i].toLowerCase());
          }
      }

    return newAr.toString().replace(/,/g , "");
    }else{
        return text[0];
    }
    contain = false;
}

while(input = readline()){
    text=input.split(" ").map(function(x) { return x; });
    print(capsLock(text));
}

const input = readline()

if(input == input.toUpperCase() || /^[a-z][A-Z]+$/.test(input)) {
    print(`${input[0].toUpperCase()}${input.slice(1).toLowerCase()}`)
} else {
    print(input)
}

  var word = readline();
  if(word.length==1){
    print(word.toUpperCase());
  } else if(word === word.toUpperCase()){
    print(word.toLowerCase());
  } else{
    var first = word.substring(0,1);
    var rest = word.substring(1);
    if(rest === rest.toUpperCase()){
      print(first.toUpperCase()+rest.toLowerCase());
    } else {
      print(word);
    }
  }

str = readline();
if(str.length - 1 == str.slice(1).replace(/[^A-Z]/g, "").length)
{str = str.toLowerCase();
print(str.charAt(0).toUpperCase() + str.slice(1))}
else print(str);

var word = readline();

if(word.match(/^[A-Z]+$/)){
    word = word.toLowerCase();
}else if(word.match(/^[a-z][A-Z]+$/)){
    word = word.charAt(0).toUpperCase().concat(word.substr(1).toLowerCase());
}

print(word);

var word = readline();
var result = '';

if(word.length === 1) {
         if(isLowerCase(word)) {
            result = word.toUpperCase();
         }
         else {
            result = word;
         }
   }

if(word.length > 1) {

   var wrngWrd = true;

   for(var i = 1; i < word.length; i++) {
      if(isLowerCase(word[i])) {
         wrngWrd = false;
         break;
      }
   }

   if(! wrngWrd) {
      result = word;
   }

   else {
      result = convrtWrd(word);
   }
}

print(result);

function isLowerCase(chrctr){
   return chrctr.toLowerCase() === chrctr;
}

function convrtWrd (word) {
   result = '';
   if(isLowerCase(word[0])) {
      result += word[0].toUpperCase();
      result += word.slice(1).toLowerCase();
   }
   else {
      result = word.toLowerCase();
   }
   return result;
}

var n = readline().toLowerCase();
var p = n[0].toUpperCase();
var c = n.substring(1);
p += c;
print(p.concat());

str = readline()
print(str.charAt(0).toUpperCase() + str.slice(1).toLowerCase)

var n = readline();

var on = true;

for (var i = 1; i < n.length; ++i) {
    if (n[i] != n[i].toUpperCase()) {
        on = false;
        break;
    }
}

if (on)
    print(n[0].toUpperCase() + n.substring(1).toLowerCase());
else
    print(n);

var line = readline().toLowerCase();

var newline = line[0].toUpperCase() + line.slice(1);

print (newline);

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

readline.on('line', line => {
    readline.close(), console.log(capsLocks(line));
});
const capsLocks = (word) => {
    const upperCase = /^[A-ZÑ]+$/g;

    if (upperCase.test(word))
        return word.toLowerCase();
    else if (upperCase.test(word.slice(1)) && !upperCase.test(word.charAt(0)))
        return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
    else
        return word;
}

var s = readline();
if(s === s.toUpperCase() || s === s[0].toLowerCase() + s.slice(1).toUpperCase()){
    print(s[0].toUpperCase() + s.slice(1).toLowerCase());
}
else print(s);

str = readline();
if(str.length - 2 < str.replace(/[^A-Z]/g, "").length)
{str = str.toLowerCase();
print(str.charAt(0).toUpperCase() + str.slice(1))}
else print(str);

 var word = readline(); f = word[0].toUpperCase();
word = word.slice(1);
print(f + word.toLowerCase());

// wHAT DO WE NEED cAPS LOCK FOR?

// Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.

// Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:

//     either it only contains uppercase letters;
//     or all letters except for the first one are uppercase.

// In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.

// Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.

// Input
// The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.

// Output
// Print the result of the given word's processing.

var s = readline()
var len = s.length
var sb = s.substring(1,len)

function isL (x){
    return x === x.toLowerCase()
}

function isU (x){
    return x === x.toUpperCase()
}

if (len === 1 && isU(s)){
    print(s.toLowerCase())
}
else if ((isL(s[0]) && isU(sb)) || isU(s)){
    print(s[0].toUpperCase()+sb.toLowerCase())
}else {
    print(s)
}

var s = readline();
var s1,s2;
var f = 1;
for(var i = 1; i < s.length; i++){
	if(s.charCodeAt(i) >=97 && s.charCodeAt(i) <= 122){
		f = 0;
		break;
	}
}
if(f){
	s1 = s.slice(0,1).toUpperCase();
	s2 = s.slice(1,s.length).toLowerCase();
	print(s1+s2);
}
else
	print(s);

const input = readline()

if(input == input.toUpperCase() || /^[a-z][A-Z]*$/.test(input)) {
    print(`{input[0].toUpperCase()}${input.slice(1).toLowerCase()}`)
} else {
    print(input)
}

// 131A - cAPS lOCK
// http://codeforces.com/problemset/problem/131/A

function main() {
    let s = read();
    let ans = s;
    if (s.length === 1 || s.substring(1, s.length - 1) === s.substring(1, s.length - 1).toUpperCase()) {
        ans = "";
        for (let i = 0; i < s.length; i++) {
            if (s[i] === s[i].toUpperCase()) {
                ans += s[i].toLowerCase();
            } else {
                ans += s[i].toUpperCase();
            }
        }
    }
    writeline(ans);
    return 0;
}

var input = "";
var read;
var writeline = (x) => process.stdout.write(x + "\n");
var write = (x) => process.stdout.write(x);
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", (chunk) => input += chunk);
process.stdin.on("end", () => {
    input = input.trim().split(/\s+/);
    read = () => input.shift();
    process.exit(main() || 0);
});

function main() {
    var s = "readline()";
    if(s.length <= 1) {
        if(s === s.toLowerCase()) {
            s = s.toUpperCase();
        }
        print(s);
    } else {
        var i;
        for(i = 1 ; i < s.length ; i++) {
            if(s.charAt(i) !== s.charAt(i).toUpperCase()) {
                break;
            }
        }
        if(i === s.length) {
            var out = "";
            for(i = 0 ; i < s.length ; i++) {
                if(s.charAt(i) === s.charAt(i).toUpperCase()) {
                    out += s.charAt(i).toLowerCase();
                } else {
                    out += s.charAt(i).toUpperCase();
                }
            }
            print(out);
        } else {
            print(s);
        }
    }
}

main();

const input = readline()

if(input == input.toUpperCase() ) {
    print(`${input.toLowerCase()}`)
} else if(/^[a-z][A-Z]+$/.test(input)) {
    print(`${input[0].toUpperCase()}${input.substring(1).toLowerCase()}`)
} else if(input == input.toLowerCase()) {
    print(input.toUpperCase())
} else {
    print(input)
}

 var word = readline().split(''),
            willChange = false;
        for (var i = 0; i < word.length; i++) {
            if (word[i] == word[i].toUpperCase()) {
                willChange = true;
            } else {
                willChange = false;
                break;
            }
        }

        if (willChange == false) {
            for (var j = 0; j < word.length - 1; j++) {
                if (word[0] == word[0].toLowerCase() && word[j + 1] == word[j + 1].toUpperCase()) {
                    willChange = true;
                } else {
                    willChange = false;
                    break;
                }
            }
        }

        if (willChange) {
            for (var a = 0; a < word.length; a++) {
                if (word[a] == word[a].toLowerCase()) {
                    word[a] = word[a].toUpperCase();
                } else {
                    word[a] = word[a].toLowerCase();
                }
            }
        }
        print(word.join(''));

var word = readline();
var result = word[0].toUpperCase() + word.slice(1).toLowerCase();

if (word === word.toUpperCase() || word === (word[0].toLowerCase() + word.slice(1).toUpperCase())) {
    print(result);
} else print(word);

s=readline()
if(s.toUpperCase()==s || s==s[0].toLowerCase()+s.substr(1).toUpperCase()){
	s=s[0].toUpperCase()+s.substr(1).toLowerCase();
}
print(s);

var n = readline();
var str= '';
//print(n[0].toUpperCase()+n.slice(1).toLowerCase());
for (var i=0; i<n.length; i++){
	if(n[i].toUpperCase()==n[i])
		str += n[i].toLowerCase();
	else str += n[i].toUpperCase();
}
print(str);

var n = readline().toLowerCase();
var p = n[0].toUpperCase();
var c = n.substring(1);
p += c;
print(p.concat());

var n = readline().toLowerCase();
var p = n[0].toUpperCase();
p += n.substring(0);
print(p.concat());

var str = readline(),
    flag = true,
    res = str[0].toUpperCase();

function isUpper(s) {
    return s === s.toUpperCase() ? true : false;
}

for (var i = 1; i < str.length; i++) {
    if (!isUpper(str[i])) flag = false;
}

if (flag) {
    for (var i = 1; i < str.length; i++) {
        if (isUpper(str[i])) s = str[i].toLowerCase();
        res += s;
    }

    print(res);
} else {
    print(str);
}

var str = readline();
var l = str.length;
var mode;
for(var i = 1; i < l; ++i)
{
        if(str[i] >= "a" && str[i] <= "z")
        {
            mode = "none";
            break;
        }
}

if(mode == "none")
{
    print(str);
}
else
{
    mode = false;
    if(str[0] >= "a" && str[0] <= "z")
    {
        mode = true;
    }
    str = str.toLowerCase();
    if(mode)
    {
        str[0] = str[0].toUpperCase();
    }
}
print(str);

var str = readline();
var mayus = str.toUpperCase();
if(str==mayus){
    print(str[0]+str.slice(1).toLowerCase());
}else{
    if(str[0]!=mayus[0] && str.slice(1)==mayus.slice(1)){
        print(str[0].toUpperCase()+str.toLowerCase().slice(1));
    }else if(str==str.toLowerCase()){
        print(str[0].toUpperCase()+str.slice(1));
    }
}

function Caps(word)
{
    var i = 0;
    word = word.split('');
    word[0] = word[0].toUpperCase();
    while (i < word.length)
    {
        word[i] = word[i].toLowerCase();
        i++;
    }
    return word.join('');
}

{
    var input = readline();
    print(Caps(input));
}

var w = readline();
function isUp(ch) {
    if (ch == ch.toUpperCase()) {
        return true;
       }
    return false;
}

if (w.length>1&&!isUp(w[0]) && isUp(w[1])){
    if (w.toUpperCase().substring(1) == w.substring(1)){
        w = w[0].toUpperCase() + w.toLowerCase().substring(1);

    }
}
if (w.toUpperCase() === w) {
    w = w.toLowerCase()
}
if (w.length === 1){
    if (w.toUpperCase() === w){
        w = w.toLowerCase();
    }else{
        w = w.toUpperCase();
    }
}
write(w)

// http://codeforces.com/problemset/problem/131/A

//Input: The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
var word = readline();

var caps = 0;

if (1 == word.length)
{
	if ( 97 > word.charCodeAt(0))
		word = word.toLowerCase();
}
else
{
	for (var i = 1; i < word.length; i++)
	{
		if (97 > word.charCodeAt(i))
			caps++;
	}

	if (caps == word.length-1)
		word = word.substr(0,1).toUpperCase() + word.substr(1,word.length-1).toLowerCase();
}

//Output: Print the result of the given word's processing.
print(word);

function isStringUppercase (string) {
  debugger
  return string.toUpperCase() === string;
}

function isFirstLetterLowerCase (string) {
  return string.charAt(0).toLowerCase() === string.charAt(0);
}

function isWrongCase(string) {
  var wrongCase = false;

  if (isFirstLetterLowerCase(string) && isStringUppercase(string.slice(1))) {
    wrongCase = true;
  } else if (isStringUppercase(string)) {
    wrongCase = true;
  }

  return wrongCase;
}

function invertWrongCaseString (string) {
  if (isWrongCase(string)) {
    return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
  } else {
    return string;
  }
}

var input = readline();

var output = invertWrongCaseString.call(null, input);

write(output);

function typedWithCapsLockKeyAccidentallySwitchedOn(s) {
	return s.match(/^[a-z].*/) && !s.match(/^[a-z].*[a-z]+.*/)
	     || s.match(/^[A-Z].+/) && !s.match(/^[A-Z].*[a-z]+.*/);
}
function main() {
	var textLine = readline();		//.split(' ');
	if (typedWithCapsLockKeyAccidentallySwitchedOn(textLine)) {
		textLine = textLine.substring(0, 1).toUpperCase() + textLine.substring(1).toLowerCase();
	}
	print(textLine);
}

main();

var txt = readline();
var k = txt.split('');
var a = k.sort();
var l;
if(txt.length>1){

 if(a[0] >= "A" && a[a.length-1] <= "Z") {
    txt = txt.toLowerCase();
}
else if(txt[0]>= "a"  && a[a.length-2] <= "Z") {
    txt = txt.toLowerCase();
    l = txt[0].toUpperCase();
    txt = txt.replace(txt[0], l);
    }
}
else {
    if(txt[0]>= "a"  && a[0] <= "Z"){
        txt = txt.toLowerCase();
    }
    else
        txt = txt.toUpperCase();
}

print(txt);

var string = readline();
var changed;
var count;
var firstLetter = false;

for (var i=0; i<string.length; i++) {
	if (i < 1) {
		if (string.charAt(i) == string.charAt(i).toLowerCase()) {
			firstLetter = true;
		} else {
			count++;
		}
	} else {
		if (string.charAt(i) == string.charAt(i).toUpperCase()) {
			count++;
		}
	}
}

if ((count == string.length-1 && firstLetter) || count == string.length) {
	for (var i=0; i<string.length; i++) {
		if (i < 1) {
			changed = string.charAt(i).toUpperCase();
		} else {
			changed += string.charAt(i).toLowerCase();
		}
	}
} else {
	changed = string;
}

print(changed);

const input = readline()

if(input == input.toUpperCase() ) {
    print(`${input.toLowerCase()}`)
} else if(/^[a-z][A-Z]+$/.test(input)) {
    print(`${input[0].toUpperCase()}${input.substring(1).toLowerCase()}`)
} else {
    print(input)
}

function capsLock(text){
    textAr = text[0].split("");
    var newAr = [];
    for (var i = 0; i<textAr.length; i++) {
        if(i==0){
            newAr.push(textAr[i].toUpperCase());
        }else{
            newAr.push(textAr[i].toLowerCase());
        }
    }
    return newAr.toString().replace(/,/g , "");
}

while(input = readline()){
    text=input.split(" ").map(function(x) { return x; });
    print(capsLock(text));
}

var word = readline();
if (word[0].toLowerCase() || word.slice(1).toUpperCase()) {
	print(word[0].toUpperCase() + word.slice(1).toLowerCase());
} else print(word);

function main() {
    var s = readline();
    if(s.length <= 1) {
        if(s === s.toLowerCase()) {
            s = s.toUpperCase();
        }
        print(s);
    } else {
        var i;
        for(i = 1 ; i < s.length ; i++) {
            if(s.charAt(i) !== s.charAt(i).toUpperCase()) {
                break;
            }
        }
        if(i === s.length) {
            var out = "";
            for(i = 0 ; i < s.length ; i++) {
                if(s.charAt(i) === s.charAt(i).toUpperCase()) {
                    out += s.charAt(i).toLowerCase();
                } else {
                    out += s.charAt(i).toUpperCase();
                }
            }
            print(out);
        } else {
            print(s);
        }
    }
}

main();

var string = readline();

for (var i=0; i<string.length; i++) {
	if (i < 1) {
		string = string.charAt(i).toUpperCase();
	} else {
		string += string.charAt(i).toLowerCase();
	}
}

print(string);

var word = readline();
if(word.substr(1).toUpperCase() == word.substr(1)){
    print(word[0].toUpperCase()+word.substr(1).toLowerCase());
}
else{
    print(word);
}

var str = readline(),
    flag = true,
    res = str[0].toUpperCase();

function isUpper(s) {
    return s === s.toUpperCase() ? true : false;
}

for (var i = 1; i < str.length; i++) {
    if (!isUpper(str[i])) flag = false;
}

if (flag) {
    for (var i = 1; i < str.length; i++) {
        if (isUpper(str[i])) s = str[i].toLowerCase();
        res += s;
    }

    print(res);
} else {
    print(str);
}

var str = readline();
var reg = /[a-z]+?/;
if (reg.test(str[0])&&reg.test(str.slice(1))==false||reg.test(str)==false)
print(str[0].toUpperCase()+str.slice(1).toLowerCase());
else
print(str);

str = readline();
if(str.length = str.replace(/[^A-Z]/g, "").length){print(str.toLowerCase)}
else if(str.length - 1 == str.slice(1).replace(/[^A-Z]/g, "").length)
{str = str.toLowerCase();
print(str.charAt(0).toUpperCase() + str.slice(1))}
else print(str);

var word = readline().toLowerCase().split('');
word[0] = word[0].toUpperCase();
print(word.join(''));

var n = readline();
var str= '';
//print(n[0].toUpperCase()+n.slice(1).toLowerCase());
for (var i=0; i<n.length; i++){
	if(n[i].toUpperCase()==n[i])
		str += n[i].toLowerCase();
	else str += n[i].toUpperCase();
}
print(str);

var word = readline();

if( word.charAt(0) < "a" ){
	if( word.charAt(1) < "a" ){
		write(word.toLowerCase());
	}
	else{
		write(word);
	}
}
else{
	write(word.charAt(0).toUpperCase());
	if( word.length > 1 ){
		for(i = 1; i < word.length; i++){
			write(word.charAt(i).toLowerCase());
		}
	}
}

const input = readline()

if(input == input.toUpperCase() ) {
    print(`${input.toLowerCase()}`)
} else if(/^[a-z][A-Z]+$/.test(input)) {
    print(`${input[0].toLowerCase()}${input.substring(1).toUpperCase()}`)
} else {
    print(input)
}

var str = readline();
a = str.split('');
var f = false;
var res = '';

for (var i = 1; i < a.length; i++) {
    if (a[i] != a[i].toUpperCase()) {
        print(str);
        f = true;
        break;
    } else res += a[i].toLowerCase();
}

if (!f) {
    print(a[0].toUpperCase() + res);
}

var str = readline();

 if (str.search(/[A-Z]/)>0){
	print(str[0].toUpperCase()+str.slice(1).toLowerCase());
	}

	else if(str.search(/[A-Z]/)==0 && str.slice(1).search(/[A-Z]/>0)){
	print(str[0].toUpperCase()+str.slice(1).toLowerCase());
	}

var s = readline();
if(s === s.toUpperCase() || s === s[0].toLowerCase() + s.slice(1).toUpperCase()){
    print(s[0].toUpperCase() + s.slice(1).toLowerCase());
}
else print(s);

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let str = readLine();
  str = str[0].toUpperCase() + str.substring(1).toLowerCase();
  console.log(str);
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let currentLine = 0;
let inputString = "";

process.stdin.on("data", (raw_data) => {
  inputString += raw_data;
});

process.stdin.on("end", (_) => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readLine() {
  return inputString[currentLine++];
}

/******** Main function*************/

function isLowerCase(str) {
  return str == str.toLowerCase() && str != str.toUpperCase();
}

function main() {
  var str = readLine().split("");
  var string = str.join("");
  var Fstr = str[0];
  var EFstr = str.join("").slice(1);

  var count = 0;

  for (var i = 0; i < str.length; i++) {
    if (isLowerCase(str[i]) == false) {
      count++;
    }
  }
  if (isLowerCase(EFstr) == false && isLowerCase(Fstr)) {
    console.log(Fstr.toUpperCase() + EFstr.toLowerCase());
  } else if (count === str.length) {
    console.log(string.toLowerCase());
  } else {
    console.log(string);
  }
}

// either it only contains uppercase letters;
// or all letters except for the first one are uppercase.

//var n = readline().split(' ').map(Number);

var str = readline();
var flag = false;

for (var i = 1; i < str.length; i++) {
    if (str[i] == str[i].toLowerCase()) {
        flag = true;
    }
}

var ans = str[0].toUpperCase();

for (var i = 1; i < str.length; i++) {
    ans += str[i].toLowerCase();
}

if (flag) {
    ans = str;
}

print(ans);


(function main() {
    var nmk = readline().split(' ').map(function(x) {return parseInt(x);});
    var n = nmk[0];
    var m = nmk[1];
    var k = nmk[2];
    var a = readline().split(' ').map(function(x) {return parseInt(x);});
    a.sort(function(a, b) {return b - a;});
    var i = 0;
    while (m > k && i < n) {
        k += a[i] - 1;
        ++i;
    }
    if (m > k)
        print(-1);
    else
        print(i);
})();

var homeStructure = readline();
homeStructure = homeStructure.split(' ');
var supplyLineFilters = Number(homeStructure[0]);
var devices = Number(homeStructure[1]);
var homeSockets = Number(homeStructure[2]);
var supplyLineFiltersSockets = readline();
supplyLineFiltersSockets = supplyLineFiltersSockets.split(' ');
supplyLineFiltersSocketsNum = [];
for (var i = 0; i < supplyLineFiltersSockets.length; i++) {
    supplyLineFiltersSocketsNum.push(Number(supplyLineFiltersSockets[i]));
}
supplyLineFiltersSocketsNum.sort(function(a, b) {
    return b - a;
});
var search = function(devices) {
    var found = 0;
    for (var i = 0; i < supplyLineFiltersSocketsNum.length; i++) {
        if (devices === supplyLineFiltersSocketsNum[i]) {
            found = i;
            break;
        }
    }
    found = supplyLineFiltersSocketsNum.splice(found, 1);
    return found;
};
var usedSupplyLines = 0;
if (devices <= homeSockets) {
    print(usedSupplyLines);
} else {
    while ((homeSockets > 0 || supplyLineFiltersSocketsNum.length > 0) && devices > 0) {

        if (devices <= homeSockets) {
            devices = 0;
            homeSockets = 0;
            break;
        }
        var supplyLineSockets = search(devices);

        if (supplyLineSockets) {
            devices -= supplyLineSockets;
            if(homeSockets !== 0){
            	homeSockets -= 1;
            }
            usedSupplyLines++;
        }
        if(devices !== 0 && homeSockets === 0 && supplyLineFiltersSocketsNum.length !==0){
        	devices += 1;
        }
    }
    if (devices > 0) {
        print(-1);
    } else {
        print(usedSupplyLines);
    }
}

var homeStructure = readline();
homeStructure = homeStructure.split(' ');
var supplyLineFilters = Number(homeStructure[0]);
var devices = homeStructure[1];
var homeSockets = homeStructure[2];
var supplyLineFiltersSockets = readline();
supplyLineFiltersSockets = supplyLineFiltersSockets.split(' ');
supplyLineFiltersSocketsNum = [];
for (var i = 0; i < supplyLineFiltersSockets.length; i++) {
    supplyLineFiltersSocketsNum.push(Number(supplyLineFiltersSockets[i]));
}
supplyLineFiltersSocketsNum.sort(function(a, b) {
    return b - a;
});
var search = function(devices) {
    var found = 0;
    for (var i = 0; i < supplyLineFiltersSocketsNum.length; i++) {
        if (devices === supplyLineFiltersSocketsNum[i]) {
            found = i;
            break;
        }
    }
    found = supplyLineFiltersSocketsNum.splice(found, 1);
    return found;
};
var usedSupplyLines = 0;
if (homeSockets === devices || devices < homeSockets) {
    print(usedSupplyLines);
} else {
    while (homeSockets > 0 && devices > 0) {
        if (devices === homeSockets) {
            devices = 0;
            homeSockets = 0;
            break;
        }
        var supplyLineSockets = search(devices);
        if (supplyLineSockets) {
            devices -= supplyLineSockets;
            homeSockets -= 1;
            usedSupplyLines++;
        }
        if(homeSockets === 0 && supplyLineFiltersSocketsNum.length !==0){
        	homeSockets += 1;
        	devices += 1;
        }
    }
    if (devices > 0) {
        print(-1);
    } else {
        print(usedSupplyLines);
    }
}

var homeStructure = readline();
homeStructure = homeStructure.split(' ');
var supplyLineFilters = Number(homeStructure[0]);
var devices = Number(homeStructure[1]);
var homeSockets = Number(homeStructure[2]);
var supplyLineFiltersSockets = readline();
supplyLineFiltersSockets = supplyLineFiltersSockets.split(' ');
supplyLineFiltersSocketsNum = [];
for (var i = 0; i < supplyLineFiltersSockets.length; i++) {
    supplyLineFiltersSocketsNum.push(Number(supplyLineFiltersSockets[i]));
}
supplyLineFiltersSocketsNum.sort(function(a, b) {
    return b - a;
});
var search = function(devices) {
    var found = 0;
    for (var i = 0; i < supplyLineFiltersSocketsNum.length; i++) {
        if (devices === supplyLineFiltersSocketsNum[i]) {
            found = i;
            break;
        }
    }
    found = supplyLineFiltersSocketsNum.splice(found, 1);
    return found;
};
var usedSupplyLines = 0;
if (homeSockets === devices || devices < homeSockets) {
    print(usedSupplyLines);
} else {
    while ((homeSockets > 0 || supplyLineFiltersSocketsNum.length > 0) && devices > 0) {
        if (devices === homeSockets) {
            devices = 0;
            homeSockets = 0;
            break;
        }
        var supplyLineSockets = search(devices);
        if (supplyLineSockets) {
            devices -= supplyLineSockets;
            if(homeSockets !== 0){
            	homeSockets -= 1;
            }
            usedSupplyLines++;
        }
        if(devices !== 0 && homeSockets === 0 && supplyLineFiltersSocketsNum.length !==0){
        	devices += 1;
        }
    }
    if (devices > 0) {
        print(-1);
    } else {
        print(usedSupplyLines);
    }
}

var homeStructure = readline();
homeStructure = homeStructure.split(' ');
var supplyLineFilters = Number(homeStructure[0]);
var devices = homeStructure[1];
var homeSockets = homeStructure[2];
var supplyLineFiltersSockets = readline();
supplyLineFiltersSockets = supplyLineFiltersSockets.split(' ');
supplyLineFiltersSocketsNum = [];
for (var i = 0; i < supplyLineFiltersSockets.length; i++) {
    supplyLineFiltersSocketsNum.push(Number(supplyLineFiltersSockets[i]));
}
supplyLineFiltersSocketsNum.sort(function(a, b) {
    return b - a;
});
var search = function(devices) {
    var found = 0;
    for (var i = 0; i < supplyLineFiltersSocketsNum.length; i++) {
        if (devices === supplyLineFiltersSocketsNum[i]) {
            found = i;
            break;
        }
    }
    found = supplyLineFiltersSocketsNum.splice(found, 1);
    return found;
};
var usedSupplyLines = 0;
if (homeSockets === devices || devices < homeSockets) {
    print(usedSupplyLines);
} else {
    while (homeSockets > 0 && devices > 0) {
        if (devices === homeSockets) {
            devices = 0;
            homeSockets = 0;
            break;
        }
        var supplyLineSockets = search(devices);
        if (supplyLineSockets) {
            devices -= supplyLineSockets;
            homeSockets -= 1;
            usedSupplyLines++;
        }
    }
    if (devices > 0) {
        print(-1);
    } else {
        print(usedSupplyLines);
    }
}

(function main() {
    var nmk = readline().split(' ').map(function(x) {return parseInt(x);});
    var n = nmk[0];
    var m = nmk[1];
    var k = nmk[2];
    var a = readline().split(' ').map(function(x) {return parseInt(x);});
    a.sort();
    a.reverse();
    var i = 0;
    while (m > k && i < n) {
        k += a[i] - 1;
        ++i;
    }
    if (m > k)
        print(-1);
    else
        print(i);
})();


// 620A - Brooks Mershon
function steps(a, b) {
  var count = 0,
      xDelta,
      yDelta;

  xDelta = Math.abs(a[0] - b[0]),
  yDelta = Math.abs(a[1] - b[1]);
  count += Math.min(xDelta, yDelta);

  a[0] -= sign(a[0] - b[0]) * count;
  a[1] -= sign(a[1] - b[1]) * count;

  function sign(x) {
    return typeof x === 'number' ? x ? x < 0 ? -1 : 1 : x === x ? 0 : NaN : NaN;
  }

  return count + Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]);
}

// Codeforces I/O
var first = readline().split(" ").map(function(x) { return parseInt(x); }),
    second = readline().split(" ").map(function(x) { return parseInt(x); });

print(steps(first, second));

var a = readline().split(" ").map(function(firstLine) { return parseInt(firstLine); });
var b = readline().split(" ").map(function(secondLine) { return parseInt(secondLine); });

function getPoint (a, b) {
  var xStep, yStep;

  if ((a[0]>=0 && b[0]<=0) || (a[0]<=0 && b[0]>=0)) {
  	xStep = Math.abs(a[0]) + Math.abs(b[0]);
  } else {
  	xStep = a[0]-b[0];
  }

  if ((a[1]>=0 && b[1]<=0) || (a[1]<=0 && b[1]>=0)) {
  	yStep = Math.abs(a[1]) + Math.abs(b[1]);
  } else {
  	yStep = a[1]-b[1];
  }

  return Math.max(Math.abs(xStep), Math.abs(yStep))
}

print(getPoint (a, b));

function rda(){ return readline().split(" ").map(Number); };
function rdn(){ return +readline(); };

var inp = rda();
var x1 = inp[0], y1 = inp[1];
inp = rda();
var x2 = inp[0], y2 = inp[1];

var ans = 0;
ans += Math.min(Math.abs(y2-y1), Math.abs(x2-x1));
ans += Math.max(Math.abs(y2-y1), Math.abs(x2-x1)) - ans;

write(ans);

var p1= readline().split(' ');
var p2= readline().split(' ');

p1[0] = parseInt(p1[0]);
p1[1] = parseInt(p1[1]);

p2[0] = parseInt(p2[0]);
p2[1] = parseInt(p2[1]);

var dx = Math.abs( p2[0] - p1[0]);
var dy = Math.abs( p2[1] - p1[1]);

var m = Math.min(dx,dy);

dx-=m;
dy-=m;

print(m+dx+dy);

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});

let c = 0;
let x1, y1, x2, y2;

rl.on("line", (d) => {
  if (c === 0) {
    [x1, y1] = d.split(" ").map(Number);
    c++;
    return;
  }

  [x2, y2] = d.split(" ").map(Number);
  const ans = Math.max(Math.abs(x1 - x2), Math.abs(y1 - y2));
  console.log(ans);
  c++;
});

function getPoint (a, b) {
  var xStep, yStep;

  if ((a[0]>=0 && b[0]<=0) || (a[0]<=0 && b[0]>=0)) {
  	xStep = Math.abs(a[0]) + Math.abs(b[0]);
  } else {
  	xStep = a[0]-b[0];
  }

  if ((a[1]>=0 && b[1]<=0) || (a[1]<=0 && b[1]>=0)) {
  	yStep = Math.abs(a[1]) + Math.abs(b[1]);
  } else {
  	yStep = a[1]-b[1];
  }

  return Math.max(Math.abs(xStep), Math.abs(yStep))
}

var a = readline().split(" ").map(function(firstLine) { return parseInt(firstLine); });
var b = readline().split(" ").map(function(secondLine) { return parseInt(secondLine); });

print(getPoint (a, b));

function getSteps(a,b) {
   var max = Math.max( Math.abs(b[0])+Math.abs(a[0]), Math.abs(b[1])+Math.abs(a[1]) );

   if (max === Math.abs(b[0])+Math.abs(a[0])) {
      return max-a[0]
   } else if (max === Math.abs(b[1])+Math.abs(a[1]) ) {
      return max-a[1]
   }
}

var parsed_start = readline().split(" ").map(function(x) { return parseInt(x); });

function getPoint (a) {
  var xStep, yStep;

  if ((a[0]>=0 && a[1]<=0) || (a[0]<=0 && a[1]>=0)) {
  	xStep = Math.abs(a[0]) + Math.abs(a[1]);
  } else {
  	xStep = a[0]-a[1];
  }

  if ((a[2]>=0 && a[3]<=0) || (a[2]<=0 && a[3]>=0)) {
  	yStep = Math.abs(a[2]) + Math.abs(a[3]);
  } else {
  	yStep = a[2]-a[3];
  }

  return Math.max(xStep, yStep)
}

getPoint(parsed_start);

function getSteps(a,b) {
  var myX = Math.abs(a[0])+Math.abs(b[0]);
  var myY = Math.abs(a[1])+Math.abs(b[1]);
  if (myX > myY) {return myX} else {return myY}
}

function getPoint (a, b) {
	var xStep, yStep;
	if ((a[0]>=0 && b[0]<=0) || (a[0]<=0 && b[0]>=0)) {
  	xStep = Math.abs(a[0]) + Math.abs(b[0]);
    console.log('xStep', xStep);
  } else {
  	xStep = a[0]-b[0];
  }

  if ((a[1]>=0 && b[1]<=0) || (a[1]<=0 && b[1]>=0)) {
  	yStep = Math.abs(a[1]) + Math.abs(b[1]);
    console.log('yStep', yStep);
  } else {
  	yStep = a[1]-b[1];
  }

  console.log('max', Math.max(xStep, yStep));
  return Math.max(xStep, yStep)
}

var parsed_start = readline().split(" ").map(function(x) { return parseInt(x); });
var parsed_finish = readline().split(" ").map(function(y) { return parseInt(y); });

function getPoint (a, b) {
	var xStep, yStep;
	if ((a[0]>=0 && b[0]<=0) || (a[0]<=0 && b[0]>=0)) {
  	xStep = Math.abs(a[0]) + Math.abs(b[0]);
  } else {
  	xStep = a[0]-b[0];
  }

  if ((a[1]>=0 && b[1]<=0) || (a[1]<=0 && b[1]>=0)) {
  	yStep = Math.abs(a[1]) + Math.abs(b[1]);
  } else {
  	yStep = a[1]-b[1];
  }

  return Math.max(xStep, yStep)
}

getPoint(parsed_start, parsed_finish);

function getSteps(x,y,newX, newY) {
  var myX = Math.abs(x)+Math.abs(newX);
  var myY = Math.abs(y)+Math.abs(newY);
  if (myX > myY) {return myX} else {return myY}
}

var a = readline().split(" ").map(function(firstLine) { return parseInt(firstLine); });
var b = readline().split(" ").map(function(secondLine) { return parseInt(secondLine); });

function getPoint (a, b) {
  var xStep, yStep;

  if ((a[0]>=0 && b[0]<=0) || (a[0]<=0 && b[0]>=0)) {
  	xStep = Math.abs(a[0]) + Math.abs(b[0]);
  } else {
  	xStep = a[0]-b[0];
  }

  if ((a[1]>=0 && b[1]<=0) || (a[1]<=0 && b[1]>=0)) {
  	yStep = Math.abs(a[1]) + Math.abs(b[1]);
  } else {
  	yStep = a[1]-b[1];
  }

  return Math.max(Math.abs(xStep), Math.abs(yStep))
}

getPoint (a, b)

function getSteps(a,b) {
   var max = Math.max( Math.abs(b[0])+Math.abs(a[0]), Math.abs(b[1])+Math.abs(a[1]) );

   if (max === Math.abs(b[0])+Math.abs(a[0])) {
   				if (Math.abs(b[0]) > Math.abs(a[0])) {
          	return Math.abs(b[0] - a[0])
          } else {
          	return Math.abs(a[0] - b[0])
          }
   } else if (max === Math.abs(b[1])+Math.abs(a[1]) ) {
      if (Math.abs(b[1]) > Math.abs(a[1])) {
          	return Math.abs(b[1] - a[1])
          } else {
          	return Math.abs(a[1] - b[1])
          }
   }
}

function getPoint (a, b) {
  var xStep, yStep;

  if ((a[0]>=0 && b[0]<=0) || (a[0]<=0 && b[0]>=0)) {
  	xStep = Math.abs(a[0]) + Math.abs(b[0]);
  } else {
  	xStep = a[0]-b[0];
  }

  if ((a[1]>=0 && b[1]<=0) || (a[1]<=0 && b[1]>=0)) {
  	yStep = Math.abs(a[1]) + Math.abs(b[1]);
  } else {
  	yStep = a[1]-b[1];
  }

  return Math.max(xStep, yStep)
}

var a = readline().split(" ").map(function(x) { return parseInt(x); });
var b = readline().split(" ").map(function(y) { return parseInt(y); });

getPoint(a,b)

function getSteps(a,b) {
   var max = Math.max( Math.abs(b[0]), Math.abs(b[1]) );

   if (max === Math.abs(b[0])) {
      return max-a[0]
   } else if (max === Math.abs(b[1])) {
      return max-a[1]
   }
}