find master word

Added: 2025-09-12 22:06:39

Question Image

find master word

Answer

✏️ Edit
word = input()

vowels = "AEIOU"
valid_last = "[{}]"

is_valid = (
    len(word) >= 6 and
    not word[0].isdigit() and
    word[1] not in vowels and
    word[-1] in valid_last
)

i = 2
num1 = ""
while i < len(word) and word[i].isdigit():
    num1 += word[i]
    i += 1

vow = ""
while i < len(word) and word[i] in vowels:
    vow += word[i]
    i += 1

num2 = ""
while i < len(word) and word[i].isdigit():
    num2 += word[i]
    i += 1

if is_valid and num1 and vow and num2 and i == len(word) - 1:
    print("YES", int(num1) + int(num2))
else:
    n1 = int(num1) if num1 else 0
    n2 = int(num2) if num2 else 0
    print("NO", n1 - n2)