39 lines
796 B
Python
39 lines
796 B
Python
import fileinput
|
|
import itertools
|
|
from collections import deque
|
|
|
|
adapters = [0]
|
|
for line in fileinput.input():
|
|
adapters.append(int(line))
|
|
adapters.sort()
|
|
adapters.append(adapters[-1] + 3)
|
|
|
|
one = 0
|
|
three = 0
|
|
|
|
for (fr, to) in zip(adapters[:-1], adapters[1:]):
|
|
if to - fr == 1:
|
|
one += 1
|
|
elif to - fr == 3:
|
|
three += 1
|
|
print(fr, to)
|
|
|
|
print(one, three, one * three)
|
|
paths = [0] * len(adapters)
|
|
paths[0] = 1
|
|
|
|
ways = 1
|
|
for i, value in enumerate(adapters[:-1]):
|
|
try:
|
|
if adapters[i + 1] <= value + 3:
|
|
paths[i + 1] += paths[i]
|
|
if adapters[i + 2] <= value + 3:
|
|
paths[i + 2] += paths[i]
|
|
if adapters[i + 3] <= value + 3:
|
|
paths[i + 3] += paths[i]
|
|
except IndexError:
|
|
pass
|
|
|
|
print(paths)
|
|
print(paths[-1])
|