def heuristic(puzzle, n):
    """
    Compute the Manhattan distance of all tiles corresponding to the heuristic used in the A* algorithm.

    :param puzzle: The puzzle instance
    :param n: Configuration for which we want to compute the total Manhattan distance.
    :return:  Total Manhattan distances for all tiles in configuration.
    """
    dist = 0
    for i in range(9):
        # Sum of Manhattan distances for all tiles
        dist += abs(n[i][0] - puzzle.winCdt[i][0]) + abs(n[i][1] - puzzle.winCdt[i][1])
    return dist