2022-12-07 05:20:05 +00:00
|
|
|
import sys
|
|
|
|
from collections import defaultdict
|
|
|
|
cmds = open("input").read().split("$")
|
|
|
|
|
|
|
|
cwd = []
|
|
|
|
sizes = defaultdict(lambda: 0)
|
|
|
|
for cmd in cmds:
|
|
|
|
cmd = cmd.strip()
|
|
|
|
if not cmd:
|
|
|
|
continue
|
|
|
|
print(cmd)
|
|
|
|
if cmd.startswith("cd "):
|
|
|
|
dir = cmd.split()[1]
|
|
|
|
if dir == "..":
|
|
|
|
cwd.pop()
|
|
|
|
elif dir == "/":
|
|
|
|
cwd = []
|
|
|
|
else:
|
|
|
|
cwd.append(dir)
|
|
|
|
elif cmd.startswith("ls\n"):
|
|
|
|
files = cmd.splitlines()[1:]
|
|
|
|
for file in files:
|
|
|
|
sz, name = file.split()
|
|
|
|
if sz == 'dir':
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
print(cwd, name, sizes)
|
|
|
|
for i in range(len(cwd)+1):
|
|
|
|
sizes['/'.join(cwd[:i])] += int(sz)
|
|
|
|
else:
|
|
|
|
print("bad command:" +cmd)
|
|
|
|
|
|
|
|
|
|
|
|
print(sizes)
|
|
|
|
|
2022-12-07 06:03:59 +00:00
|
|
|
print(sum(sz for sz in sizes.values() if sz <= 100000))
|
2022-12-07 05:20:05 +00:00
|
|
|
|
|
|
|
print(min(sz for sz in sizes.values() if 70000000 - sizes[''] + sz >= 30000000))
|