Problem:
 Score : 200 points    Problem Statement  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.        Sample Input 1  3
1 2 3      Sample Output 1  1  Since the average of frame representations is 2 , Niwango-kun needs to select the index 1 , whose representation is 2 , that is, the nearest value to the average.       Sample Input 2  4
2 5 2 5      Sample Output 2  0  The average of frame representations is 3.5 . In this case, every frame has the same distance from its representation to the average. Therefore, Niwango-kun should select index 0 , the smallest index among them.

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
s = sum(a)/N
a = [(abs(a[i]-s),i) for i in range(N)]
a.sort()
print(a[0][1])

Solution (Python):
N = int(input())
a = list(map(lambda x: int(x), input().split(' ')))

avg = sum(a)/N
min = 1000
answer = 101

for i in range(0, N):
	if abs(a[i] - avg) < min:
		min = abs(a[i] - avg)
		answer = i

print(answer)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

mean = 0

for i in range(len(A)):
    mean += A[i]

mean /= len(A)

min_value = 1000
min_frame = 0
for i in range(len(A)):
    tmp_value = abs(A[i] - mean)
    if min_value > tmp_value:
        min_value = tmp_value
        min_frame = i

print(min_frame)

Solution (Python):
n = int(input())
arr = list(map(int,input().split()))

total = 0 
for i in range(n):
    total += arr[i]

ave = total / n

tmp = float('inf')

for j in range(n):
    if abs(arr[j] - ave) < tmp:
        tmp = abs(arr[j] - ave)
        ans = j
print(ans)

Solution (Python):
n = int(input())
a_array = [int(x) for x in input().split()]

avg = sum(a_array)/n

res = 1000000
ret = 0
for i, j in enumerate(a_array, 0):
    if abs(j-avg) < res:
        res = abs(j-avg)
        ret = i
print(ret)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

avg = sum(a)/N

ans = 0
tmpmin = abs(a[0]-avg)
for i in range(1, N):
    if abs(a[i]-avg) < tmpmin:
        tmpmin = abs(a[i]-avg)
        ans = i

print(ans)

Solution (Python):
N = int(input())

a = list(map(int,input().split()))

sum = 0
for n in a:
    sum += n

ave = float(sum) / N

ans_content = N
for i,n in enumerate(a):
    if ans_content > abs(n-ave):
        ans = i
        ans_content = abs(n-ave)

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

argmin_diff = None
min_diff = 100
mean_a = sum(a) / len(a)
for i, val in enumerate(a):
    diff = abs(val - mean_a)
    if diff < min_diff:
        min_diff = diff
        argmin_diff = i
print(argmin_diff)

Solution (Python):
N = int(input())
a = list(map(int,input().split(" ")))
b = sum(a) / N
now = 100
count = 0
for i in range(N):
    c = abs(a[i]-b)
    if now > c:
        count = i
        now = c
print(count)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
mean = sum(a)/len(a)
for i in range(n):
    if i == 0:
        result = i
    elif i > 0:
        if abs(mean - a[i]) < abs(mean - a[result]):
            result = i
print(result)

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
ave=sum(a)/N
ans=0
min_d=100
for i in range(N):
  d = abs(ave-a[i])
  if d < min_d:
    min_d=d
    ans=i
print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
num = 1000000
ans = 0

meam = sum(a) / n
for i in a:
  b = abs(i - meam)
  if b < num:
    num = b
    ans = a.index(i)
    
print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ave = sum(a)/N
tmp = 100000
ans = 0
for i in range(N):
    if abs(a[i]-ave)<tmp:
        ans = i
        tmp = abs(a[i]-ave)
print(ans)

Solution (Python):
from sys import stdin

def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    n = sum(A) / N
    ans, d = 0, float('inf')
    for i, a in enumerate(A):
        if abs(n - a) < d:
            ans = i
            d = abs(n - a)
    print(ans)

input = lambda: stdin.readline()
main()

Solution (Python):
N = int(input())
a = list(map(int,input().split()))

k = 0
ans = 0
for i in range(N):
    k += a[i]
find = k/N
now = 1000000
for i in range(N):
    if abs(a[i]-find) < now - 0.00001:
        ans = i
        now = abs(a[i]-find)
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
avg = sum(a) / n
min_i = 0
min_v = abs(a[0]-avg)
for i in range(len(a)):
    if min_v > abs(a[i]-avg):
        min_v = abs(a[i] - avg)
        min_i = i
