import sys class lines: def __init__(self, inp): self.line = inp def solve(self): counter = True counter2 = 0 operators = ['()', '[]', '<>', '{}'] scores = [('(]', 57), ('(}', 1197), ('(>', 25137), ('[)', 3), ('[}', 1197), ('[>', 25137), ('{)', 3), ('{]', 57), ('{>', 25137), ('<)', 3), ('<]', 57), ('<}', 1197)] scores2 = [('(', 1), ('[', 2), ('{', 3), ('<', 4)] while counter: counter = False for i in operators: if i in self.line: self.line = self.line.replace(i, '') counter = True for i in scores: if i[0] in self.line: return i[1], None for i in range(len(self.line)-1, -1, -1): counter2 = counter2*5 for f in scores2: if self.line[i] == f [0]: counter2 += f[1] return 0, counter2 inp = [] solution = 0 solution2 = [] with open(sys.argv[1], 'r') as f: for i in f.readlines(): i = i.strip() inp.append(lines(i)) for f in inp: tem1, temp2 = f.solve() solution += tem1 if temp2 is not None: solution2.append(temp2) solution2 = sorted(solution2) temp3 = len(solution2) // 2 print(solution2[temp3]) print(solution)