···11+import fileinput
22+from functools import cache
33+44+55+@cache
66+def dp(s, n):
77+ """Dynamic program to get the max joltage of a string."""
88+ if n == 1:
99+ return max(s)
1010+1111+ poss = []
1212+ for i in range(len(s) - n + 1):
1313+ poss.append(s[i] + dp(s[i+1:], n - 1))
1414+1515+ return max(poss)
1616+1717+1818+PART_1 = 0
1919+PART_2 = 0
2020+2121+for bank in fileinput.input():
2222+ bank = bank.strip()
2323+ PART_1 += int(dp(bank, 2))
2424+ PART_2 += int(dp(bank, 12))
2525+2626+print("Part 1:", PART_1)
2727+print("Part 2:", PART_2)
2828+