import collections


def align (crabs, cost):
    """Aligns the crab positions `crabs` (array) to the same position using
    the least fuel, according to the given `cost` function.  The `cost`
    function takes a single parameter, the number of steps to move,
    i.e. `cost(steps)`.

    Returns `(pos, fuel)`.
    """
    fuel = collections.defaultdict(int)

    for moveto in range( max(crabs) ):
        for crab in crabs:
            fuel[moveto] += cost( abs(crab - moveto) )

    return min(fuel.items(), key=lambda pair: pair[1])