# Do you ever wish you could talk like Siegfried of KAOS ?

## YES, of course you do!

https://en.wikipedia.org/wiki/Get_Smart



# Task

Write the function ```siegfried``` to replace the letters of a given sentence.

Apply the rules using the course notes below. Each week you will learn some more rules.

Und by ze fifz vek yu vil be speakink viz un aksent lik Siegfried viz no trubl at al!


# Lessons

## Week 1

* ```ci``` -> ```si```
* ```ce``` -> ```se```
* ```c``` -> ```k``` (except ```ch``` leave alone)

## Week 2

* ```ph``` -> ```f```

## Week 3

* remove trailing ```e``` (except for all 2 and 3 letter words)
* replace double letters with single letters (e.g. ```tt``` -> ```t```)

## Week 4

* ```th``` -> ```z```
* ```wr``` -> ```r```
* ```wh``` -> ```v```
* ```w``` -> ```v```

## Week 5

* ```ou``` -> ```u```
* ```an``` -> ```un```
* ```ing``` -> ```ink``` (but only when ending words)
* ```sm``` -> ```schm``` (but only when beginning words)



# Notes

* You must retain the case of the original sentence
* Apply rules strictly in the order given above
* Rules are cummulative. So for week 3 first apply week 1 rules, then week 2 rules, then week 3 rules

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "import re\n\n\ndef siegfried(week, txt):\n    weeks_have_passed = {0: week_one, 1: week_two, 2: week_three, 3: week_four, 4: week_five}\n\n    for counter in range(0, week):\n\n        txt = weeks_have_passed[counter](txt)\n    \n    return txt\n\ndef week_one(txt):\n\n    letter_list = list(txt)\n\n    copy_reverse_letter_list = letter_list.copy()\n\n\n    last_letter = ''\n\n    count = -1\n\n    for letter in copy_reverse_letter_list[::-1]:\n\n        lowercase_letter = letter.lower()\n\n        if lowercase_letter == 'c':\n            lowercase_letter += last_letter\n\n            if letter.isupper():\n                dict_to_know = {'ci': 'S', 'ce': 'S', 'ch': 'C'}\n                to_return = 'K'\n            else:\n                dict_to_know = {'ci': 's', 'ce': 's', 'ch': 'c'}\n                to_return = 'k'\n\n            letter_list[count] = dict_to_know.get(lowercase_letter, to_return)\n\n        count -= 1\n        last_letter = letter\n\n    final_txt = ''.join(letter_list)\n\n    return final_txt\n\n\ndef week_two(txt):\n\n    letter_list = list(txt)\n\n    copy_letter_list = letter_list.copy()\n    copy_letter_list.append('')\n\n    fix_position = 0\n\n    for counter, letter in enumerate(copy_letter_list[:-1]):\n\n        lowercase_letter = letter.lower()\n\n        next_letter = copy_letter_list[counter+1]\n        lowcase_next_letter = next_letter.lower()\n\n        if lowercase_letter == 'p' and lowcase_next_letter == 'h':\n\n            counter -= fix_position\n\n            if letter.isupper():\n                to_change = 'F'\n            else:\n                to_change = 'f'\n\n            letter_list[counter: counter + 2] = to_change\n\n            fix_position += 1\n\n    new_txt = ''.join(letter_list)\n\n    return new_txt\n\n\ndef week_three(txt):\n    trailling_e = r'[a-zA-Z]{3,}e\\b'\n\n    trailling_list = re.findall(trailling_e, txt)\n\n    new_txt = txt\n\n    for trailling_e_word in trailling_list:\n        new_txt = new_txt.replace(trailling_e_word, trailling_e_word[:-1])\n\n    letter_list = list(new_txt)\n\n    copy_letter_list = letter_list.copy()\n\n    last_letter = ''\n\n    position = -1\n\n    for letter in copy_letter_list[::-1]:\n\n        lowercase_letter = letter.lower()\n\n        if lowercase_letter == last_letter and lowercase_letter.isalpha():\n\n            del letter_list[position+1]\n\n            position += 1\n\n        last_letter = lowercase_letter\n\n        position -= 1\n\n    final_txt = ''.join(letter_list)\n\n    return final_txt\n\n\n\ndef week_four(txt):\n\n    letter_list = list(txt)\n\n    copy_reverse_letter_list = letter_list.copy()\n\n    last_letter = ''\n\n    counter = -1\n\n    for letter in copy_reverse_letter_list[::-1]:\n\n        lowercase_letter = letter.lower()\n\n        if lowercase_letter == 'w' or lowercase_letter == 't' and last_letter == 'h':\n            lowercase_letter += last_letter\n\n            if letter.isupper():\n                dict_to_know = {'wr': 'R', 'wh': 'V', 'th': 'Z'}\n                lonely_w = 'V'\n            else:\n                dict_to_know = {'wr': 'r', 'wh': 'v', 'th': 'z'}\n                lonely_w = 'v'\n\n            possible_last_letters = {'h', 'r'}\n\n            if last_letter in possible_last_letters:\n                letter_list[counter: counter+2] = dict_to_know[lowercase_letter]\n                counter += 1\n\n            else:\n                letter_list[counter] = lonely_w\n\n        counter -= 1\n        last_letter = letter\n\n    final_txt = ''.join(letter_list)\n\n    return final_txt\n\n\ndef week_five(txt):\n    letter_list = list(txt)\n\n    copy_reverse_letter_list = letter_list.copy()\n\n    last_letter = ''\n\n    counter = -1\n\n    for letter in copy_reverse_letter_list[::-1]:\n        lowercase_letter = letter.lower()\n\n        if lowercase_letter == 'o' and last_letter == 'u':\n            lowercase_or_uppercase = {'o': 'u', 'O': 'U'}\n\n            letter_list[counter: counter+2] = lowercase_or_uppercase[letter]\n\n            counter += 1\n\n        elif lowercase_letter == 'a' and last_letter == 'n':\n            lowercase_or_uppercase_2 = {'a': 'u', 'A': 'U'}\n\n            letter_list[counter] = lowercase_or_uppercase_2[letter]\n\n        last_letter = lowercase_letter\n\n        counter -= 1\n\n    first_txt = ''.join(letter_list)\n\n    re_to_find_ing = r'[a-zA-Z]{1,}ing\\b'\n\n    all_words_ending_with_ing = re.findall(re_to_find_ing, first_txt)\n\n    second_txt = first_txt\n\n    for word in all_words_ending_with_ing:\n        new_word = word[:-1] + 'k'\n        second_txt = second_txt.replace(word, new_word)\n\n    re_to_find_sm = r'\\b[sS][mM][a-zA-Z]*'\n\n\n    all_words_starting_with_sm = re.findall(re_to_find_sm, second_txt)\n\n    third_txt = second_txt\n\n    for word in all_words_starting_with_sm:\n        new_word = word[0] + 'ch' + word[1:]\n        third_txt = third_txt.replace(word, new_word)\n\n    final_txt = third_txt\n\n    return final_txt"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'siegfried'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 6745