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:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

#n=3
#a = [1, 4, 3]

import statistics
#import NumPy

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

#print(a)
print(list.index(min(list)))

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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())

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

s = input()
w = input().split()
sum = 0
for i in range(int(s)):
    sum += int(w[i])
average = sum / int(s)
limit = 100
index = 0
for i in range(int(s)):
    if abs(int(w[i]) - average) < limit:
        limit = abs(int(w[i]) - average)
        index = i
print(index)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
med=sum(a)/n#平均の値
gosa=[]
for i in range(n):
    gosa.append(abs(med-a[i]))
ans=min(gosa)
for i in range(n):
    if ans==gosa[i]:
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

NA = sum(A)
mv = float('inf')
mi = -1

for i in xrange(N):
    v = abs(NA - A[i] * N)
    if v < mv:
        mv = v
        mi = i

print mi

Submission status: Accepted

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

av = sum(A) / N

min_dist = 9999
min_idx = 0

for i in range(N):
  if min_dist > abs(A[i] - av):
    min_dist = abs(A[i] - av)
    min_idx = i
    
print(min_idx)

Submission status: Accepted

Solution code:
n=int(input())
s=input().split()
l=[int(s[i]) for i in range(n)]
su=sum(l)
best=10000000000000000
res=0
for i in range(n):
  if(abs(su-n*l[i])<best):
    best=abs(su-n*l[i])
    res=i
print(res)

Submission status: Accepted

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

a = list(map(lambda x: int(abs(N*x-sum(a))), a))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

avg = sum(a)/len(a)

m = 10000000000000
ans = 0
for i , val in enumerate(a):
    if abs(val - avg) < m:
        m = abs(val-avg)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
def a_thumbnail(N, A):
    ave_x_n = sum(A)
    a = [abs(i * N - ave_x_n) for i in A]  # 小数の計算をしたくない
    ans = a.index(min(a))
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(a_thumbnail(N, A))

Submission status: Accepted

Solution code:
# coding: utf-8

N = int(input())
ai = [int(_) for _ in input().split()]

d = sum(ai)
ave = d / N

i = 0
ret = None
for i in range(N):
    a = ai[i]
    if(abs(a - ave) < d):
        d = abs(a - ave)
        ret = i

print(ret)

Submission status: Accepted

Solution code:
import math
n = int(raw_input())
a =  raw_input().split()
a = map(int, a)
ave = float(sum(a))/n
dif = 10000
count  = 0
ans = 0
for x in a:
    s = abs(x-ave)
    if s < dif:
        dif = s
        ans = count
    count += 1
  
