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=list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
int(input().strip())
a_s = list(map(int,input().strip().split()))
a_mean = sum(a_s)/len(a_s)
min_div_a = 0
answer = 0
for i,a in enumerate(a_s):
    if i==0 or min_div_a > abs(a_mean-a):
        min_div_a = abs(a_mean-a)
        answer = i
print(answer)

Submission status: Accepted

Solution code:
import numpy as np

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

mean = np.mean(a)

idx = np.abs(np.asarray(a) - mean).argmin()

print(idx)

Submission status: Accepted

Solution code:
n = int(input())
frame_list = list(map(int,input().split()))
frame_mean = sum(frame_list)/len(frame_list)
outcome = 200
count = 0

for i in range(n):
    if abs(frame_mean - frame_list[i]) < outcome:
        outcome = abs(frame_mean - frame_list[i])
        count = i

print(count)

Submission status: Accepted

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

ac = 0
ad = 999
mean = sum(aList) / len(aList)
for i in range(N):
    iad = abs(aList[i] - mean)
    if iad == 0:
        ac = i
        break
    elif iad < ad:
        ad = iad
        ac = i
    else:
        continue
print(ac)

Submission status: Accepted

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

ave=sum(a)/N
b=list(map(lambda x: abs(ave-x),a))
ans=min(b)

for i in range(N):
    if b[i]==ans:
        print(i)
        break

Submission status: Accepted

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
sum_ = 0
for i in num_list:
    sum_ += i
mean = sum_ / n
min_ = 1000000000000000
for i in range(n):
    if abs(mean - num_list[i]) < min_:
        min_ = abs(mean - num_list[i])
        thumbnail = i
print(thumbnail)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
#print("N",N)
a_arr = input().split()
tmp = []
for ele in a_arr:
    tmp.append(int(ele))
arr = np.array(tmp)
avg = np.mean(arr)
evaluate_arr = np.abs(arr - avg)
evaluate_pos = np.argmin(evaluate_arr)
print(evaluate_pos)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import statistics

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

def argmin(z):
    min_idx = 0
    min_val = 10000
    for k, v in enumerate(z):
        if min_val > v:
            min_idx = k
            min_val = v
    return min_idx, min_val

m = statistics.mean(a)
z = [abs(b - m) for b in a]

