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: Wrong Answer

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)]
print(a_norm.index(min(a_norm)))

Submission status: Wrong Answer

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 = S - a[i] * N
        ans = i

print ans

Submission status: Wrong Answer

Solution code:
N = float(input())
a = list(map(float, input().split()))
aver = sum(a)//N

inta = (0, -1, 1, -2, 2, -3, 3)

for atest in inta:
    if atest+aver in a:
        print(a.index(atest+aver))
        break

Submission status: Wrong Answer

Solution code:
N = float(input())
a = list(map(float, input().split()))
aver = int(sum(a)//N+1) if sum(a)/N > sum(a)//N+0.5 else int(sum(a)//N)
 
inta = (0, -1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6)
 
for atest in inta:
    if atest+aver in a:
        print(a.index(atest+aver))
        break

Submission status: Wrong Answer

Solution code:
N = float(input())
a = list(map(float, input().split()))
aver = int(sum(a)//N+1) if sum(a)/N > sum(a)//N+0.5 else int(sum(a)//N)

inta = (0, -1, 1, -2, 2, -3, 3)

for atest in inta:
    if atest+aver in a:
        print(a.index(atest+aver))
        break

Submission status: Wrong Answer

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

inta = (0, -1, 1, -2, 2, -3, 3)

for atest in inta:
    if atest+aver in a:
        print(a.index(atest+aver))
        break

Submission status: Wrong Answer

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[1],x[0]))
# print(ave,a)

print(a[0][0])

Submission status: Wrong Answer

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

ma = sum(a) / len(a)

l = 0
u = len(a)-1
for i in range(len(a)):
    if a[i] <= ma and a[l] < a[i]:
        l = i
    if a[i] >= ma and a[u] > a[i]:
        u = i

if (ma - a[l]) <= (a[u] - ma):
    print(l)
else:
    print(u)

Submission status: Wrong Answer

Solution code:
import numpy as np

_ = int(input())
a = np.array(list(map(int, input().split())))
idx = np.argsort(np.abs(a- a.mean()))[0]
print(idx)

Submission status: Wrong Answer

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 = avr - num[i]
        pos = i
print(pos)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = sorted([(i, int(x)) for i, x in enumerate(input().split())], key=lambda x: x[1])
avg = sum([l[1] for l in a]) / N
d = 999999999999
t = -1
pre = -1
for i, n in a:
    if n == pre:
        continue
    p = n - avg if n >= avg else avg - n
    if p == 0:
        t = i
        break
    elif p < d:
        d = p
        t = i
    else:
        break
print(t)

Submission status: Wrong Answer

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

ma = sum(a) / len(a)

a.sort()
l = 0
u = len(a)-1
for i in range(len(a)):
    if a[i] <= ma and a[l] <= a[i]:
        l = i
    if a[i] >= ma and a[u] >= a[i]:
        u = i

if (ma - a[l]) <= (a[u] - ma):
    print(a[l])
else:
    print(a[u])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = []
for i, x in enumerate(input().split()):
    if i != 0 and a[-1][1] == int(x):
        continue
    a.append((i, int(x)))
a = sorted(a, key=lambda x: x[1])
avg = sum([l[1] for l in a]) / N
d = 999999999999
t = -1
pre = -1
for i, n in a:
    if n == pre:
        continue
    p = n - avg if n >= avg else avg - n
    if p < d:
        d = p
        t = i
    elif p > d:
        break
print(t)

Submission status: Wrong Answer

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]):
        break
    if min > abs(mean - a[i]):
        min = abs(mean - a[i])
        ans = i
print(ans)

Submission status: Wrong Answer

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

ma = sum(a) / len(a)

a.sort()
l = 0
u = len(a)-1
for i in range(len(a)):
    if a[i] <= ma and a[l] <= a[i]:
        l = i
    if a[i] >= ma and a[u] >= a[i]:
        u = i

print(a[l])
print(a[u])
print(ma)

if (ma - a[l]) <= (a[u] - ma):
    print(a[l])
