import os import sys file = open('input.txt', 'r') input = file.read() open = "(" close = ")" open_count = input.count(open) close_count = input.count(close) print("Open count: " + str(open_count)) print("Close count: " + str(close_count)) floor = open_count - close_count print("Santa is on floor: " + str(floor)) floor = 0 count = 0; for char in input: if char == open: floor = floor + 1 if char == close: floor = floor - 1 count = count + 1 if floor < 0: break; print("Santa visits the basement first at position: " + str(count))