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):
def solve(n, a):
    b = sum(a) / n
    ans = 0
    best = abs(a[0] - b)
    for i in range(n):
        c = abs(a[i] - b)
        if c < best:
            ans, best = i, c
    return ans

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Solution (Python):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
x = np.abs(a - a.mean())
print(np.argmin(x))

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ave = sum(a)/N
min = idx = 10**9
for i in range(N):
    if abs(ave-a[i])<min:
        min = abs(ave-a[i])
        idx = i
print(idx)

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

ave = sum(a) / N
check = []

for i in range(N):
    check.append([abs(ave - a[i]), i])

check.sort()
print(check[0][1])

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

avg = sum(a) / len(a)
diff = list(map(lambda x : abs(x - avg), a))
min_diff = min(diff)
for i in range(n):
    if abs(a[i] - avg) == min_diff:
        print(i)
        break

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

ave = sum(a)
for i in range(n):
    a[i] = a[i] * n

diff = float("inf")
for i in range(n):
    if abs(a[i] - ave) < diff:
        ans = i
        diff = abs(a[i] - ave)
print(ans)

Solution (Python):
N = int(input())
nums = list(map(int,input().split(" ")))
avr = sum(nums)/N
diff = 10 ** 9
ans = 0
for i,num in enumerate(nums):
  if diff > abs(avr - num):
    ans = i
    diff = abs(avr - num)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

S = sum(A)
best_diff = 10**18
best_i = -1
for i,x in enumerate(A):
    d = abs(x*N-S)
    if d < best_diff:
        best_diff = d
        best_i = i

print(best_i)

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

mean = sum(flame_list)/n

flame_list_2 = [ abs(mean - i) for i in flame_list ]


print(flame_list_2.index(min(flame_list_2)))

Solution (Python):
from statistics import mean

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

avg = mean(a)

tmp = []
result = []
for x in a:
    tmp.append(abs(x - avg))
    
tmp_min = min(tmp)
for i in range(len(tmp)):
    if tmp[i] == tmp_min:
        print(i)
        break

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

av = sum(a) / N
mi = 101
c = 0
for i in range(N - 1, -1, -1):
    if abs(a[i] - av) <= mi:
        mi = abs(a[i] - av)
        idx = i
print(idx)

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

aveA = sum(vA) / N
vD = [abs(a - aveA) for a in vA]

res = vD.index(min(vD))
print(res)

Solution (Python):
n=int(input())
A=tuple(map(int,input().split()))
ave=sum(A)/n
d=float('inf')
for i,a in enumerate(A):
    if abs(a-ave)<d:
        d=abs(a-ave)
        ans=i
print(ans)

Solution (Python):

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    avg = sum(A) / N
    D = {(abs(avg - a), i) for i, a in enumerate(A)}
    print(min(D)[1])


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    avg = sum(A) / N
    D = [(abs(avg - a), i) for i, a in enumerate(A)]
    print(min(D)[1])


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    avg = sum(A) / N
    D = sorted((abs(avg - a), i) for i, a in enumerate(A))
    print(D[0][1])


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
P = list(map(int,input().split()))
sum = 0
ave = 0
ave_first = 99999
k = []


for i in range(N):
    sum += P[i]
ave = sum/N

for i in range(0,N-1):
    if abs(P[i]-ave)< ave_first:
            ave_first = abs(P[i]-ave)
            k.clear()
            k.append(i)
    elif abs(P[i]-ave) == ave_first:
        k.append(i)
print(min(k))

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

avg = sum(A) / N

ans = -1
ms = 100
for i, a in enumerate(A):
    if abs(a - avg) < ms:
        ms = abs(a - avg)
        ans = i
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
avg=sum(A)/N
l=200
ans=0
for i in range(N):
  if abs(avg-float(A[i]))<l:
    l=abs(avg-float(A[i]))
    ans=i
print(ans)

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

sum = 0


for i in range(n):
  sum += framelist[i]

avg = sum /n

min = avg
value = 0

for i in range(n):
  difference = abs(framelist[i]-avg)
  if min>difference:
    min = difference
    value = framelist[i]
    
