from functools import reduce from operator import add def floor(plan: str): return reduce(add, [1 if e == '(' else -1 for e in plan]) def test(): assert floor("(())") == 0 assert floor("()()") == 0 assert floor("(((") == 3 assert floor("(()(()(") == 3 assert floor("))(((((") == 3 assert floor("())") == -1 assert floor("))(") == -1 assert floor(")))") == -3 assert floor(")())())") == -3 def solve(): with open("in1") as puzzle: r = puzzle.read() return floor(r) if __name__ == "__main__": print(f"Floor: {solve()}")