import shared from collections import Counter def pt1(inp): floor = 0 chars = [x for x in inp] c = Counter(chars) floor += c['('] floor -= c[')'] print(floor) def pt2(inp): floor = 0 chars = [x for x in inp] for idx, c in enumerate(chars): if c == '(': floor +=1 if c == ')': floor -= 1 if floor == -1: print(idx+1) break if __name__ == "__main__": with open(shared.get_fname(1), "r") as f: inp = f.read().rstrip() pt1(inp) pt2(inp)