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 x_{i} has a corresponding weight w_{i}. As the gravitational force on Joy
differs from earth, the “distance” between their home and the gathering
position p need to be calculated as S^{3}*W_{i} where S is |x_{i} - p|.

In a word, we need to calculate the
position p that minimize the total distance Σ( S^{3}*W_{i}) where S is |x_{i} - p|.