private boolean isValid(List<Integer> perm){
        for (int i = 0; i < perm.size(); ++i){
            for (int j = i + 1; j < perm.size(); ++j){
                if (i - j == perm.get(i) - perm.get(j) || i - j == perm.get(j) - perm.get(i)) return false;
            }
        }
        return true;
    }