print(framelist.index(value))

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
sum=0
for i in a:
        sum+=i
sum/=N
mini=100000000
k=0
for i in a:
        if mini>abs(i-sum):
                mini=abs(i-sum)
                ans=k
        k+=1
print(ans)

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

Solution (Python):
n=int(input())
al=list(map(int,input().split()))
t=sum(al)/n
ta=100
for i in range(n):
    if abs(t-al[i])<ta:
        ta=abs(t-al[i])
        ans=i
print(ans)

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

li = list(map(int,input().split()))
av = sum(li) / n


ans = 0
tp = abs(li[ans] - av)
for i in range(1,n):
    if(abs(li[i] - av) < tp):
        tp = abs(li[i] - av)
        ans = i

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ah = sum(a)/n
al = [abs(a[i]-ah) for i in range(n)]
print(al.index(min(al)))

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

Ave = sum(A)/len(A)
abs_distance = list()

for i in range(N):
    abs_distance.append(abs(A[i]-Ave))

print(abs_distance.index(min(abs_distance)))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mean = sum(A) / N
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())
l=list(map(int,input().split()))
ave=sum(l)/n
ans=None
c=100000 
for i in range(n):
  if abs(ave-l[i])<c:
    ans=i;c=abs(ave-l[i])
print(ans)

Solution (Python):
n = int(input())
a = [int(item) for item in input().split()]
ave = sum(a) / n

diff = []
for i, item in enumerate(a):
    diff.append([abs(item - ave), i])
diff.sort()
print(diff[0][1])

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

avg=sum(alist)/N
min_index=-1
min_diff=1000
for i in range(N):
  diff=abs(avg-alist[i])
  if diff<min_diff:
    min_diff=diff
    min_index=i
    
print(min_index)

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

avg = sum(A) / N
diff = [(abs(A[i] - avg), i) for i in range(N)]
diff.sort()

print(diff[0][1])

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

ave=(sum(a)/N)

ave_a=[abs(i-ave) for i in a]

ans=101
thum=101
for i in range(N):
    if ave_a[i]<thum:
        thum=ave_a[i]
        ans=i

print(ans)

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]
mean=sum(A)/n
ans=-1
dif=float("inf")
for i in range(n):
  if abs(A[i]-mean)<dif:
    dif=abs(A[i]-mean)
    ans=i
print(ans)

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

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

ave=sum(a)/N

mini=1000
argmin=-1
for i in range(N):
  if abs(ave-a[i])<mini:
    mini=abs(ave-a[i])
    argmin=i
    
print(argmin)

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

Solution (Python):
N = int(input())
*A, = map(int, input().split())
mean = sum(A)/N
_, i = min([(abs(a - mean), i) for i, a in enumerate(A)])
print(i)

Solution (Python):
import numpy as np

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

avg = np.average(a)

def delta(tsumugi):
  return tsumugi - avg

a_delta = list(map(delta, a))
a_abs = list(np.abs(a_delta))
num_min = np.min(a_abs)
index = a_abs.index(num_min)

print(index)

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())
L=list(map(int,input().split()))
mid=sum(L)/len(L)
LL=[abs(i-mid) for i in L]
print(LL.index(min(LL)))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
ave = sum(a)/len(a)
min_diff = max(a)
for i in range(n):
    diff = abs(a[i]-ave)
    if diff < min_diff:
        min_diff = diff
        ans = i
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
sums = sum(A)
sml = [abs(N*A[i]-sums) for i in range(N)]

tmp = 100
result = 0
for i, n in enumerate(sml):
    if tmp > n:
        result = i
        tmp = n

print(result)

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

s = sum(A)

answer = 0
min_dist = 10**10
for i,a in enumerate(A):
  d = abs(N*a-s)
  if min_dist > d:
    min_dist = d
    answer = i

print(answer)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
aa=[]
avea = sum(a)/n
for i in range(n):
    aa.append(abs(avea-a[i]))
print(aa.index(min(aa)))

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
average = sum(a) / n
for i in range(n):
    a[i] -= average
    a[i] = abs(a[i])
check = min(a)
ans = a.index(check)
print(ans)

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

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

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())


N = int(input())
As = list(mi())
avg = sum(As) / N

minno = -1
min = 1000
for i, a in enumerate(As):
  if abs(a-avg) < min:
    min = abs(a-avg)
    minno = i

print(minno)

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

avr = sum(a_lst) / N

ans = 0
x = -1
for i in range(N):
    if x == -1 or x > abs(a_lst[i] - avr):
        x = abs(a_lst[i] - avr)
        ans = i

print(ans)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ave=sum(a)/n
b=[]
for i in range(n):
        b.append((a[i],abs(a[i]-ave),i))
b=sorted(b,key=lambda x:(x[1],x[2]))
print(b[0][2])

Solution (Python):
n = int(input())
a = list(int(i) for i in input().split())
avg = sum(a) / n
ansa = 999
ansn = 0
for x in range(n):
  if ansa > abs(avg - a[x]):
    ansa = abs(avg - a[x])
    ansn = x
print(ansn)

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

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

ans = 10**12
Ans = None
for i, a in enumerate(A):
    if abs(S - N*a) < ans:
        ans = abs(S - N*a)
        Ans = i
print(Ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ave = sum(A)/N
ans = 0
dist = 1000
for i, a in enumerate(A):
	if abs(a - ave) < dist:
		ans = i
		dist = abs(a - ave)
	if dist < 0.5:
		break
print(ans)

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

ave_a = sum(a) / n
dist = 1000007
flamenum = 0

for i in range(n):
    if abs(a[i] - ave_a) < dist:
        dist = abs(a[i] - ave_a)
        flamenum = i
        

print(flamenum)

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

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

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

tmp1 = 10000
tmp2 = 0

for i in range(len(a)):
  if abs(a[i]-mean) < tmp1 :
    tmp1 = abs(a[i]-mean) 
    tmp2 = i
    

print(tmp2)

Solution (Python):
N = int(input())
a_s = [int(x) for x in input().split()]

mean = sum(a_s) * 1.0 / N
d = min(map(lambda a: abs(a - mean), a_s))
ans = N
for i in range(N):
    if abs(a_s[i] - mean) == d:
        ans = i
        break

print(ans)

Solution (Python):
if __name__=="__main__":
    n = int(input())
    a = [int(i) for i in input().split(' ')]
    ave = 0.0
    for i in a:
        ave += i
    ave /= n
    ans = 0
    for id, i in zip(range(n), a):
        if abs(a[ans] - ave) > abs(i - ave):
            ans = id
    print(ans)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
ave = sum(A)/n 
diff = []  
for a in A:
	diff.append(abs(a-ave))
tmp = 0   
d = 10**9
for i in range(n):
	if diff[i] < d:
		d = diff[i]
		tmp = i
print(tmp)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
m=sum([e/len(a)for e in a])
s=[abs(e-m) for e in a]
print(s.index(min(s)))

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
avg=sum(arr)/n
pos=0
diff=10**9
for i in range(n):
  if abs(arr[i]-avg)<diff:
    diff=abs(arr[i]-avg)
    pos=i
print(pos)

Solution (Python):
import numpy as np
n = int(input())
a = list(map(int, input().split()))
m = np.mean(a)
ans = 0
dist = abs(a[0] - m)

for i in range(n):
    if abs(a[i] - m) < dist:
        dist = abs(a[i] - m)
        ans = i

print(ans)

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

Solution (Python):
from numpy import*;_,a=open(0);a=int32(a.split());print(argmin(abs(a-mean(a))))

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
avg = sum(a) / len(a)
a = [abs(i - avg) for i in a]
print(a.index(min(a)))

Solution (Python):
from statistics import mean

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

A = list(map(lambda i: abs(i - mean(A)), A))

print(A.index(min(A)))

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

ave = sum(a)/N
ans = 0
dif = 1e+3
for i in range(N):
    if abs(a[i] - ave) < dif:
        ans = i
        dif = abs(a[i] - ave)

print( ans )

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

Solution (Python):
n = int(input())
m = list(map(int, input().split()))
avg = sum(m) / n
print(min([(abs(e - avg), i) for i, e in enumerate(m)])[1])

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

Solution (Python):


def main():
    N = int(input())
    a = list(map(int, input().split()))
    ave_a = sum(a)/len(a)

    best_diff = abs(a[0] - ave_a)
    best_i = 0
    for i, aa in enumerate(a):
        diff = abs(ave_a - aa)
        if diff < best_diff:
            best_i = i
            best_diff = diff

    print(best_i)

main()

Solution (Python):
import numpy as np
n=int(input())
a = list(map(int, input().split()))
num = sum(a)/n
idx = np.abs(np.asarray(a) - num).argmin()
print(idx)

Solution (Python):
N = int(input())
a = [int(_) for _ in input().split()]
ave = sum(a)/N
Min = sum(a)
res = 0

for i in range(N):
    if abs(ave - a[i]) < Min:
        Min = abs(ave - a[i])
        res = i

print(res)

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
a=sum(l)/len(l)
for i in range(n):
    l[i]=abs(l[i]-a)
print(l.index(min(l)))

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

Solution (Python):
from sys import stdin
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
from statistics import mean
data_mean=mean(data)
def calc_(n):
    return abs(n-data_mean)
 
data2 = list(map(calc_, data))
data3=list(data2)
result=data3.index(min(data3))
print(result)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m = sum(a)/n
d = 100
c = 0
for i in range(n):
  a[i] = abs(a[i] - m)
  if a[i] < d:
    d = a[i]
    c = i
print(c)

Solution (Python):
from numpy import*;input();*a,=map(int,input().split());print(argmin(abs(a-mean(a))))

Solution (Python):
from numpy import*;n,*a=map(int,open(0).read().split());print(argmin(abs(a-mean(a))))

Solution (Python):
from numpy import*;n,*a=map(int,open(0).read().split());print(argmin(abs(a-sum(a)/n)))

Solution (Python):
n,*a=map(int,open(0).read().split());b=[abs(i-sum(a)/n)for i in a];print(b.index(min(b)))

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
ave=sum(a)/len(a)
A=[(abs(a[i]-ave),i) for i in range(n)]
A.sort()
print(A[0][1])

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int,input().split()))
ave = sum(num) / n
dis = [abs(num[i]-ave) for i in range(n)]
print(dis.index(min(dis)))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
m = 10 ** 10
mi = 0
for i, e in enumerate(a):
    if abs(e*n - s) < m:
        m = abs(e*n - s)
        mi = i
print(mi)

Solution (Python):
from statistics import mean

frame_num = int(input())
frame_value = list(map(int, input().split()))
avg = mean(frame_value)
min_frame = max(frame_value)
thumbanil = 0
for frame, value in enumerate(frame_value):
    diff = abs(avg - value)
    
    if diff < min_frame:
        min_frame = diff
        thumbanil = frame

print(thumbanil)

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

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

average=sum(a)/N


b=list(map(lambda x:abs(x-average),a))
print(b.index(min(b)))

Solution (Python):
n = int(input())
a = list(int(i) for i in input().split())
average = sum(a)
query =[]
for i in a:
 query.append(abs(n*i-average))
print(query.index(min(query)))

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

sum = sum(a)
avg = sum/N

result = 0
tmp = 0

for i in range(len(a)):
  ans = avg - a[i]
  ans = ans if ans > 0 else ans * -1
  if i == 0:
    result = i
    tmp = ans
  elif tmp > ans:
    result = i
    tmp = ans

print(result)

Solution (Python):


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
aN = LIST()
avg = sum(aN) / len(aN)
aN2 = [[0] * 2 for i in range(N)]
for i in range(N):
    aN2[i][0] = i
    aN2[i][1] = abs(aN[i] - avg)

aN2.sort(key=itemgetter(1))
print(aN2[0][0])

Solution (Python):
a = int(input())
ar = list(map(int,input().split(" ")))
b = sum(ar) / a
s = abs(ar[0] - b)
ans = 0
for i in range(1,a):
    if s > abs(b - ar[i]):
        s = abs(b - ar[i])
        ans = i
print(ans)

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

print(ans)

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

mean = sum(a)/len(a)

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

Solution (Python):
N = int(input())
at = input().split(" ")
a = []
for i in at:
    a.append(int(i))
avg = sum(a) / N
mdif, flag = abs(a[0]-avg), 0
for i in range(len(a)):
    if abs(a[i]-avg) < mdif:
        mdif = abs(a[i]-avg)
        flag = i
print(flag)

Solution (Python):
N = int(input())
a_list = list(map(int,input().split()))
ave = sum(a_list)/N
abs_list = [abs(i - ave) for i in a_list]
print(abs_list.index(min(abs_list)))

Solution (Python):
import statistics as st
N = int(input())
a = [int(x) for x in input().split()]
m = st.mean(a)


nbr = abs(a[0]-m)
idx = 0
for i in range(1,N):
    if abs(a[i]-m)<nbr:
        nbr = abs(a[i]-m)
        idx = i
print(idx)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ave = sum(x)/len(x)
MIN = abs(x[0]-ave)
MIN_index = 0
for i,j in enumerate(x):
  if abs(j-ave) < MIN:
    MIN_index = i
    MIN = abs(j-ave)
print(MIN_index)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
average = sum(a)/N
minv = 101
minframe = 0
for i in range(N):
    diff = abs(a[i] - average)
    if diff < minv:
        minv = diff
        minframe = i

print(minframe)

Solution (Python):
import numpy as np

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

avg = np.sum(a) / len(a)

x = np.abs(a - avg)

print(np.argmin(x))

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

d = q
e = 1000
for i in range(n-1,-1,-1):
    if d >= abs(q-a[i]):
        d = abs(q-a[i])
        e = i
print(e)

Solution (Python):
import numpy as np
N=int(input())


frames=list(map(int, input().split(" ")))
ave=sum(frames)/N

ans=np.abs(np.asarray(frames)-ave).argmin()
print(ans)

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

print(ans)

Solution (Python):
from functools import reduce

def main():
    n = int(input())
    thumbnails = []
    thumbnails = list(map(lambda x: (x[0], int(x[1])), enumerate(input().split(' '))))

    thumbnails.sort(key=lambda t: t[1])

    average = reduce(lambda x, y: x + y[1], thumbnails, 0) / n

    min_diff = 100
    t_options = []

    for i, t in thumbnails:
        diff = abs(average - t)
        if min_diff > diff:
            t_options = [i]
            min_diff = diff
        elif min_diff == diff:
            t_options.append(i)
    print(min(t_options))


if __name__ == "__main__":
    main()

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

a = input()
a = a.split(" ")

a = [int(i) for i in a]

ave = sum(a) / N

sa = float("inf")

for i in range(N):
  if sa > abs(a[i] - ave):
    sa = abs(a[i] -ave)
    index = i
print(index)

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

ret = -1
dist = 10000000

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

print(ret)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
mean = sum(L)/N
q = 10**9+7
ans = -1
for i in range(N) :
    di = abs(mean - L[i])
    if di < q :
        q = di
        ans = i
print(ans)

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




import statistics


m = statistics.mean(a)

list = []
for i in a:
    list.append(abs(i - m))


print(list.index(min(list)))

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

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

Solution (Python):
n = int(raw_input())
arr = map(int,raw_input().split())
ave = sum(arr)*1.0/n
arr_d = []
min = 100
min_i = -1
for i in range(n):
    if abs(ave-arr[i])<min:
        min=abs(ave-arr[i])
        min_i = i
print min_i

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

ave = sum(a) / N

aa =[abs(a[i] - ave) for i in range(N)]

x = min(aa)

print(aa.index(x))

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

mean = sum(A) / N
index, value = float('inf'), float('inf')
for i, a in enumerate(A):
  x = abs(a - mean)
  if x <= value and x != value:
    value, index = x, i

print(index)

Solution (Python):


import numpy as np

def calc():
    _ = input()
    a = np.array([int(s) for s in input().split(" ")])
    ave = np.average(a)
    absolute = np.absolute(a - ave)

    return np.argmin(absolute)

if __name__ == '__main__':
    print(calc())

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
avarage = sum(a) / len(a) 
index = float("inf")
value = float("inf")

for i in range(len(a)):
    if abs(a[i] - avarage) <= value and value != abs(a[i] - avarage):
        value = abs(a[i] - avarage)
        index = i
print(index)

Solution (Python):
N = int(input())
Na = list(map(int, input().split()))
mean = sum(Na)/N
print(min((abs(a-mean),i)  for i, a in enumerate(Na))[1])

Solution (Python):
n = int(input())
input = input()
listA = list(map(int, input.split()))
listB = list(map(int, input.split()))
listB.sort()

index =0
sum=0
while index < len(listB):
    sum+=listB[index]
    index+=1

average = sum/len(listB)
minI =100
delta=1000

index2 =0
while index2 < len(listA):
    if abs(listA[index2]-average) < delta:
        minI = index2
        delta = abs(listA[index2]-average)
    index2+=1

print(minI)

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
ave=sum(L)/len(L)
L2=[abs(x-ave) for x in L]
idx=L2.index(min(L2))
print(idx)

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

aveA = sum(As) / N

ans = 0
minDiff = abs(As[0] - aveA)
for i, A in enumerate(As[1:], 1):
    diff = abs(A - aveA)
    if diff < minDiff:
        ans = i
        minDiff = diff
print(ans)

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

av=sum(A)
ans=N
res=10**10

for i in range(N):
  cnt=A[i]*N
  if abs(av-cnt) < res:
    ans=i
    res=abs(av-cnt)
    
print(ans)

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
t=sum(A)/N
s=0
num=10**9
for i in range(N):
    if num>abs(A[i]-t):
        s=i
        num=abs(A[i]-t)
print(s)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mean = sum(A)/N
print(min((abs(a-mean), i) for i,a in enumerate(A))[1])

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

frames = list(map(int, input().split(" ")))

mean = sum(frames) / N

sa = 100
ind = 0
for i in range(N):
  if sa > abs(frames[i] - mean):
    sa = abs(frames[i] - mean)
    ind = i
    
print(ind)

Solution (Python):
def dw19A():
    N = int(input())
    a = list(map(int, input().split()))
    avea = sum(a) / N
    mina = 1000000000000
    ans = 0
    for i in range(N):
        if mina > abs(a[i] - avea):
            ans = i
            mina = abs(a[i] - avea)
    print(ans)
dw19A()

Solution (Python):
n = int(raw_input())
a = map(int,raw_input().split())
b = float(sum(a))/n
c = []
for i in range(n):
  x = abs(a[i]-b)
  c.append(x)
d = min(c)
print c.index(d)

Solution (Python):
n = int(input())
aaa = list(map(int, input().split()))
ave = sum(aaa) / n
bbb = [(abs(a - ave), i) for i, a in enumerate(aaa)]
bbb.sort()
print(bbb[0][1])

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

mean = sum(A)/N
ans = 0
p = 10**9 + 7
for i in range(N) :
    q = abs(A[i] - mean)
    if q < p :
        p = q
        ans = i
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
avr = sum(a)/N
d = []
judge = 'n'
for i in range(N):
    x = abs(avr-a[i])
    if x == 0:
        ans = i
        judge = 'z'
        break
    else:
        d.append(x)

if judge == 'z':
    print(ans)
else:
    print(d.index(min(d)))

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

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

a = sorted(A)
ave = sum(a)/n

ans = 0
ans2 = 0
flag = 0
for i in range(n):
    if a[i] == ave:
        ans = a[i]
        break
    elif a[i] > ave:
        if i == 0:
            ans = a[0]
        elif a[i] - ave < ave - a[i-1]:
            ans = a[i]
        elif a[i] - ave == ave - a[i-1]:
            flag = 1
            ans = a[i]
            ans2 = a[i-1]
        else:
            ans = a[i-1]
        break
    else:
        ans = a[i]

if flag == 0:
    print(A.index(ans))
else:
    print(min(A.index(ans), A.index(ans2)))

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

ave = sum(a)/len(a)

a_dist = [abs(x-ave) for x in a]
a_min  = min(a_dist)
print(a_dist.index(a_min))