implemented kmeans cost