print(min_i)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
l = []
ave = sum(a)/n

diff = 1000
res = 0

for i in range(len(a)):
    if diff > abs(ave-a[i]):
        res = i
        diff = abs(ave-a[i])
else:
    print(res)

Solution (Python):
N = int(input())
a = list(map(int,input().split(' ')))

sum_a = sum(a)
b = sum_a/N
ans = 0
minimum = abs(b-a[0])
for i in range(1,N):
    if minimum > abs(b-a[i]):
        minimum = abs(b-a[i])
        ans = i

print(ans)

Solution (Python):
import numpy as np

n = int(input())
a_list = np.array(list(map(int, input().split())))

kouho = abs(a_list - np.mean(a_list))
print(np.where(kouho == kouho.min())[0].min())

Solution (Python):
import math

N = int(raw_input())
A = [int(x) for x in raw_input().split()]
a = sum(A)/float(N)
tmp=99999999
ans=0
for i in range(N):
    if abs(a-A[i]) < tmp:
        tmp =abs(a-A[i])
        ans =i
print ans

Solution (Python):
N = int(input())

S = list(map(int, input().split()))

a = 10000

min = 0

for i in range(N):
    if abs(S[i] - sum(S)/len(S)) < a:
        a = abs(S[i] - sum(S)/len(S))
        min = i

print(min)

Solution (Python):
from statistics import mean

N = int(input())
a = [int(i) for i in input().split()]

a_mean = mean(a)

ans = 0
ans_dist = max(a)
for i, frame in enumerate(a):
    dist = abs(frame - a_mean)
    if dist < ans_dist:
        ans_dist = dist
        ans = i

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
n = sum(A) / N
A2 = [abs(n - a) for a in A]
min_a = min(A2)
print(A2.index(min_a))

Solution (Python):


N = int(input())
a = [int(i) for i in input().split()]

total = 0
for i in range(N):
    total += a[i]
ave = total / N

small = abs(a[0] - ave)
place = 0
for i in range(1,N):
    if abs(a[i] - ave) < small:
        small = abs(a[i] - ave)
        place = i

print(place)

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
b=sum(a)/N
d=10**9
ans=0
for i in range(N):
  if abs(a[i]-b)<d:
    ans=i
    d=abs(a[i]-b)
print(ans)

Solution (Python):
n = int(input())
a = [int(s) for s in input().split()]
ave = sum(a) / n
ans, m = 500, 500
for v, i in sorted(((abs(x - ave), i) for (i, x) in enumerate(a)), key=lambda t: t[0]):
    if m > 100:
        m = v
        ans = min(ans, i)
    else:
        break
print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ave = sum(A) / N
A = abs(A - ave)
min = min(A)
A = list(A)
idx = A.index(min)
print(idx)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]

tmp = 100

ave = sum(A)/N

for i in range(N):
    if abs(A[i]-ave) < tmp:
        tmp = abs(A[i]-ave)
        ans = i
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

avg = sum(A) / N
ans = 0
diff = float('inf')

for i, a in enumerate(A):
    if abs(avg - a) < diff:
        ans = i
        diff = abs(avg - a)

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

ave = sum(A) / N
diff_min = float('inf')
ans = -1

for i, a in enumerate(A):
    if diff_min > abs(ave - a):
        diff_min = abs(ave - a)
        ans = i

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ave = sum(a)/n
ans = 10000000000
unt = 0
for i in range(n):
    if ans > abs(ave-a[i]):
        ans = abs(a[i]-ave)
        unt = i
print(unt)

Solution (Python):
def main():
    N = int(input())
    a = list(map(int, input().split()))
    avg = sum(a) / N
    min_abs = float("inf")
    min_frame = 0
    for i in range(N):
        score = abs(a[i] - avg)
        if score < min_abs:
            min_abs = score
            min_frame = i
    print(min_frame)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
nums = list(map(int, input().split()))
ave = sum(nums)/N
ans = 10000
ans2 = 0 
for i in range(N):
  temp = abs(ave - nums[i])
  if ans>temp:
    ans = temp
    ans2 = i

print(ans2)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
ans = 1000
avg = sum(a) / N
for i in range(N):
    x = abs(avg - a[i])
    if x < ans:
        ans = x
        index = i
print(index)

Solution (Python):
N = int(raw_input())
A = map(int, raw_input().split())

