private boolean set(int i, int value)
    {
      X[i] = value;
      
      int maxA = 0;
      for (int j = 0; j < i; j++)
      {
        if (X[j] != 0)
        {
          maxA = Math.max(maxA, A[j]);
        }
      }

      int maxB = 0;
      for (int j = i+1; j < N; j++)
      {
        if (X[j] != 0)
        {
          maxB = Math.max(maxB, B[j]);
        }
      }
      
      return maxA + 1 == A[i] && maxB + 1 == B[i];
    }