import re import sys def swap_case(match): word = match.group() return ''.join(c.lower() if c.isupper() else c.upper() for c in word) def transform_text(input_text): pattern = re.compile(r'\b(?=\w*[a-ząćęłńóśźż])(?=\w*[A-ZĄĆĘŁŃÓŚŹŻ])\w+\b') transformed_text = pattern.sub(swap_case, input_text) return transformed_text for line in sys.stdin: output_text = transform_text(line) sys.stdout.write(output_text)