aboutsummaryrefslogtreecommitdiff
path: root/2025/03/b.py
blob: 4c74ae6a7d18bb5daf3f242e4d05ccce79fb2390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import fileinput
from functools import cache

neginf = -1e13

@cache
def joltage(line, n):
	if n == 0:
		return 0
	if n > len(line)-1:
		return neginf
	j = 0
	for i in range(len(line)-1):
		j = max(j, int(line[i])*10**(n-1)+joltage(line[i+1:],n-1))
	return j

with fileinput.input() as lines:
	print(sum(joltage(line, 12) for line in lines))

Generated with cgit - Back to sebastiano.tronto.net