average = sum(A)/float(N)

diff = max(A)
index = None

for i, a in enumerate(A):
    if abs(a-average) < diff:
        index = i
        diff = abs(a-average)
print(index)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

ave = sum(a)/N
nearest = 0
for i in range(N):
    if abs(a[i] - ave) < abs(a[nearest] - ave):
        nearest = i
print(nearest)

Solution (Python):
n=int(input())

aList=list(map(int,input().split()))

s=sum(aList)
mean=s/n

ans=-1
kyori=1000
for i in range(n):
  tmpkyori=abs(aList[i]-mean)
  if kyori>tmpkyori:
    ans=i
    kyori=tmpkyori

print(ans)

Solution (Python):

import numpy as np
def solve():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    f = np.argmin(np.abs(A-A.mean()))
    return f
    
if __name__ == '__main__':
    print(solve())

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
m = sum(A) / float(N)
ans = 0
min_diff = 10**6
for i, a in enumerate(A):
    tmp = abs(a - m)
    if tmp < min_diff:
        min_diff = tmp
        ans = i
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
avg=0
for i in a:
    avg+=i
avg/=n
b=[]
for i in a:
    b.append(abs(i-avg))
print(b.index(min(b)))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

avg = sum(a)/len(a)
b = []
for aa in a:
    b.append(abs(aa-avg))

print(b.index(min(b)))

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]

ave = sum(a)/len(a)
sub = 100000
ans = -1

for i in reversed(range(len(a))):
    if abs(a[i]-ave) <= sub:
        sub = abs(a[i]-ave)
        ans = i

print(ans)

Solution (Python):
from statistics import mean, median,variance,stdev
N = int(input())
a = list(map(int,input().split()))
b = mean(a)
for i in range(N):
  a[i] = abs(a[i]-b)
  if a[i]==0:
    print(i)
    exit(0)
b = min(a)
for i in range(N):
  if a[i]==b:
    print(i)
    break

Solution (Python):
n = int(input())
alIst = list(map(int, input().split()))

sumN = 0

for i in range(n):
    sumN += alIst[i]

mean = sumN / n

min_margin = float("inf")
frame = 0

for i in range(n):
    a = alIst[i]
    margin = abs(a-mean)
    if margin < min_margin:
        min_margin = margin
        frame = i

print(frame)

Solution (Python):
import math
from functools import reduce
import collections
import itertools
n = input()
a = list(map(int,input().split()))
m =  sum(a)/len(a)
ans = 0
sabun = 1000000000000000000
for (i, x) in enumerate(a):
   
    if abs(x - m) < sabun:
        sabun = abs(x-m)
        ans = i
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))

s = sum(a)
for i in range(len(a)):
    a[i]*=n
a_diff = [abs(a[i]-s) for i in range(len(a))]
mi = min(a_diff)



for i in range(len(a_diff)):
    if a_diff[i] == mi:
        print(i)
        exit()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
sum=0
for i in range(n):
  sum+=a[i]
ave=sum/n
min=abs(a[0]-ave)
ans=0
for i in range(1,n):
  if (abs(a[i]-ave)<min):
    min=abs(a[i]-ave)
    ans=i
print(ans)

Solution (Python):
from statistics import mean
N = int(input())
a=list(map(int,input().split(' ')))

avg=mean(a)

b=[]
for i in range(N):
    b.append(abs(a[i]-avg) )




for i in range(N):
    if b[i]==min(b):
        print(i)
        exit(0)

Solution (Python):
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

MOD = 10 ** 9 + 7

N = int(input())
A = [int(x) for x in input().split()]


ave = sum(A)/N

d = [abs(a - ave) for a in A]
mi = min(d)

for i in range(N):
    if d[i] == mi:
        print(i)
        sys.exit(0)

sys.exit(0)

Solution (Python):
import statistics
import numpy as np

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n = int(input())
A = list(map(int,input().split()))
mean = statistics.mean(A)
print(A.index(getNearestValue(A,mean)))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

p = 0
d = abs(n * a[0] - sum(a))

for i in range(1, n):
  if abs(n * a[i] - sum(a)) < d:
    d = abs(n * a[i] - sum(a))
    p = i

print(p)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a_avg = sum(a) / len(a)
ai_min = 0  
d_min = abs(a[0] - a_avg)  
for i in range(1, N):
    d = abs(a[i] - a_avg)
    if d < d_min:
        ai_min = i
        d_min = d
