def check_position(grid, num, row, col):
    """
    Based on rules, checks if the given 'num' is in a valid position.
    """
    def box_pos(val):
        # Determine coordinates of 3x3 box corresponding to val(row or col of the current square)
        if val < 3:
            pos = 0
        elif 3 <= val < 6:
            pos = 3
        else:
            pos = 6
        return pos

    # Check row
    if num in grid[row, :]:
        return False
    # Check column
    if num in grid[:, col]:
        return False

    # Check box
    pos_y = box_pos(row)
    pos_x = box_pos(col)
    if num in grid[pos_y:pos_y+3, pos_x:pos_x+3]:
        return False

    return True