print("%d" % ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
Mean = sum(a)/N
a_norm = [a[i] - Mean for i in range(N)]
a_norm_abs = list(map(abs,a_norm))
print(a_norm_abs.index(min(a_norm_abs)))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
M = (sum(A))/N
t = 101
for e in A:
    t = min(t,abs(e-M))

for k in range(N):
    if abs(A[k]-M) == t:
        print(k)
        exit(0)

Submission status: Accepted

Solution code:
N = int(input())
an = [int(i) for i in input().split()]
s  = sum(an)
h = s/N
ans = -1
m = float('inf')
for i in range(N-1,-1,-1):
    t = abs(h-an[i])
    if m >= t:
        m = t
        ans = i
print(ans)

Submission status: Accepted

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

ans,m=0,1e22
for i,j in enumerate(a):
  if abs(j-avg)<m:
    ans=i
    m=abs(j-avg)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
*a, = map(int, input().split())
s = sum(a)/n
ans = -1
mind = 101
for i in range(n):
    t = a[i]
    if abs(t-s) < mind:
        mind = abs(t-s)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

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

S = sum(a)

ans = 0
diff = INF

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

print ans

Submission status: Accepted

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

ttl = sum(a)

ans = 0
for i, aa in enumerate(a):
    if abs(ttl - a[i] * n) < abs(ttl - a[ans] * n):
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

_ = int(input())
a = np.array(list(map(int, input().split())))
idx = np.argmin(np.abs(a - a.mean()))
print(idx)

Submission status: Accepted

Solution code:
n=int(input())
tmp=list(map(int,input().split()))
a=[]
ave=0
for i in range(n):
    ave+=tmp[i]
    a.append([i,tmp[i]])

ave=ave/n
a.sort(key=lambda x:(abs(ave-x[1]),x[0]))
# print(ave,a)
print(a[0][0])

Submission status: Accepted

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

ma = sum(a) / len(a)

def d(i):
    return abs(a[i] - ma)

best = 0
for i in range(len(a)):
    if d(i) < d(best):
        best = i

print(best)

Submission status: Accepted

Solution code:
import numpy as np

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

mean_a = np.mean(a)
ans = []

for i in range(N):
    ans.append(abs(a[i] - mean_a))

print(np.argmin(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(s) for s in input().split()]
avg = sum(a) / len(a)
lengs = [abs(v - avg) for v in a]
minleng = min(lengs)
print(lengs.index(minleng))

Submission status: Accepted

Solution code:
n = int(input());
mylist = list(map(int, input().split()));
sum = 0;
for k in mylist:
	sum += k;
sum /= len(mylist);
maxi = 0;
for i in range(len(mylist)):
	if (abs(mylist[maxi] - sum) > abs(mylist[i] - sum)):
		maxi = i;
print(maxi);

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = list(map(int,input().split()))
median = np.average(a)
idx = np.abs(np.asarray(a) - median).argmin()

ans = 0
for i in range(n):
    if a[i] == a[idx]:
        ans = i
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
num = tuple(map(int,input().split()))
avr = sum(num)/n
pos = 0
d = 9999999999
for i in range(n):
    if abs(avr - num[i]) < d:
        d = abs(avr - num[i])
        pos = i
print(pos)

Submission status: Accepted

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

sum_a = sum(a)
mean_a = sum_a / N

for i in range(N):
    a[i] = abs(a[i] - mean_a)
thum = min(a)

for i in range(N):
    if a[i] == thum:
        print(i)
        break

Submission status: Accepted

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

average = sum(a) / len(a)

min_diff = abs(a[0] - average)
ans = 0
for i, x in enumerate(a):
    if min_diff > abs(x - average):
        min_diff = abs(x - average)
        ans = i

print(ans)

Submission status: Accepted

Solution code:
x = int(input())
a = input().split()
list(map(int, a))
c = 100
d = 100
cange = 0
f = 0
for i in range(x):
  f += int(a[i]) 
  
b = f / x

for i in range(x):
    if abs(b - int(a[i])) < d :
        d = abs(b - int(a[i]))
        e = i
        cange = 1
if cange:
	print(e)
else:
    print(0)

Submission status: Accepted

Solution code:
# vim: set fileencoding=utf-8:
import numpy as np


def main():
    N = input()
    a = np.array([int(ele) for ele in raw_input().split()])
    avg = sum(a) / float(N)
    a = a - np.array([avg] * N)
    a = map(abs, list(a))
    print(a.index(min(a)))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

def minus(m):
    return abs(m-sum(a)/n)

a2 = list(map(minus,a))

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

Submission status: Accepted

Solution code:
N, = [int(x) for x in input().strip().split(" ")]
As = [int(x) for x in input().strip().split(" ")]

ave = float(sum(As))/N
diss = [abs(ave-a) for a in As]
minn = sorted(diss)[0]
for i, x in enumerate(diss):
    if x == minn:
        aaa = i
        break
print(aaa)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = sum(A) / len(A)
D = max(A)
I = 0

for i, a in enumerate(A):
    if D > abs(a - M):
        D = abs(a - M)
        I = i

print(I)

Submission status: Accepted

Solution code:
def main():
    n = input()
    data = input().split()
    data = list(map(lambda x: int(x), data))

    mid_val = calculate_mean(data)

    if int(n) < 1 or 101 < int(n):
        return -1

    current_pos = -1
    current_distance = 101

    if int(n) == len(data):
        for key, value in enumerate(data):
            if int(value) < 1 or 101 < int(value):
                return -1
            new_distance = abs(mid_val - value)
            if current_distance > new_distance:
                current_pos = key
                current_distance = new_distance
        return current_pos


def calculate_mean(data):
    s = sum(data)
    N = len(data)
    mean =s/N

    return mean

r = main()
print(r)

Submission status: Accepted

Solution code:
#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N, = getIntList()
#print(N)
za  = getIntList()
tot = sum(za)
ti = 0
td = 10000000
for i in range(N ):
    x = za[i]
    t = abs(x*N - tot)
    if t<td:
        td = t
        ti = i
print(ti)

Submission status: Accepted

Solution code:
from statistics import mean

N = int(input())
a = [int(i) for i in input().split()]
m = mean(a)
d = 100
r = 0

for i, v in enumerate(a):
    if abs(m - v) < d:
        d = abs(m - v)
        r = i

print(r)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

input = raw_input()
N = int(input)
aVec = raw_input().split(" ")
a = []

for i in aVec:
    a.append(float(i))


#平均を算出
mean = sum(a) / N

#平均に最も近い値を算出(平均を引いたときの最小値を出す)
near_mean = []

for i in a:
    near_mean.append(abs(i - mean))

#平均値に最も近い値のフレーム番号(0始まり)を出力
#同じ値が複数ある場合は最初のインデックスを返す必要があるが、index関数はそういう仕様なので問題ない
print near_mean.index(min(near_mean))

Submission status: Accepted

Solution code:
from sys import stdin

a = []
sum = 0

n = int(stdin.readline().rstrip())
a = [int(y) for y in stdin.readline().rstrip().split()]

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

ave = sum / n
tmp = abs(a[0] - ave)
ans = 0

for i in range(n) :
    if (abs(a[i] - ave) < tmp ) and ( a[ans] is not a[i]):
        ans = i
        tmp = abs(a[i] - ave)
        
print(ans)

Submission status: Accepted

Solution code:
N=input()
A=map(int, raw_input().split())
ave=float ( sum(A) )/len(A)

ans=0
diff=10**9
for idx, x in enumerate(A):
	if diff>abs(x-ave):
		ans=idx
		diff=abs(x-ave)

print ans

Submission status: Accepted

Solution code:
n = int(input())
list = list(map(int,input().split()))
flist = []
avr = sum(list)/n

for i in range(n):
    flist.append(max(list[i], avr) - min(list[i], avr))

d = flist.count(min(flist))

if d == n:
    print("0")
else:
    index = flist.index(min(flist))
    print(index)

Submission status: Accepted

Solution code:
n = int(input())

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

ave = sum(a)/n
diff = [abs(ave - x) for x in a]
#print(diff)

print(diff.index(min(diff)))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = list(map(int, input().split()))

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

idx = np.abs(np.asarray(a)-avg).argmin()
print(idx)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
k = sum(a)
k = k/n
ans = n-1
kyo = 100000000000000000
for i in range(n-1,-1,-1):
  if kyo >= abs(a[i]-k):
    kyo = abs(a[i]-k)
    ans = i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

avg_l = sum(int_l) / N

diff_l =[]
for i in range(N):
  diff_l.append(abs(avg_l - int_l[i]))

answer = diff_l.index(min(diff_l))
print(answer)

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())
a = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
d = [abs(sum(a)/float(N) - ai) for ai in a]

if len(set(d))==1:
  print(0)
else:
  print(d.index(min(d)))

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = str(input())
array = [int(s) for s in a.split()]
sum = 0
difference = 0
index = 0

avarage = np.average(array)

for i, a in enumerate(array):
    tmp_diff = abs(a-avarage)
    if i == 0:
        difference = tmp_diff
        index = 0
    else:
        if difference > tmp_diff:
            difference = tmp_diff
            index = i

print(index)

Submission status: Accepted

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
av, ans = sum(l) / n, 0
d = abs(l[0] - av)
for i in range(n):
  t = abs(l[i] - av)
  if d > t:
    d, ans = t, i
print(ans)

Submission status: Accepted

Solution code:
a=int(input())
b = [int(i) for i in input().split()]
#print(b)
#print(sum(b)/a)
c={}
for i in range(a):
	c.update({i:abs(sum(b)/a-b[i])})
#print(c)
c=sorted(c.items(), key=lambda x: x[1])
#print(c)
print(c[0][0])

Submission status: Accepted

Solution code:
n =int( input() )
a = input().split()
a_list = []
summ = 0
for ai in a:
  summ += int(ai) 
  a_list.append(int(ai))
ave = summ/n
result = 0
min_dis = abs(a_list[0] - ave)
for i,ai in enumerate(a_list):
  dis = abs(ai - ave)
  if dis > min_dis:
    pass
  elif dis == min_dis:
    result = min(result,i)
  else:
    min_dis = dis
    result = i
print(result)

Submission status: Accepted

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

keys = [i for i in range(N)]


ave = 0
newa = []
for j in range(N):
    ave =  ave + a[j]
    newa.append(a[j]*N)
      
adict = dict(zip(keys, newa))
    
mat =[]
for i in range(N):
    mat.append(abs(newa[i]-ave))
    

amin = min(mat)


keys = [k for k, v in adict.items() if abs(v-ave) == amin]


print(min(keys))

Submission status: Accepted

Solution code:
from statistics import mean
import math
n = int(input())
a = list(map(int, input().split()))

m = mean(a)
Min = math.fabs(a[0]-m)
ret = []

for i in range(1, len(a)):
    if math.fabs(a[i]-m) < Min:
        Min = math.fabs(a[i]-m)
        ret.append(i)


if len(ret) > 0:
    print(ret[-1])
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())