print(ai_min)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
av=0
for i in range(n):
    av+=a[i]
av/=n
ans=0
anss=abs(av-a[0])
for i in range(1,n):
    if anss>abs(av-a[i]):
        ans=i
        anss=abs(av-a[i])
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
ave = sum(a)/N
for i in range(len(a)):
    a[i] = abs(a[i]-ave)

mina, minid = 1e9,-1
for i in range(len(a)):
    if mina>=a[N-1-i]:
        mina, minid = a[N-1-i], N-1-i
print(minid)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

ave = sum(a)/n

dif = 1000
ans = 0
for i in range(n):
    if abs(a[i]-ave) < dif:
        dif = abs(a[i]-ave)
        ans = i

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

md = sum(a)/n

ans = 0
m = float('inf')
for i in range(n):
    if abs(a[i]-md) < m:
        ans = i
        m = abs(a[i]-md)
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
ave = 0
i = 0
for i in range(N):
    ave += a[i]
ave /= N
mini = 1000
mnum = 1000
for j in range(N):
    if mini > abs(a[j] - ave):
        mini = abs(a[j] - ave)
        mnum = j
print(mnum)

Solution (Python):
N=int(input())
a=list(map(int, input().split()))
adv=sum(a)/N
min=10000
ans=0
for i in range(N):
    if min>abs(a[i]-adv):
        min=abs(a[i]-adv)
        ans=i
print(ans)

Solution (Python):
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [long(input_raw[0])]
    A = []
    input_raw = read_func().strip().split()
    S = 0.0
    for i in range(N):
        A.append(int(input_raw[i]))
        S += int(input_raw[i])
    Ave = S/N

    min_err = float(sys.maxint)
    min_idx = 0
    for i in range(N):
        err = abs(A[i] - Ave)
        if err < min_err:
            min_err = err
            min_idx = i
    print min_idx



if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

N= int(input())
Ax = list(map(int, input().split(" ")))

Ax = np.array(Ax)
r = np.average(Ax)
Dx = list(map(lambda x:abs(r-x), Ax))
m = min(Dx)
r = Dx.index(m)

print(r)

Solution (Python):
N = int(input())
a = [int(_) for _ in input().split()]
av = sum(a) / N

a = [(abs(ai - av), i) for (i, ai) in enumerate(a)]
mi = min(a)
print(mi[1])

Solution (Python):
import numpy as np

n = int(input())
l = np.array(list(map(int, input().split())))

m = np.mean(l)
 
dif = abs(l - m)

mini = dif[0]
ans = 0

for i in range(n):
    if dif[i] < mini:
        mini = dif[i]
        ans = i
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

ave = float(sum(a) / n)
min_d = 1e9
ans = 0
for i in range(n):
    if abs(ave-a[i]) < min_d:
        ans = i
        min_d = abs(ave-a[i])

print(ans)

Solution (Python):
n = int(raw_input())
ar = map(int, raw_input().split())

s = sum(ar)

margin = 9999999999999999999999999999999999999
pos = -7

for i in xrange(n):
    if abs(n * ar[i] - s) < margin:
        margin = abs(n * ar[i] - s)
        pos = i

print pos

Solution (Python):


import sys

input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()
m = sum(A)/N
tmp = INF
min_num = A[0]
for b in A:
    if abs(b - m) < tmp:
        tmp = abs(b - m)
        min_num = b

print(A.index(min_num))

Solution (Python):
n = int(raw_input())
nums = map(float, raw_input().split())
sum = 0.0
for i in xrange(n):
	sum += nums[i]
avg = sum / float(n)
ans, idx = 10000.0, 0
for i in xrange(n):
	if abs(avg-nums[i]) < ans:
		ans = abs(avg-nums[i])
		idx = i
print idx

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n = int(input())
e = [int(i) for i in input().split()]

s = sum(e) / n;
v = 0xFFFFFFFF
ans = -1
for i in range(n):
    if (abs(s - e[i]) < v):
        v = abs(s - e[i])
        ans = i
print(ans)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]

h=sum(a)/n
ans=0
an=0
k=abs(h-a[0])

for i in range(n):
    if k>abs(h-a[i]):
        k=abs(h-a[i])
        ans=i
        
print(ans)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    avg = sum(A)/len(A)
    diff = 300000
    ans = 0
    for i in range(len(A)):
        if abs(A[i]-avg) < diff:
            diff = abs(A[i]-avg)
            ans = i
        else:
            pass
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

