#!/usr/bin/env python3 import sys from collections import defaultdict match = { "}": "{", ")": "(", ">": "<", "]": "[", } bad = defaultdict(int) for l in sys.stdin: mem = [] for c in l.strip(): if c in ["{", "(", "<", "["]: mem.append(c) elif c in ["}", ")", ">", "]"]: m = match[c] if mem.pop() != m: bad[c] += 1 break else: raise Exception(f"Bad char: {c}") # ): 3 points. # ]: 57 points. # }: 1197 points. # >: 25137 points. print(bad["}"] * 1197 + bad[")"] * 3 + bad[">"] * 25137 + bad["]"] * 57)