with open("input") as f: lines = [n.strip() for n in f.readlines()] solution = 0 for line in lines: char_count = 0 i = 1 while i < len(line) - 1: char = line[i] if char == "\\": next_char = line[i + 1] if next_char in ["\\", '"']: i += 1 elif next_char in ["x"]: i += 3 char_count += 1 i += 1 literal_count = len(line) print(f"{line}: {literal_count=}, {char_count=}") solution += literal_count - char_count print(solution)