34 lines
794 B
Python
Executable File
34 lines
794 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from useful import *
|
|
|
|
def hush(s):
|
|
return reduce(lambda a, b: (a+ord(b))*17%256, s, 0)
|
|
|
|
steps = open(0).read().strip().split(',')
|
|
|
|
print(sum(hush(s) for s in steps))
|
|
|
|
boxen = [deque() for _ in range(256)]
|
|
|
|
for s in steps:
|
|
if s[-1] == '-':
|
|
id = s[:-1]
|
|
box = boxen[hush(id)]
|
|
for i in range(len(box)):
|
|
if box[i][0] == id:
|
|
del box[i]
|
|
break
|
|
else:
|
|
id, vstr = s.split('=')
|
|
box = boxen[hush(id)]
|
|
val = int(vstr)
|
|
for i in range(len(box)):
|
|
if box[i][0] == id:
|
|
box[i][1] = val
|
|
break
|
|
else:
|
|
box.append([id, val])
|
|
|
|
print(sum((i+1) * (j+1) * foc for i, b in enumerate(boxen) for j, (s, foc) in enumerate(b)))
|