with open("input") as f: puzzle_input = f.read() floor = 0 position = 1 for char in puzzle_input: if char == "(": floor += 1 else: floor -= 1 if floor == -1: break position += 1 print(position)