23 lines
430 B
Python
23 lines
430 B
Python
import sys
|
|
from collections import deque
|
|
|
|
D = { ">":"<", ")":"(", "]":"[","}":"{", }
|
|
S = { ")": 3, "]": 57, "}": 1197, ">": 25137, }
|
|
L = sys.stdin.read().splitlines()
|
|
N = 0
|
|
for l in L:
|
|
Q = deque(["y"]*1)
|
|
for c in l:
|
|
p = Q.pop()
|
|
if c in D: # if closing char
|
|
e = D[c]
|
|
if p != e: # fail case
|
|
N += S[c]
|
|
break
|
|
else: # just discard the pair
|
|
pass
|
|
else: # not closing
|
|
Q.append(p)
|
|
Q.append(c)
|
|
print(N)
|