else:
    print(a[u])

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    if not(0 <= n <= 100):
        exit()

    a = input().split()
    ans = {}
    ave = 0

    if n != len(a):
        exit()

    for i in a:
        ave += int(i)

    ave = ave / n

    for j in range(n):
        if ave >= int(a[j]):
            ans.update({str(j): ave - int(a[j])})
        else:
            ans.update({str(j): int(a[j]) - ave})

    print(min(ans, key=ans.get))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

idx = np.argsort(np.abs(a.mean()- a))[0]
print(idx)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = input().split()
    ans = {}
    ave = 0

    # if n != len(a):
    #     exit()

    for i in a:
        ave += int(i)

    ave = ave / n

    for j in range(n):
        if ave >= int(a[j]):
            ans.update({str(j): ave - int(a[j])})
        else:
            ans.update({str(j): int(a[j]) - ave})

    print(min(ans, key=ans.get))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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(int(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: Wrong Answer

Solution code:
import numpy as np

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

idx = np.argsort(np.abs(a - np.round(a.mean(), 2)))[0]
print(idx)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = list(map(lambda x: x*n, a))
         
av = sum(a)//n
for i in range(n):
    if a[i] == av:
        print(i)
        break
    if a[i] < av and av < a[i+1]:
        print(i if  av-a[i] <= a[i+1]-av else i+1)
        break
print(a, av)

Submission status: Wrong Answer

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 ((mylist[maxi] > sum or mylist[maxi] < mylist[i]) and mylist[i] <= sum):
		maxi = i;
print(maxi);

Submission status: Wrong Answer

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(array[index])

Submission status: Wrong Answer

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)
        print(math.fabs(a[i]-m))

print(ret)

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = sorted([(i, int(x)) for i, x in enumerate(input().split())], key=lambda x: x[1])
avg = sum([l[1] for l in a]) / N
d = 999999999999
t = -1
pre = -1
for i, n in a:
    if n == pre:
        continue
    p = n - avg if n >= avg else avg - n
    if p < d:
        d = p
        t = i
    elif p > d:
        break
    elif p == 0:
        t = i
        break
print(t)

Submission status: Wrong Answer

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())
print(c[0][0])

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = input().split()
    ans = {}
    ave = 0

    if n != len(a):
        exit()

    for i in a:
        ave += int(i)

    ave = ave / n

    for j in range(n):
        if ave >= int(a[j]):
            ans.update({str(j): ave - int(a[j])})
        else:
            ans.update({str(j): int(a[j]) - ave})

    print(min(ans, key=ans.get))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = sorted([(i, int(x)) for i, x in enumerate(input().split())], key=lambda x: x[1])
avg = sum([l[1] for l in a]) / N

d = 999999999999
t = -1
pre = -1
for i, n in a:
    if n == pre:
        continue
    p = n - avg if n >= avg else avg - n
    if p < d:
        d = p
        t = i
    elif p > d:
        break
    else:
        t = i
        break
print(t)

Submission status: Wrong Answer

Solution code:
from statistics import mean, median
input()
inputs =  list(map(int, input().split()))

med = median(inputs)
flameNum = 0
min = 999999
for index,i in enumerate(inputs):
    if(abs(i - med) < min):
        min = abs(i-med)
        flameNum = index
print(flameNum)

Submission status: Wrong Answer

Solution code:
from statistics import mean, median
input()
inputs =  list(map(int, input().split()))

med = median(inputs)
flameNum = 0
min = 999
for index,i in enumerate(inputs):
    if(abs(i - med) < min):
        min = abs(i-med)
        flameNum = index
print(flameNum)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
av = sum(a)/n
for i in range(n-1):
    if a[i] <= av and av <= a[i+1]:
        print(i if  av-a[i] <= a[i+1]-av else i+1)
        break

Submission status: Wrong Answer

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

m = mean(a)
Min = abs(a[0]-m)
ret = []

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

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

Submission status: Wrong Answer

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

m = mean(a)
Min = abs(a[0]-m)
ret = [0]

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = sorted([(i, int(x)) for i, x in enumerate(input().split())], key=lambda x: x[1])
avg = sum([l[1] for l in a]) / N
d = 999999999999
t = -1
pre = -1
for i, n in a:
    if n == pre:
        continue
    p = n - avg if n >= avg else avg - n
    if p < d:
        d = p
        t = i
    elif p > d:
        break
