def word_to_number(words): singles = { "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9 } teens = { "ten": 10, "eleven": 11, "twelve": 12, "thirteen": 13, "fourteen": 14, "fifteen": 15, "sixteen": 16, "seventeen": 17, "eighteen": 18, "nineteen": 19 } tens = { "twenty": 20, "thirty": 30, "forty": 40, "fifty": 50, "sixty": 60, "seventy": 70, "eighty": 80, "ninety": 90 } words = words.strip().lower().split() result = 0 i = 0 while i < len(words): if words[i] in teens: result += teens[words[i]] i += 1 elif words[i] in tens: result += tens[words[i]] if i + 1 < len(words) and words[i + 1] in singles: result += singles[words[i + 1]] i += 2 else: i += 1 elif words[i] in singles: result += singles[words[i]] i += 1 else: i += 1 return result def chess_moves(x, y): if x == 0 and y == 0: return 0 rook = 1 if x == 0 or y == 0 else 2 if (x + y) % 2 != 0: bishop = float('inf') elif x == y or x == -y: bishop = 1 else: bishop = 2 return min(rook, bishop) # ---- Input Handler ---- import sys input_line = sys.stdin.read().strip().lower() tokens = input_line.split() if all(token.isdigit() for token in tokens): # Numeric input x, y = map(int, tokens) else: # Word input # Strategy: split the input into two word groups (first for x, second for y) # e.g., "twenty one five" → ["twenty one", "five"] # e.g., "forty four" → ["forty", "four"] found = False for i in range(1, len(tokens)): x_words = " ".join(tokens[:i]) y_words = " ".join(tokens[i:]) x = word_to_number(x_words) y = word_to_number(y_words) if isinstance(x, int) and isinstance(y, int): found = True break if not found: x = y = 0 # fallback print(chess_moves(x, y))