def get_differences(numbers: list[int]) -> list[int]:
    differences = []
    for i in range(1, len(numbers)):
        differences.append(numbers[i] - numbers[i - 1])
    return differences

values = []

for line in open("./input2"):
    history = [[int(x) for x in line.split(" ")]]
    while not all(x == 0 for x in history[-1]):
        history.append(get_differences(history[-1]))
    history.reverse()
    for i in range(len(history)):
        if i == 0:
            history[i].append(0)
            continue
        history[i].append(history[i][-1] + history[i - 1][-1])
    values.append(history[-1][-1])

print(values)
print(sum(values))