A = list(map(int,input().split()))

AVE = sum(A)/len(A)
DIFF = 1000.0
Samu = 0
for i in range(N):
    a = A[i]
    if abs(AVE-a) < DIFF:
        DIFF = abs(AVE-a)
        Samu = i
    
        
print(Samu)

Solution (Python):
n = int(input())
a = [int(v) for v in input().split()]

ave = sum(a) / n
ans = 0
diff = abs(a[ans] - ave)
for i in range(1, n):
    if diff > abs(a[i] - ave):
        diff = abs(a[i] - ave)
        ans = i

print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
sum=0
for i in range(N):
    sum+=a[i]
ave=sum/N
ans=-1
min=100
for i in range(N):
    if min > abs(a[i]-ave):
        ans=i
        min=abs(a[i]-ave)
print(str(ans))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
s = sum(a)
ans = -1
diff = 100000
for i in range(N):
	d = abs(s - a[i] * N)
	if d < diff:
		ans = i
		diff = d
print(ans)

Solution (Python):
n=int(input())
*a,=map(int,input().split())
m=sum(a)/n
i=0
s=10**18
for j in range(n):
    if abs(a[j]-m)<s:
        i=j
        s=abs(a[j]-m)
print(i)

Solution (Python):
n=int(input())
*a,=map(int,input().split())
avg=sum(a)/n

c=[(abs(j-avg),i) for i,j in enumerate(a)]
c.sort(key=lambda x:(x[0],x[1]))
print(c[0][1])

Solution (Python):


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split(' ')))

    A_average = sum(A) / N
    result = sorted(range(N), key=lambda i: abs(A[i] - A_average))

    print(result[0])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ave = sum(a) / n
b = 10000000
c = 0
for i in range(n):
    if b > abs(ave - a[i]):
        b = abs(ave - a[i])
        c = i
print(c)

Solution (Python):

N = int(input())
ls_a  = list(map(int,input().split()))
avg = sum(ls_a)/N
min_l = 1e+6
for i,a in enumerate(ls_a):
    if abs(a-avg)<min_l:
        min_l = abs(a-avg)
        min_idx = i
print (min_idx)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

from statistics import mean
M = mean(A)
A = [abs(a - M) for a in A]

ans = 0
cur = float('inf')
for i, v in enumerate(A):
    if cur > v:
        ans = i
        cur = v


print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

sum = 0
for i in range(len(A)):
    sum += A[i]

av = sum/len(A)
ans = 0
dis = 10000000

for i in range(len(A)):
    if abs(A[i]-av) < dis:
        dis = abs(A[i]-av)
        ans = i
print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
mid = float(sum(a)/n)
mi = 0
for i in range(1, n):
	if abs(mid - a[i]) < abs(mid - a[mi]):
		mi = i
print(mi)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
sum = 0
for item in a:
    sum += item
ave = sum / n
ans = [200, 0]
for i in range(n):
    if abs(a[i]-ave) < ans[0]:
        ans[0] = abs(a[i]-ave)
        ans[1] = i
print(ans[1])

Solution (Python):
N=int(input())
arr=list(map(int,input().split()))
mean=sum(arr)/N

ans=N
min_=10**12
for i,x in enumerate(arr):
    if abs(mean-x)<min_:
        min_=abs(mean-x)
        ans=i
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

x = sum(a) / len(a)
y = 100

for i in range(len(a)):
    if abs(a[i]-x) < y:
        result = i
        y = abs(a[i]-x)

print(result)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ave = sum(a) / n
ans_ = float("inf")
for i in range(n):
    if abs(ans_ - ave) > abs(a[i] - ave):
        ans_ = a[i]
        ans = i
print(ans)

Solution (Python):
a = int(input())

b = list(map(int,input().split()))

c = sum(b)/a
d = 10000
for i in range(a):
	if abs(b[i]-c) < d:
		d = abs(b[i]-c)

for i in range(a):
	if abs(b[i]-c) == d:
		print(i)
		break

Solution (Python):
from statistics import mean, median,variance,stdev

n = int(input())

a = list(map(int, input().split()))


ans = 0

s = sum(a)
N = len(a)
mean = s / N

for i in range(N):
    if abs(a[ans] - mean) > abs((a[i]-mean)):
        ans = i

print(ans)

