private void transpose(int[][] board) {
        if (board.length != board[0].length) {
            throw new UnsupportedOperationException();
        }
        int n = board.length;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                int buf = board[i][j];
                board[i][j] = board[j][i];
                board[j][i] = buf;
            }
        }
    }