code: private static double distanceSum(double[] distances) {
          double sum = 0;
          for (double distance : distances)
              sum += Math.pow(distance, 2);
          return sum;
      }
docs: Returns the sum of distances squared.