code: static double squaredDistance(double[] x, double[] y) {
          int n = x.length;
          int m = 0;
          double dist = 0.0;
  
          for (int i = 0; i < n; i++) {
              if (!Double.isNaN(x[i]) && !Double.isNaN(y[i])) {
                  m++;
                  double d = x[i] - y[i];
                  dist += d * d;
              }
          }
  
          if (m == 0) {
              dist = Double.MAX_VALUE;
          } else {
              dist = n * dist / m;
          }
  
          return dist;
      }
docs: Squared Euclidean distance with handling missing values (represented as NaN).