print(t)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ave = a.mean()
idx = np.argsort(np.abs(a - ave))[0]
print(idx)

Submission status: Wrong Answer

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

keys = [i for i in range(N)]
adict = dict(zip(keys, a))

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

mat =[]
for i in range(N):
    mat.append(a[i]-ave)

amin = min(mat)


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

print(min(keys))

Submission status: Wrong Answer

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):
    print(abs(a[i] - ave_a))
    if sa > abs(a[i] - ave_a):
        sa = abs(a[i] - ave_a)
        min_ind = i
print(min_ind)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = sorted([(i, int(x)) for i, x in enumerate(input().split())], key=lambda x: x[1])
avg = sum([l[1] for l in a]) / N
d = 999999999999
t = -1
for i, n in a:
    p = n - avg if n >= avg else avg - n
    if p < d:
        d = p
        t = i
    elif p > d:
        break
print(t)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = sorted([(i, int(x)) for i, x in enumerate(input().split())], key=lambda x: x[1])
avg = sum([l[1] for l in a]) / N

d = 999999999999
t = -1

for i, n in a:
    p = n - avg if n >= avg else avg - n
    if p < d:
        d = p
        t = i
    elif p > d:
        print(t)

Submission status: Wrong Answer

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 = a[i] * n - s
		ans = i
print(ans)

Submission status: Wrong Answer

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

m = sum(a)/n
a1 = list(set(sorted(a)))
a2 = [0]*len(a1)
for i in range(len(a1)):
    a2[i] = abs(m-a1[i])
