#K34962. Finding the Closest Friend
Finding the Closest Friend
Finding the Closest Friend
In this problem, n friends are standing equally spaced on a circle. The i-th friend is located at an angle \(\theta_i = \frac{2\pi i}{n}\) (in radians) from the positive x-axis and exerts a pulling force of magnitude strengths[i] toward the center.
The net force vector is obtained by summing the contributions from all friends:
\[ X = \sum_{i=0}^{n-1} {\tt strengths}[i]\cos\left(\frac{2\pi i}{n}\right), \quad Y = \sum_{i=0}^{n-1} {\tt strengths}[i]\sin\left(\frac{2\pi i}{n}\right). \]
Let \(\theta = \operatorname{atan2}(Y, X)\) (adjusted to be within \([0, 2\pi)\)). Then, the candidate index is computed by:
\[ \text{candidate} = \left(\operatorname{round}\left(\frac{n \theta}{2\pi}\right)\right) \bmod n. \]
Finally, consider the friends in the cyclic order starting from this candidate index (i.e. the list \(\texttt{strengths}[\text{candidate}:] + \texttt{strengths}[:\text{candidate}]\)). The answer is the index (in the original list) of the friend who has the maximum strength according to this order. Your task is to compute and output this index.
inputFormat
The first line contains an integer \(n\) representing the number of friends.
The second line contains \(n\) space-separated integers, where the \(i\)-th integer represents strengths[i], the pulling strength of the \(i\)-th friend.
outputFormat
Output a single integer which is the zero-based index of the friend selected based on the aforementioned process.
## sample4
10 20 30 40
3