def calculate_manhattan_dist(idx, value, n):
    """calculate the manhattan distance of a tile"""
    if value == 0:
        return 0
    value_x, value_y = idx // n, idx % n
    sol_x, sol_y = value // n, value % n
    return abs(sol_x-value_x) + abs(sol_y-value_y)