A remote planet is called Joy. There is an ancient rule in Joy that every kid need to go for a hiking in dark forest to become an adult. This year, the kids of Joy that need to go for a hiking want to go together to ensure their safety. But they want to calculate a position to gather which minimizes the sum of their “distance”.
To simplify, we assume Joy is a straight line, every kid has a location xi on the line and every xi has a corresponding weight wi. As the gravitational force on Joy differs from earth, the “distance” between their home and the gathering position p need to be calculated as S3*Wi where S is |xi - p|.
In a word, we need to calculate the position p that minimize the total distance Σ( S3*Wi) where S is |xi - p|.