k, v = argmin(z)
print(k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
I= list(map(int, input().split()))
NI = sum(I)/N
for i in range(N):
    I[i]=abs(I[i]-NI)
minI=min(I)
print(I.index(minI))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
s=sum(a)
l=len(a)
x=s/l
z=100
for cnt,i in enumerate(a):
    y=abs(i-x)
    if y<z:
        ans=cnt
        z=y
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
nums=np.array(list(map(int,input().split())))
ave=np.average(nums)
print(np.argmin(np.abs(nums-ave)))

Submission status: Accepted

Solution code:
def 解():
    iN = int(input())
    aA = [int(_) for _ in input().split()]

    iM = sum(aA) / iN

    d = {}
    for i,a in enumerate(aA):
        d[i] = [a, abs(a - iM)]
    print(sorted(d.items(),key=lambda x:x[1][1])[0][0])
解()

Submission status: Accepted

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

min = abs(avg-max(a))+1
index=0
for i in range(len(a)):
    x=abs(a[i]-avg)
    if x < min:
        min = x
        index=i
print(index)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import numpy as np
from sys import stdin

def load():
    n = stdin.readline()
    data = [int(x) for x in stdin.readline().split()]
    return (n,data)

def calc(n, data):
    d = np.asarray(data)
    m = d.mean()
    diff = np.abs(d - m)
    return diff.argmin()

n, data = load()
print(calc(n, data))

Submission status: Accepted

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

avg = sum(A) / N

ans = 0
cur = float('inf')
for i, a in enumerate(A):
    d = abs(avg - a)
    if cur > d:
        cur = d
        ans = i
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
if __name__ == "__main__":
    n = int(input())
    a = list(map(float, input().split()))

    mean = sum(a) / n

    dist = [0. for _ in range(n)]
    for i in range(n):
        dist[i] = abs(a[i] - mean)

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

Submission status: Accepted

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

import numpy as np
mean = np.mean(a)
lst = []
for i in range(N):
  lst.append(np.abs(a[i]-mean))

min_val = np.min(lst)
for i in range(N):
  if lst[i] == min_val:
    print(i)
    break

Submission status: Accepted

Solution code:
import sys

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

ave = sum(a)/N

mini = float("inf")
ans = 0
for i,_a in enumerate(a):
	d = ave - _a
	d = abs(d)
	if d == 0:
		print(i)
		sys.exit()
	if mini > d:
		mini = d
		ans = i
print(ans)

Submission status: Accepted

Solution code:
from statistics import mean

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


avg = mean(a_list)
a_list2 = [abs(a - avg) for a in a_list]

print(str(a_list2.index(min(a_list2))))

Submission status: Accepted

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

mean = sum(a) / N
mini = (0, abs(a[0] - mean))
for i, ai in enumerate(a):
    if abs(ai - mean) < mini[1]:
        mini = (i, abs(ai - mean))
print(mini[0])

Submission status: Accepted

Solution code:
# coding:utf-8

n = int(input())

a_arr = [a for a in map(int, input().split())]

a_ave = sum(a_arr)/n

min_frame_num = 0
for i in range(len(a_arr)):
    if i==0:
        min_frame_num = 0
        min_frame = abs(a_ave-a_arr[i])
    if min_frame > abs(a_ave-a_arr[i]):
        min_frame_num = i
        min_frame = abs(a_ave-a_arr[i])


print(min_frame_num)

Submission status: Accepted

Solution code:
N = input()

buf = input()

array = buf.split()

array_int = [int(ele) for ele in array]

sum_array = sum(array_int)
mean = float(sum_array) / int(N)

diff = [ float(abs(x-mean)) for x in array_int]


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

Submission status: Accepted

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




#%%
ave = sum(a)/len(a)

least_dif = 99999
ans = 0
for i, num in enumerate(a):
    dif = abs(num - ave)
    if dif < least_dif:
        least_dif = dif
        ans = i

print(ans)

Submission status: Accepted

Solution code:

array = list(map(int, input().strip().split(' ')))

N = array[0]

array1 = list(map(int, input().strip().split(' ')))

kazu = len(array1)

ans = 0

for i in range(N):

    ans = ans + array1[i]

heikin = ans / N

min_ans = 999
ans2 = 0

for i in  range(N):

    test = abs(array1[i] - heikin)
    

    if test < min_ans:

        min_ans = test
        ans2 = i

print(ans2)

Submission status: Accepted

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

su = sum(a) / n
mi = 1000
ans = 1000

for i, aa in enumerate(a):
	tmp = abs(aa - su)
	if tmp < mi:
		mi = tmp
		ans = i
		
print(ans)

Submission status: Accepted

Solution code:
# your code goes here
import numpy as np

def main():
	n = int(input())
	a = list(map(int, input().split()))
	m = np.mean(a)
	r = 0
	
	for i in range(n):
		if ((a[i]-m)**2 < (a[r]-m)**2):
			r = i
	print(r)
	
main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
import numpy as np
av = np.mean(a)
nor = a - av
pos = [abs(i) for i in nor]
min = np.min(pos)
print(pos.index(min))

Submission status: Accepted

Solution code:
input()
lst = list(map(int,input().split()))
avg = sum(lst)/len(lst)
mn = abs(avg-lst[0])
mnn=0
for i in lst:
    if abs(avg-i)<mn:
        mnn=lst.index(i)
        mn = abs(i-avg)
print(mnn)

Submission status: Accepted

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

mean = sum(A) / N
# print(mean)
err = abs(A[0]-mean)
ans = 0
for i, a in enumerate(A):
    # print(i, err)
    if abs(a - mean) < err:
        # print(i, err)
        err = abs(a - mean)
        ans = i

print(ans)

Submission status: Accepted

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

ave = sum(a) / N

min = abs(a[0] - ave)
min_num = 0


for i in range(1, N):
    if min > abs(a[i] - ave):
        min_num = i
        min = abs(a[i] - ave)

print(min_num)

Submission status: Accepted

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

mean = sum(a)/N
ind = None
min = None
for i in range(N):
    tmp=abs(mean-a[i])
    if min is None:
        min=tmp
        ind=i
    else:
        if tmp<min:
            min=tmp
            ind=i

print(ind)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
lst = list(map(int, input().split()))
ave = sum(lst) / len(lst)

lst_diff = []
for i, val in enumerate(lst):
    lst_diff.append(abs(ave - val))
print(lst_diff.index(min(lst_diff)))

Submission status: Accepted

Solution code:
n = int(input())
p = input()
o = p.split()
k = []
for i in range(n):
    k.append(int(o[i]))
a = sum(k)/n
l = 99999
m = None
for i in range(n):
    w = k[i]
    if (abs(w - a) < l):
        m = i
        l = abs(w - a)
print(m)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

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

ave = 0

for n in range(N):
	ave = ave + X_list[n]
ave = ave / N

answer_size = max(X_list)

answer = 0

for n in range(N):
	if answer_size > abs(ave - X_list[n]):
		answer_size = abs(ave - X_list[n])
		answer = n

print(answer)

Submission status: Accepted

Solution code:
import math

N = int(input())
a = [int(x) for x in input().split()]
mean = sum(a) / N
x = [abs(i-mean) for i in a]
ans = x.index(min(x))
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = np.array([int(x) for x in input().split(" ")])
indices = np.abs(np.subtract.outer(a, a.mean())).argmin(0)
print(indices)

Submission status: Accepted

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

Ave=sum(A)/N
Ans=0
cnt=10000000
for i in range(N):
    if abs(Ave-A[i])<cnt:
        cnt=abs(Ave-A[i])
        Ans=i

print(Ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(answer)

Submission status: Accepted

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

mean = 0

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

mean /= len(A)

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

print(min_frame)

Submission status: Accepted

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

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

ave = total / n

tmp = float('inf')

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

Submission status: Accepted

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

avg = sum(a_array)/n

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

Submission status: Accepted

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

avg = sum(a)/N

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

ave = float(sum) / N

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

diff = 1000
res = 0

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
N = int(input())

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

a = 10000

min = 0

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

print(min)

Submission status: Accepted

Solution code:
from statistics import mean

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

a_mean = mean(a)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

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

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

print(place)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

tmp = 100

ave = sum(A)/N

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans2)

Submission status: Accepted

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

Submission status: Accepted

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

average = sum(A)/float(N)

diff = max(A)
index = None

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())

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

s=sum(aList)
mean=s/n

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sumN = 0

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

mean = sumN / n

min_margin = float("inf")
frame = 0

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

print(frame)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

avg=mean(a)

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

#print(min(b))
#c=sorted(b)

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

Submission status: Accepted

Solution code:
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

MOD = 10 ** 9 + 7

N = int(input())
A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

ave = sum(A)/N

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

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

sys.exit(0)

Submission status: Accepted

Solution code:
import statistics
import numpy as np

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

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

Submission status: Accepted

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

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

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

print(p)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a_avg = sum(a) / len(a)
ai_min = 0  # 最も小さいフレーム番号
d_min = abs(a[0] - a_avg)  # ai_minが持つ平均値との距離
for i in range(1, N):
    d = abs(a[i] - a_avg)
    if d < d_min:
        ai_min = i
        d_min = d
print(ai_min)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ave = sum(a)/n

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

print(ans)

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()))
ave = 0
i = 0
for i in range(N):
    ave += a[i]
ave /= N
mini = 1000
mnum = 1000
for j in range(N):
    if mini > abs(a[j] - ave):
        mini = abs(a[j] - ave)
        mnum = j
print(mnum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy

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


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

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



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

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

print(r)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

mini = dif[0]
ans = 0

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

s = sum(ar)

margin = 9999999999999999999999999999999999999
pos = -7

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

print pos

Submission status: Accepted

Solution code:
# coding:utf-8

import sys

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


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


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

print(A.index(min_num))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()