|
|
@ -2,21 +2,33 @@ lines = open("input.txt", 'r').read().splitlines() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
di = { |
|
|
|
di = { |
|
|
|
')': ('(', 3), |
|
|
|
('(', ')', 3, 1), |
|
|
|
']': ('[', 57), |
|
|
|
('[', ']', 57, 2), |
|
|
|
'}': ('{', 1197), |
|
|
|
('{', '}', 1197, 3), |
|
|
|
'>': ('<', 25137) |
|
|
|
('<', '>', 25137, 4) |
|
|
|
} |
|
|
|
} |
|
|
|
score = 0 |
|
|
|
score1 = 0 |
|
|
|
|
|
|
|
score2 = [] |
|
|
|
for l in lines: |
|
|
|
for l in lines: |
|
|
|
stack = [] |
|
|
|
stack = [] |
|
|
|
|
|
|
|
valid = True |
|
|
|
for c in l: |
|
|
|
for c in l: |
|
|
|
if c == '(' or c == '[' or c == '{' or c == '<': |
|
|
|
if c == '(' or c == '[' or c == '{' or c == '<': |
|
|
|
stack.append(c) |
|
|
|
stack.append(c) |
|
|
|
if c == ')' or c == ']' or c == '}' or c == '>': |
|
|
|
if c == ')' or c == ']' or c == '}' or c == '>': |
|
|
|
if stack.pop() != di.get(c)[0]: |
|
|
|
if stack.pop() != [x[0] for x in di if x[1] == c][0][0]: |
|
|
|
score += di.get(c)[1] |
|
|
|
score1 += [x for x in di if x[1] == c][0][2] |
|
|
|
|
|
|
|
valid = False |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
if valid: |
|
|
|
|
|
|
|
if stack == []: |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
score = 0 |
|
|
|
|
|
|
|
while stack != []: |
|
|
|
|
|
|
|
cha = stack.pop() |
|
|
|
|
|
|
|
score = score * 5 + [x for x in di if x[0] == cha][0][3] |
|
|
|
|
|
|
|
score2.append(score) |
|
|
|
|
|
|
|
|
|
|
|
print(score) |
|
|
|
print(score1) |
|
|
|
|
|
|
|
score2.sort() |
|
|
|
|
|
|
|
print(score2[(int)(len(score2)/2)]) |