num = list(map(int, input().split()))
ave = sum(num) / n

diff = None
for i, l in enumerate(num):
    if diff is None or abs(l - ave) < diff:
        diff = abs(l - ave)
        ans = i

print(ans)

Submission status: Accepted

Solution code:
n = input()
l = map(float,raw_input().split())
av = sum(l)/n
diff = abs(av-l[0])
index = 0
for i in xrange(1,n):
    if diff > abs(av-l[i]):
        index = i
        diff = abs(av-l[i])
print index

Submission status: Accepted

Solution code:
N=int(input())

a=list(map(int,input().split()))
suma=0
for i in range(N):
  suma+=a[i]
meana=suma/N

tikai=101
for i in range(N):
  if abs(meana-a[i])<tikai:
    tikai=abs(meana-a[i])
    answer=i
print(answer)

Submission status: Accepted

Solution code:
import numpy as np

N = input()

A = input().strip().split(' ')
A=[int(x) for x in A]
A_ary=np.array(A)
# print(N,A)
mu=A_ary.mean()
ans=np.argmin(abs(A_ary-mu))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
means = sum(a)/N
res = 0

for i, x in enumerate(a):
    if abs(means - x) < abs(means - a[res]):
        res = i

print(res)

Submission status: Accepted

Solution code:
import sys
N = float(input())
a = list(map(int, input().split()))
sum = 0.0
avg = 0.0

for i in a:
    sum += i
# print(N)
# print(sum)

avg = sum / N
# print(avg)
result = sys.maxsize
answer = 0
for i in a:
    if result > abs(i - avg):
        result = abs(i - avg)
        answer = a.index(i)

print(answer)

Submission status: Accepted

Solution code:
P = int(input())
N = list(map(int,input().split()))
N.reverse()
#print(N)
s = sum(N)/P
minfr=9999
ans = 0
#print(s)
for i ,n in enumerate(N):
    minfr = min(minfr,abs(n-s))
    #print(minfr,i,n)
    if minfr == abs(n-s):
        ans = i
    # TODO: write code...
print(abs(ans-(P-1)))

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
dis=np.abs(a-np.mean(a))
ind=np.argmin(dis)
print(np.min(ind))

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import sys
n= input()
n = int(n)
a = input()
b = a.split()
c=[]
for i in range(n) :
    c.append(int(b[i]))
m = mean(c)
for i in range(n) :
    if c[0] != c[i]: break
    if i == n-1:
        print(0)
        sys.exit()
for i in range(n) :
    c[i] = c[i] - m
    c[i] = abs(c[i])
f = min(c)
print(c.index(f))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = list(map(int, input().split()))

a = np.array(a)
thumbnail = np.mean(a)

print(abs(a-thumbnail).argmin())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

m = sum(a)/n
a1 = [100]*n
for i in range(n):
    a1[i] = abs(m-a[i])
print(a1.index(min(a1)))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ave = sum(a)/n
m = float('inf')
for i in a:
    m = min(m,abs(ave-i))

for k,i in enumerate(a):
    if abs(abs(i-ave)-m) <= 10**(-6):
        print(k)
        exit()

Submission status: Accepted

Solution code:
import statistics


def main():
    input()
    a = list(map(lambda x: int(x), input().split()))
    average = statistics.mean(a)
    b = list(map(lambda x: abs(x - average), a))
    print(b.index(min(b)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().strip().split()))
s = 0
for i in range(n):
	s += a[i]
mn = abs(a[0] * n - s)
ans = 0
for i in range(1, n):
	if (abs(a[i] * n - s) < mn):
		mn = abs(a[i] * n - s)
		ans = i
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
list = list(map(int,input().split()))
mean = np.mean(list)

# print(mean)
minabs = 1000
min = 0
for i,data in enumerate(list):
    if abs(data - mean) < minabs:
        minabs = abs(data - mean)
        min = i

print(min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
from statistics import mean, median,variance,stdev
import numpy as np

def main():
    N = int(input())
    A = list(map(int, stdin.readline().rstrip().split()))
    m = mean(A)

    A = np.array(A)
    A = np.abs(A -m)

    print(np.argmin(A))

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

Submission status: Accepted

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

average = sum(a)/len(a)

lst = []

for i in a:
    lst.append(abs(i-average))

print(lst.index(min(lst)))

Submission status: Accepted

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