def is_valid_grid(grid):
    n = len(grid)
    for i in range(n):
        for j in range(n):
            if grid[i][j] != grid[0][j] and grid[i][j] != grid[i][0]:
                return True
    return False


grid = [
    [1, 2, 3],
    [2, 3, 1],
    [3, 1, 2]
]

ret = is_valid_grid(grid)
print(ret)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: