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.



Sample input:
3
1 2 3


Sample output:
1

Submission status: Accepted

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

h = sum(a) / len(a)
ans = []

for i, j in enumerate(a):
	ans.append([abs(j - h), i])

print(sorted(ans)[0][1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
m = np.mean(a)
ans = 0
mx = 999999
for i in range(n):
	if abs(a[i] - m) < mx:
		mx = abs(a[i] - m)
		ans = i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int,input().split()))

mean = sum(al) / n

argmin = -1
min_a = float("inf")

for idx, a in enumerate(al):
    if min_a > abs(mean-a):
        argmin = idx
        min_a = abs(mean-a)

print(argmin)

Submission status: Accepted

Solution code:

N = int(input())

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

s = sum(a) / N
m = float("inf")

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

Submission status: Accepted

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

l = list(map(lambda x: abs(x-sum(a)/n) ,a))
print(l.index(min(l)))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
avg = 0
for i in range(N):
	avg+=a[i]
avg=avg/len(a)
min = 100
ans = 0
for i in range(N):
	if min > abs(avg - a[i]):
		ans = i
		min = abs(avg - a[i])
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
l = np.array([int(i) for i in input().split()])

mean = np.mean(l)

l = np.abs(l - mean)

print(np.where(l == l.min())[0][0])

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import combinations_with_replacement

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

ave = sum(li)/n
mi = 10**9
now = 0
for i,j in enumerate(li):
    if abs(j-ave) < mi:
        mi = abs(j-ave)
        now = i
print(now)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    mean = sum(A)/N
    ans = []
    for i in range(N):
        ans.append(abs(A[i]-mean))
    min_ = min(ans)
    for i in range(N):
        if ans[i]==min_:
            print(i)
            exit()
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read

N, *a = map(int, read().split())
ave = sum(a)
a = [abs(i * N - ave) for i in a]

print(a.index(min(a)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# A - Thumbnail

from statistics import mean

N = int(input())
a = list(map(int, input().split()))
a2 = [abs(x - mean(a)) for x in a]

print(a2.index(min(a2)))

Submission status: Accepted

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

ans = 0
abs_value = abs(A[0] - mean)

for i in range(1, N):
    if abs(A[i] - mean) < abs_value:
        ans = i
        abs_value = abs(A[i] - mean)
    
print(ans)

Submission status: Accepted

Solution code:
from fractions import Fraction
N = int(input())
A = list(map(int, input().split()))

avg = Fraction(sum(A), N)

min_val = float('inf')
for a in A:
    val = abs(a - avg)
    min_val = min(min_val, val)

for i, a in enumerate(A):
    val = abs(a - avg)
    if val == min_val:
        print(i)
        exit(0)

Submission status: Accepted

Solution code:
N=int(input())
a = list(map(int, input().split()))
me=sum(a)/len(a)
mini=1000
ans=0
for i in range(N):
    if abs(a[i]-me)<mini:
        mini=abs(a[i]-me)
        ans=i
print(ans)

Submission status: Accepted

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

avg = sum(a)/len(a)
dist = []
for i in range(N):
    dist.append(abs(a[i]-avg))

print(dist.index(min(dist)))

Submission status: Accepted

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

ave=sum(a)/len(a)
a=list(map(lambda x:abs(x-ave), a))
min=sorted(a)[0]
print(a.index(min))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
avg = sum(a) / n
dis = max(a)
index = 0
for i in range(n):
    tmp = abs(a[i] - avg)
    if tmp < dis:
        index = i
        dis = tmp
print(index)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    m = sum(a)/n
    f = {}
    for i in range(n):
        if not a[i] in f:
            f[a[i]] = i
    a = list(set(a))
    a.sort()
    i = bisect.bisect_left(a,m)-1
    if abs(m-a[i]) < abs(a[i+1]-m):
        print(f[a[i]])
    elif abs(m-a[i]) == abs(a[i+1]-m):
        print(min(f[a[i]],f[a[i+1]]))
    else:
        print(f[a[i+1]])
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
ave=sum(A)/N
ABS=abs(A[0]-ave)
ans=0
for i,a in enumerate(A):
    if ABS>abs(ave-a):
        ABS=abs(ave-a)
        ans=i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
avg = 0
for a in A:
    avg += a
avg = avg / N
target = 1000
for a in A:
    dif1 = abs(target-avg)
    dif2 = abs(a-avg)
    if dif2 < dif1:
        target = a
ans = 0
for i,a in enumerate(A):
    if a == target:
        ans = i
        break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ave = sum(A)/N
ans = 0
sa = 10**9
for i in range(N):
    x = max(A[i]-ave,ave-A[i])
    if x < sa:
        sa = x
        ans = i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
mid = sum(A)/N
diff = []
for i in range(N):
    diff.append(abs(mid-A[i]))
print(diff.index(min(diff)))

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
heikin=sum(A)/N
kouho = []

if heikin in A:
    print(A.index(heikin))
else:
    for i in A:
        kouho.append(abs(heikin-i))
    ans = kouho.copy()
    ans.sort()
    print(kouho.index(ans[0]))

Submission status: Accepted

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

mean = sum(A)/N
ans = 0

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

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()
import fractions
#gcd=fractions.gcd
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a
class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo
show_flg=False
show_flg=True
def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

ans=0

n=I()
a=LI()

av=sum(a)/n
m=min([abs(i-av) for i in a])
for i in range(n):
    if m==abs(a[i]-av):
        print(i)
        exit()

#print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    a = sum(A) / len(A)
    f, m = 0, abs(A[0] - a)
    for i, j in enumerate(A[1:], 1):
        t = abs(j - a)
        if t < m:
            f, m = i, t
    print(f)

main()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
mean=sum(A)/N
S=[abs(a-mean) for a in A]
Smin=min(S)
print(S.index(Smin))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]

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

ans = 0
tmp = 10000
for i in range(n):
    if abs(a[i] - average) < abs(tmp - average):
        tmp = a[i]
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    m = sum(A)/N
    ans = []
    for i, a in enumerate(A):
        ans.append((i, abs(a-m)))
    ans.sort(key=lambda x: x[1])
    print(ans[0][0])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ave = sum(a) / n
ans_i = 0
ans_v = float("inf")
for i in range(n):
    if abs(ans_v - ave) > abs(a[i] - ave):
        ans_i = i
        ans_v = a[i]

print(ans_i)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())

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

x = np.array(l)

avg = x.mean()

min = np.argmin(np.abs(x - avg))

print(min)

Submission status: Accepted

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

d = float('inf')
ans = 0
for i in range(N):
    if d > abs(A[i] - avg):
        d = abs(A[i] - avg)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    ave = sum(a)/N
    ls = [abs(ave - i) for i in a]
    print(ls.index(min(ls)))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
*a, = map(int, input().split())

ave = sum(a)/n

ans = []
for i, _a in enumerate(a):
    ans.append([abs(ave-_a), i])

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ave=sum(a)/n
ans=0
mini=float('inf')
for x,i in enumerate(a):
    if abs(i-ave)<mini:
        mini=abs(i-ave)
        ans=x
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split(" ")))
ave = sum(a)/n
dist = [2**50 for i in range(n)]
for i in range(n):
  dist[i] = abs(ave-a[i])
key = dist.index(min(dist))
print(key)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=sum(a)/n
l=[0]*n
for i in range(n):
    l[i]=abs(m-a[i])
x=min(l)
for i in range(n):
    if l[i]==x:
        print(i)
        break

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int, input().split()))

ave = sum(ls) / n
mn = 101
ans = -1

for i in range(n):
    sa = abs(ls[i] - ave)
    if sa < mn:
        mn = sa
        ans = i

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_li = list(map(int, input().split(" ")))
dif = 1000
ave = sum(a_li) / n
for i in range(n):
    if dif > abs(a_li[i] -ave):
        dif = abs(a_li[i] -ave)
        ans = i    
print(ans)

Submission status: Accepted

Solution code:

N = int(input())

a_str = input()
a_list = [int(j) for j in a_str.split(' ')]

average = sum(a_list)/len(a_list)

fark_min = abs(a_list[0] - average)
save_list = []
for i in range(len(a_list)):
    fark = abs(a_list[i]-average)
    if fark <= fark_min:
        fark_min = fark

for i in range(len(a_list)):
    fark = abs(a_list[i] - average)
    if fark == fark_min:
        save_list.append(i)

print(min(save_list))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
K=sum(A)/n
ans=(inf,0)
for i ,ai in enumerate(A):
    if ans[0]>abs(K-ai):
        ans=(abs(K-ai),i)
print(ans[1])

Submission status: Accepted

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

mean = sum(a) / n
dif = float("inf")
ind = -1
for i in range(n):
	if abs(mean - a[i]) < dif:
		dif = abs(mean - a[i])
		ind = i
print(ind)

Submission status: Accepted

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

mean = sum(a) / n
dif = float("inf")
ind = -1
for i in range(n):
	if abs(mean - a[i]) < dif:
		dif = abs(mean - a[i])
		ind = i
print(ind)

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())

ave = 0
for i in range(len(A)):
    ave = ave + A[i]
ave = ave / N

min = float("inf")
for i in range(len(A)):
    temp = abs(A[i]-ave)

    if min> temp:
        min = temp
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
A=np.array([int(i) for i in input().split()])
B=np.abs(A-np.mean(A))
print(np.argmin(B))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

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

sm = sum(a)
best_dif = 100*100
for i in range(N):
    dif = abs(a[i]*N - sm)
    if dif < best_dif:
        best_dif = dif
        ans = i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a_list = list(map(int, input().split()))

ave_a = sum(a_list) / N
flame_i = 0
dif_a = abs(a_list[0] - ave_a)

for i in range(1, N):
  if dif_a > abs(a_list[i] - ave_a):
    dif_a = abs(a_list[i] - ave_a)
    flame_i = i

print(flame_i)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ave=0
for i in range(n):
    ave+=a[i]
ave/=n
if ave in a:
    ans=a.index(ave)
    print(ans)
else:
    min=101
    for i in range(n):
        gap=abs(ave-a[i])
        if min>gap:
            min=gap
            num=a[i]
    print(a.index(num))

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))

ave=sum(l)/n

for i in range(n):
	l[i]=abs(l[i]-ave)

#print(l)

print(l.index(min(l)))

Submission status: Accepted

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

import numpy as np

def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

avg=sum(a)/N

print(getNearestValue(a,avg))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
avg = sum(A) / len(A)
l = []
for i in range(N):
  l.append(abs(A[i]-avg))
c = min(l)
print(l.index(c))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
avg = sum(a)/n
difmin = 10**18
for i in range(n):
  if difmin>abs(a[i]-avg):
    difmin = abs(a[i]-avg)
    ans = i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
aveA = sum(A)/N
dif = float('inf')
ans = None
for i,a in enumerate(A):
  if dif > abs(a-aveA):
    dif = abs(a-aveA)
    ans = i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
sum = sum(a)
min = 10000000
ans = 0
for i in range(n):
    if abs(sum - (a[i] * n)) < min:
        min = abs(sum - (a[i] * n))
        ans = i
print(ans)

Submission status: Accepted

Solution code:

n = int(input())
a = list(map(int,input().split()))
b = []
avg = sum(a)/len(a)

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

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
nn = list(range(n))
ann = [a,nn]
h = sum(a) / len(a)
idx = np.abs(np.asarray(a) - h).argmin()
print(idx)

Submission status: Accepted

Solution code:
def examA():
    N = I(); A = LI()
    sumnale = sum(A)/N
    cur = 10**9; curL = 0
    for i in range(N):
        if cur>abs(A[i]-sumnale):
            cur = abs(A[i]-sumnale)
            curL = i
    ans = curL
    print(ans)
    return


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
M = sum(A) / N
std = float("inf")
ans = 0
for i in range(N):
  if abs(M - A[i]) < std:
    std = abs(M - A[i])
    ans = i
print(ans)

Submission status: Accepted

Solution code:
n= int(input())
a= list(map(int,input().split()))
m=sum(a)/n
for i in range(n):
    a[i]=abs(a[i]-m)
for i in range(n):
    if a[i]==min(a):
        print(i)
        break

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ave=sum(a)/n
x=0
m=10**9
for i in range(n):
    if abs(ave-a[i])<m:
        m=abs(ave-a[i])
        x=i
print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
a = sum(A)/N
ind = -1
dmin = 10**4
for i in range(N):
    if abs(a-A[i])<dmin:
        dmin = abs(a-A[i])
        ind = i
print(ind)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

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

avg = sum(a) / N
mk, mv = 0, float('inf')
for i in range(N) :
    if abs(a[i]-avg) < mv :
        mk, mv = i, abs(a[i]-avg)
print(mk)

Submission status: Accepted

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

b = []
s = (sum(a)/len(a))
for i in range(len(a)):
    b.append(abs(a[i]-s))

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
ave = sum(a) / n

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

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split());print(sorted((abs(a[i]-sum(a)/n),i)for i in range(n))[0][1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, a: "List[int]"):
    sv = sum(a)/N
    p = 0
    s = INF
    for i in range(N):
        if abs(sv - a[i]) < s:
            p = i
            s = abs(sv - a[i])
        
    print(p)
    
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

print([abs(ai-sum(a)/N) for ai in a].index(min([abs(ai-sum(a)/N) for ai in a])))

Submission status: Accepted

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

S = sum(A)
d = 10**14
for i, a in enumerate(A):
  if abs(a*n-S) < d:
    d = abs(a*n-S)
    ind = i
    
print(ind)

Submission status: Accepted

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

ans = 0
amin = 10**10
for i in range(n):
    if abs(a[i] -sum(a)/n) < amin:
        amin = abs(a[i] -sum(a)/n)
        ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
alist = np.array(list(map(int, input().split())))
mean = sum(alist) / N
alist = np.abs(alist - mean)
print(np.argmin(alist))

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

A = np.array(A, dtype=float)
A -= A.mean()
A = np.abs(A)
ans = A.argmin()

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ave=sum(a)/len(a)
minv=sum(a)
mini=0
for i in range(len(a)):
  if abs(a[i]-ave)<minv:
    minv=abs(a[i]-ave)
    mini=i
print(mini)

Submission status: Accepted

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

avg = sum(A) / N

diff = [[abs(val - avg), itr] for itr, val in enumerate(A)]

sdiff = sorted(diff, key=lambda x: (x[0],x[1]))

print(sdiff[0][1])

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
m = sum(A)
l = [ abs(i*n-m) for i in A ]
q = min(l)
for i in range(n):
  if l[i] == q:
    print(i)
    break

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))

check = sum(li) / len(li)
ans = -1
temp = 10**10

for i in range(n):
    s = abs(check - li[i])
    if s < temp:
        temp = s
        ans = i
        
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1,n):
    if abs(a[i]-b)<abs(a[ans]-b):
        ans = i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = sum(a) / n
mn = 10000
for i, j in enumerate(a):
    if mn > abs(s - j):
        mn = abs(s - j)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ave=sum(a)/n
count=1000000000
ans=0
for j in range(len(a)):
    if abs(a[j]-ave)<count:
        count=abs(a[j]-ave)
        ans=j
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
avg = sum(A) / N
ans = 0
for i, a in enumerate(A):
    if abs(A[ans] - avg) > abs(a - avg):
        ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
sum=0
for i in range(N):
  sum+=A[i]
sum
ans=0
for i in range(N):
  A[i]=abs(A[i]*N-sum)
  if(A[i]<A[ans]):
    ans=i
print(ans)

Submission status: Accepted

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

m = sum(A)/n
ans = 0
cnt = m
for i in range(n):
    if abs(A[i]-m) < cnt:
        ans = i
        cnt = abs(A[i]-m)
print(ans)

Submission status: Accepted

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

tmp=sum(a)/n
cnt=100000 -tmp
ans=0
for i in range(len(a)):
    if cnt>abs(tmp-a[i]):
        ans=i
        cnt=abs(tmp-a[i])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
List = list(map(int,input().split()))
mean = sum(List)/N
diff = [abs(i -mean) for i in List]

for i,item in enumerate(diff):
  if item == min(diff):
    Answer = i
    break
print(Answer)

Submission status: Accepted

Solution code:
import sys


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ls = [10 ** 10] * n
    t = 0
    for i in range(n):
        t += a[i]
    t /= n
    mt = 10 ** 10
    for i in range(n):
        ls[i] = abs(a[i] - t)
        mt = min(mt, ls[i])
    for i in range(n):
        if ls[i] == mt:
            print(i)
            exit()


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    ave = sum(aa) / n
    mn = 1000
    mi = 0
    for i, a in enumerate(aa):
        if abs(ave - a) < mn:
            mn = abs(ave - a)
            mi = i
    print(mi)

main()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
av = sum(a) / N
tmp = 101
index = 0
for i in range(N):
    if tmp > abs(a[i] - av):
        tmp = abs(a[i] - av)
        index = i

print(index)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    ave = sum(a) / n
    diffs = sorted([(abs(ai - ave), i) for i, ai in enumerate(a)])[0][1]
    print(diffs)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

dif = 100
mean_a = sum(a)/len(a)
for i in range(len(a)):
  if abs(a[i]-mean_a) < dif:
    ans = i
    dif = abs(a[i]-mean_a)

print(ans)

Submission status: Accepted

Solution code:
# 2019/10/15

import numpy as np

n=int(input())
a=np.array(list(map(int,input().split())))
avg=np.mean(a)

ans=abs(a-avg)
min_a=10**9
idx=-1
for i,e in enumerate(ans):
    if min_a>e:
        min_a=e
        idx=i
print(idx)

Submission status: Accepted

Solution code:
n=int(input())
a = list(map(int,input().split()))	
h=sum(a)/n
value=sum(a)
index=0
for i in range(n):
    if value > abs(a[i] - h):
        value = abs(a[i] - h)
        index = i
print(index)

Submission status: Accepted

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

# 平均を出す
mean = sum(a)/n

# 差分を求める
a = [abs(i-mean) for i in a]

temp = 101
ans = -1

for i in range(n):
    if temp > a[i]:
        temp = a[i]
        ans = i

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
mean_a = sum(A)/N
ans = 0
ans_dist = float('inf')
for ind,a in enumerate(A):
    if(abs(mean_a-a)<ans_dist):
        ans_dist = abs(mean_a-a)
        ans = ind
print(ans)

Submission status: Accepted

Solution code:
#%%
n = int(input())
a = list(map(int,input().split()))

s = sum(a) / len(a)

ans = 0
tmp = 10**9

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

print(ans)


#%%

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mean = sum(a) / n
a = [abs(i - mean) for i in a]
print(a.index(min(a)))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ave = sum(A) / len(A)
diff = float('inf')
ans = None
for i, a in enumerate(A):
    if abs(a - ave) < diff:
        diff = abs(a - ave)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
m = sum(A)
ans = 0
for i in range(N):
  if abs(A[i]*N - m) < abs(A[ans]*N - m):
    ans = i    
print(ans)