code: public static long countUnorderedPairs(int minI, int maxI, int minJ, int maxJ) {
          long maxPairs = 0;
          int min = Math.min(minI, minJ);
          int max = Math.max(maxI, maxJ);
      
          for (int i=min; i<max; i++) {
              for (int j=i; j<max; j++) {
                  if ((minI <= i && i < maxI && minJ <= j && j < maxJ) ||
                      (minJ <= i && i < maxJ && minI <= j && j < maxI)) {
                      maxPairs++;
                  }
              }
          }
          return maxPairs;
      }
docs: Count the number of unordered pairs that satisfy the constraint the
  constraints: minI <= i < maxI and minJ <= j < maxJ.
  
  Note that since these are unordered pairs. We can think of this as being
  the count of ordered pairs (i,j) s.t. i<=j and either of the following
  two conditions holds:
  
  minI <= i < maxI and minJ <= j < maxJ.
  
  minI <= j < maxI and minJ <= i < maxJ.
  
  @param minI The minimum value for i (inclusive).
  @param maxI The maximum value for i (exclusive).
  @param minJ The minimum value for j (inclusive).
  @param maxJ The maximum value for j (exclusive).
  @return The number of unordered pairs.