Niwango-kun is an employee of Dwango Co., Ltd.
One day, he is asked to generate a thumbnail from a video a user submitted.
To generate a thumbnail, he needs to select a frame of the video according to the following procedure:
Get an integer N and N integers a_0, a_1, ..., a_{N-1} as
inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video.
Select t-th frame whose representation a_t is nearest to the average of all frame representations.
If there are multiple such frames, select the frame with the smallest index.
Find the index t of the frame he should select to generate a thumbnail.
Constraints
1 \leq N \leq 100
1 \leq a_i \leq 100
All numbers given in input are integers
Input
Input is given from Standard Input in the following format:
N
a_{0} a_{1} ... a_{N-1}
Output
Print the answer.
Examples
Input
3
1 2 3
Output
1
Input
4
2 5 2 5
Output
0
Assistant
We need to write solution: problem: given N and a_i, find index t such that a_t is nearest to average (mean) of all a_i. If multiple, choose smallest index.
We need compute average. Since values are integers but average may be non-integer. "nearest" likely means absolute difference minimized. We need to compute sum, then compute average as sum/N (floating point). But we can also compare as rational numbers. Simpler: compute sum, then for each i compute |a_i * N - sum| to compare distances scaled by N. Because |a_i - avg| = |a_i - sum/N| = |a_iN - sum| yields same ordering. So we can compute diff_i = |a_i * N - sum|. Find min diff_i, then smallest index.
N - sum| / N. Since denominator N>0 constant, minimizing |a_i
Edge cases: average exactly halfway between two integers? Then both have same absolute difference? Actually if a_i * N - sum = 0 then perfect. If two a_i have same absolute difference, we choose smallest index.
Implementation: read N, list a. Compute total = sum(a). Compute min_diff = large number, ans = 0. Loop i from 0 to N-1: diff = abs(a[i]*N - total). if diff < min_diff: update min_diff and ans. At end print ans.
Check examples:
N=3, a=[1,2,3], sum=6. a0: |1*3-6|=3, a1: |6-6|=0, a2: |9-6|=3. min diff=0 at i=1, output 1.
N=4, a=[2,5,2,5], sum=14. a0: |2*4-14|=|8-14|=6, a1:|20-14|=6, a2:|8-14|=6, a3:|20-14|=6. All diff=6, so choose smallest index 0. Output 0.
Works.
We need to produce final answer: Python code.
Let's also consider constraints: N<=100 so trivial.
Thus final answer is the code.
Now output only the solution. Provide explanation? The user said "write solution". They expect code. In typical ChatGPT "final" we provide solution.
I will produce the code with reading input, computing.
Make sure to handle newline etc. Use sys.stdin.
Will output ans.
Thus final. ```python
import sys
def main():
data = sys.stdin.read().strip().split()
if not data:
return
N = int(data[0])
a = list(map(int, data[1:1+N]))
total = sum(a)
min_diff = None
ans = 0
for i, val in enumerate(a):
diff = abs(val * N - total)
if min_diff is None or diff < min_diff:
min_diff = diff
ans = i
print(ans)