import math


def part2(data):
    """Return least fuel to move all submarines to same position.

    Fuel to go from current to desired position is 1 + 2 + ... + abs(d - c).
    """
    numbers = list(map(int, data.split(',')))
    # puzzle has 100s of numbers in a range of 1000, so brute-force is OK
    min_fuel = math.inf
    for position in range(min(numbers), max(numbers)+1):
        fuel = 0
        for number in numbers:
            difference = abs(number - position)
            fuel += difference * (difference + 1) // 2
        if fuel < min_fuel:
            min_fuel = fuel
    return min_fuel