print(a.index(a1[a2.index(min(a2))]))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ave = a.mean()
idx = np.abs(np.argsort(a - ave))[0]
print(idx)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
list = list(map(int,input().split()))
mean = int(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: Wrong Answer

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

Submission status: Wrong Answer

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

Solution code:
from statistics import mean, median
input()
inputs =  list(map(int, input().split()))

med = median(inputs)
flameNum = 0
tmpnum = 0
min = 999
for i in inputs:
    if(abs(i - med) < min):
        min = abs(i-med)
        flameNum = tmpnum
    tmpnum += 1
print(flameNum)

Submission status: Wrong Answer

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 = i-avg
print(mnn)

Submission status: Wrong Answer

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 = min(i, ans)
		
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def frame(N, *args):
    a = frame(*args)
    if N == sum(a) / a:
        return min
    else:
        return N / sum(a) / a

Submission status: Wrong Answer

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(a[indices])

Submission status: Wrong Answer

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

mean = -1

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: Wrong Answer

Solution code:
import math

N = int(raw_input())
A = [int(x) for x in raw_input().split()]
a = sum(A)/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: Wrong Answer

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

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

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

Submission status: Wrong Answer

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 = ave-a[i]
else:
    print(res)

Submission status: Wrong Answer

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=Ave-A[i]
        Ans=i

print(Ans)

Submission status: Wrong Answer

Solution code:
import sys

N = int(sys.stdin.readline())

A = map(int, sys.stdin.readline().strip().split(" "))

avg = 1. * sum(A) / N

near = 9999999
idx = -1
for i, a in enumerate(A):
    if near > abs(a-avg):
        near = abs(a-avg)
        idx = i

print(idx)

Submission status: Wrong Answer

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 c[i]==min(b):
        print(i)
        exit(0)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
import math

N = int(raw_input())
A = [int(x) for x in raw_input().split()]
a = sum(A)/N
if a % 1 <= 0.5:
    print int(math.floor(a))
else:
    print int(math.ceil(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

Submission status: Wrong Answer

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()
B = set(A)
m = sum(A)/N
tmp = INF
min_num = A[0]
for b in B:
    if abs(b - m) < tmp:
        tmp = abs(b - m)
        min_num = b

print(A.index(min_num))

Submission status: Wrong Answer

Solution code:
a = int(input())

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

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

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

Submission status: Wrong Answer

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

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

min_a = 100000000
index = 0
for i in range(len(a)):
    if min_a > abs(a_mean - a[i]):
        index = i
        min_a = a_mean - a[i]
print(index)

Submission status: Wrong Answer

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: Wrong Answer

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

Submission status: Accepted

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

mean = sum(A) / n

B = []
for i in A:
    B.append(abs(i - mean))
print(B.index(min(B)))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

m = sum(A) / N

res = 10 ** 9
cost = 10 ** 9
for i, a in enumerate(A):
    if abs(a - m) < cost:
        res = i
        cost = abs(a - m)

print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b
def ceil(x):
    return math.ceil(x)
def floor(x):
    return math.floor(x)

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

    avg = sum(a) / N
    min_abs = 10**9
    for i in range(N):
        min_abs = min(min_abs, abs(a[i] - avg))
    for i in range(N):
        if abs(a[i] - avg) == min_abs:
            print(i)
            exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import statistics
n = int(input())
a = list(map(int,input().split()))
s = statistics.mean(a)
c = float("inf")
for i in range(n):
    if c!=min(abs(s-a[i]),c):
        c = abs(s-a[i])
        d = i
print(d)

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 = ave/N

ans = 0
m = 10**8
for i in range(N):
    tmp = A[N-1-i]
    res = abs(tmp-ave)
    if res<=m:
        m = res
        ans = N-1-i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in f:
    diff=abs(i-ave)
    b.append(diff)
print(b.index(min(b)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from statistics import mean
# a=int(input())
b=int(input())
# c=[]
# for i in b:
#     c.append(i)
#e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#j = [input() for _ in range(3)]

mea = mean(f)
lis=[]

if mea in f :
    print(f.index(mea))
else:
    for i in range(len(f)):
        lis.append(abs(mea-f[i]))
    print(lis.index(min(lis)))

Submission status: Accepted

Solution code:
# 第5回 ドワンゴからの挑戦状 予選: A – Thumbnail
N = int(input())
a = [int(i) for i in input().split()]

avg = sum(a) / len(a)
diff = [abs(i - avg) for i in a]

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(s) for s in input().split()]
avg = sum(a) / len(a)

min_abs = 100
index = 0
for i in range(len(a)):
    if abs(avg - a[i]) < min_abs:
        min_abs = abs(avg - a[i])
        index = i
print(index)

Submission status: Accepted

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

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 /= n
delta = 100
ans = -1
for i in range(n):
    d = abs(avg - a[i])
    if d < delta:
        ans = i
        delta = d
print(ans)

Submission status: Accepted

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

if N == 1:
  print(0)
  exit()

m = sum(a)

MIN=10**20
argmin=-1
for i in range(N):
  if MIN>abs(m-a[i]*N):
    MIN = abs(m-a[i]*N)
    argmin = i
print(argmin)

Submission status: Accepted

Solution code:
import sys

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


def main():
    N = int(readline())
    a = list(map(int, readline().split()))
    S = sum(a)
    b = list(map(lambda x: abs(S - N * x), a))
    print(b.index(min(b)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
n=int(input())
l = list(map(int,input().split()))
heikin=sum(l)/n
tmp=float('inf')
ans=n-1
for i in range(n-1,-1,-1):
    if abs(l[i]-heikin) <= tmp:
        ans=i
        tmp=abs(l[i]-heikin)
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    sum_a = sum(a_list)
    min_val = 100
    min_index = 0

    for i, a in enumerate(a_list):
        d = abs(n * a - sum_a)
        if d < min_val:
            min_val = d
            min_index = i

    print(min_index)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    mean_a = sum(a_list) / n
    diff_list = [abs(a - mean_a) for a in a_list]
    min_a = min(diff_list)
    print(diff_list.index(min_a))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
import numpy as np
import heapq
from collections import defaultdict
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    a = list(mi())
    mean = sum(a)/N

    m = min((abs(a[i]-mean), i) for i in range(N))
    print(m[1])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

mean = sum(l)/n
x=10**9+7
y=-1
for i in l:
    if x > abs(i-mean):
        x = abs(i-mean)
        y = i

print(l.index(y))

Submission status: Accepted

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