Solution (Python):
from statistics import mean

N = int(input())
A = [int(x) for x in input().split()]

avg = mean(A)

mini = 0
mind = 101

for i in range(N):
    if abs(A[i] - avg) < mind:
        mini = i
        mind = abs(A[i] - avg)

print(mini)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
a=0
for i in range(n):
    a+=l[i]
a/=n

s=[]
for i in range(n):
    s.append(abs(l[i]-a))
b=min(s)

for i in range(n):
    if b==s[i]:
        print(i)
        break

Solution (Python):

N = int(input())
an = list(map(int, input().split()))

ave = sum(an)/len(an)

an2 = {i:abs(a-ave) for i,a in enumerate(an)}

ans,val = sorted(an2.items(), key=lambda x: x[1])[0] 

print(ans)

Solution (Python):
from sys import stderr, setrecursionlimit
from functools import reduce
from operator import add
from statistics import mean
setrecursionlimit(2147483647)
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n = int(input())
a = f()
m = mean(a)
min_ = 5000000000
ans = 0
for i, v in enumerate(a):
    if abs(v-m) < min_:
        min_ = abs(v-m)
        ans = i
print(ans)

Solution (Python):
import numpy as np
n=int(input())
A=np.array(list(map(int, input().split(" "))))

me=A.mean()
min_diff=99999999999999999999999999999999999
for num,i in enumerate(A):
    diff=abs(me-i)
    if diff<min_diff:
        out=num
        min_diff=diff

print(out)

Solution (Python):
N = int(input())
a_list = [int(elem) for elem in input().split()]

avg_a = sum(a_list) / N

min_dist = float('inf')
idx = -1
for i, a in enumerate(a_list):
    dist = abs(a - avg_a)
    if min_dist > dist:
        idx = i
        min_dist = dist
    elif min_dist == dist and i < idx:
        idx = i

print(idx)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
mean_a = sum(a) / N
l = [abs(a_i - mean_a) for a_i in a]
print(l.index(min(l)))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
s = sum(A)
for i in range(N):
    A[i] *= N
mi = float("inf")
imi = 0
for i, a in enumerate(A):
    if abs(a-s) < mi:
        imi = i
        mi = abs(a-s)
print(imi)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    total += a[i]

tar = total / n

d = tar
ans = 0
for i in range(n):
    k = abs(tar - a[i])
    if(k < d):
        d = k
        ans = i

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split(" ")))

avg = sum(a) / n
ans = -1
tmp = 1e10

for i in range(len(a)):
    if(tmp > abs(a[i]-avg)):
        ans = i
        tmp = abs(a[i]-avg)

print(ans)

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
mean = sum(a) / len(a)

ans = 0
diff = abs(a[0] - mean)
for i in range(1,N):
    if diff > abs(a[i] - mean):
        diff = abs(a[i] - mean)
        ans = i
print(ans)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
mean=sum(a)/n
a=[abs(i-mean) for i in a]
b=[]
for i in range(n):
    b.append([a[i],i])
b.sort()
print(b[0][1])

Solution (Python):
import numpy as np

N = int(input())
a = list(map(int, input().split()))
b = np.array([abs(N * a[i] - sum(a)) for i in range(N)])
print(b.argmin())

Solution (Python):

N = int(input())
a = list(map(int, input().split()))

idx = -1
mindiff = 100
ave = sum(a) / N
for i, ai in enumerate(a):
   diff = (ai - ave) if ai > ave else (ave - ai)
   if diff < mindiff:
       idx = i
       mindiff = diff

print(idx)

Solution (Python):
n = int(input())
a = input().split()
a = [int(m) for m in a]
b = sum(a) / n
bli = []
for i in range(n):
    bli.append([abs(b - a[i]), i])
bli.sort()
print(bli[0][1])

Solution (Python):



def main():
    n = int(input())
    a = list(map(int, input().split()))
    diff = float('inf')
    ans = 0
    ave = sum(a) / n

    for i, ai in enumerate(a):
        if abs(ai - ave) < diff:
            diff = abs(ai - ave)
            ans = i

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
ave = sum(a)/len(a)
b = [0 for i in a]
b = [abs(a[i]-ave) for i in range(n)]
print(b.index(min(b)))

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
S=sum(a)
b=[abs(N*a[i]-S) for i in range(N)]
L=[]
m=min(b)
for i in range(N):
    if b[i]==m:
        L.append(i)
