public static int generate(int[] result, int N) {
         int res = 0;
         if (result.length == N) {
             return 1;
         }
         else {
             for (int i=0; i<result.length; i++) {
                 result[N] = i;
                 if (isConsistent(result, N)) 
                     res += generate(result, N+1);
             }
         }
         return res;
     }