-
Notifications
You must be signed in to change notification settings - Fork 0
/
09.py
54 lines (47 loc) · 887 Bytes
/
09.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from lib import *
input = read_input(2017, 9)
out = 0
level = 0
garbage = False
skip = False
for c in input:
if skip:
skip = False
continue
if garbage:
if c == "!":
skip = True
elif c == ">":
garbage = False
else:
if c == "{":
level += 1
elif c == "}":
out += level
level -= 1
elif c == "<":
garbage = True
print(out)
out = 0
level = 0
garbage = False
skip = False
for c in input:
if skip:
skip = False
continue
if garbage:
if c == "!":
skip = True
elif c == ">":
garbage = False
else:
out += 1
else:
if c == "{":
level += 1
elif c == "}":
level -= 1
elif c == "<":
garbage = True
print(out)