print(min(L))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

avg = sum(a) / N
near = None
near_n = float("inf")

for i, x in enumerate(a):
    if abs(avg - x) < near_n:
        near = i
        near_n = abs(avg - x)

print(near)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

ave = sum(a) / len(a)
idx = -1
d = float('inf')
for i in range(n):
    t = abs(a[i] - ave)
    if t < d:
        d = t
        idx = i

print(idx)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
tyu = sum(A)/N
ans = [0] * N
for i in range(N):
    ans[i] = abs(tyu-A[i])
print(ans.index(min(ans)))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

ava = sum(a) / n

for i in range(n):
    a[i] = abs(a[i] - ava)

mina = min(a)
for i in range(n):
    if a[i] == mina:
        print(i)
        break

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
ave=sum(a)/N
m=100000000000000
ans=100000000000
for i in range(N):
    A=abs(a[i]-ave)
    if A<m:
        m=A
        ans=i
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ave = sum(A) / len(A)
ans = 100
ans_index = 0
for i in range(N):
    dif = abs(A[i] - ave)
    if dif < ans:
        ans = dif
        ans_index = i
print(ans_index)

Solution (Python):
import sys
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

ave = np.sum(a)/n
x = np.abs(a-ave)
m = np.min(x)
for i,s in enumerate(x):
    if s==m:
        print(i)
        sys.exit()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

sum = sum(a)
min = 100000
ans = 0
for i in range(len(a)):
    if abs(a[i] * n - sum) < min:
        ans = i
        min = abs(a[i] * n - sum)

print(ans)

Solution (Python):




def main():
    n = int(input())
    a = list(map(int, input().split()))

    ave = sum(a) / n
    ans, k = 0, 500
    for i in range(n):
        if abs(a[i]-ave) < k:
            ans = i
            k = abs(a[i]-ave)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]


ave = sum(a)/N

bestId = 0
bestScore = abs(a[0]-ave)
for i in range(1,N):
    score = abs(a[i]-ave)
    if bestScore>score:
        bestId=i
        bestScore = score
print(bestId)

Solution (Python):
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()
m = sum(A) / N

print(sorted([(abs(a-m), i) for i, a in enumerate(A)])[0][1])

Solution (Python):
n = int(input())
A = [int(i) for i in input().split()]

avg = sum(A) / n

ans = 0
m = A[0]

for i, a in enumerate(A):
    if abs(a - avg) < abs(m - avg):
        ans = i
        m = a

print(ans)

Solution (Python):


from statistics import mean, median,variance,stdev
n = int(input())
l = list(map(int,input().split(" ")))
m = mean(l)
d = 1000
ans = 10000
for i in range(n):
    a = l[i]
    t = abs(m - a)
    if t < d:
        d = t
        ans = i
print(ans)

Solution (Python):
N=int(input())
A = list(map(int,input().split()))

p = sum(A)/N

q = 10*9
for i in range(N) :
    r = abs(A[i] - p)
    if r < q :
        q = r
        ans = i
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
k=sum(a)/n
d=[]
for i in range(n):
    d.append([abs(a[i]-k),i])
d.sort()
print(d[0][1])

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
ave=sum(A)/len(A)
dif=abs(A[0]-ave)
idx=0
for i,a in enumerate(A):
    if abs(a-ave)<dif:
        dif=abs(a-ave)
        idx=i
print(idx)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

k = 0
for i in range(n):
    k += a[i]

num = float('inf')
ans = 0
for i in range(n-1, -1, -1):
    if num >= abs(k - a[i] * n):
        num = abs(k - a[i] * n)
        ans = i

print(ans)

Solution (Python):
def solve(N, As):
    avg = sum(As) / N
    return min([(abs(c - avg), i) for i, c in enumerate(As)])[1]

if __name__ == "__main__":
    N = int(input())
    As = [int(c) for c in input().split()]
    print(solve(N, As))

Solution (Python):
N = input()
a = [int(ai) for ai in input().split()]
m = sum(a) / len(a)
index = 0
min_diff = float('inf')
for i, ai in enumerate(a):
    diff = abs(m - ai)
    if diff < min_diff:
        index = i
        min_diff = diff
print(index)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

ans = 0

ave = sum(A)/N

min1 = float(max(A))
for i in range(N):
    diff = abs(float(A[i]) - ave)

    if min1 > diff:
        ans = i
        min1 = diff

print(ans)