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

tot = sum(a)
ans = -1
dif = 10**6
for i,ai in enumerate(a):
    dif_i = abs(ai*n - tot)
    if(dif > dif_i):
        dif = dif_i
        ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

li = [abs(L[i]-sum(L)/len(L)) for i in range(n)]

print(li.index(min(li)))

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
o=list(map(int,input().split()))
a=sum(o)/n
dif=1000000000
ans=-1
for i,k in enumerate(o):
    if abs(a-k)<dif:
        dif=abs(a-k)
        ans=i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
'''
Created on 2020/08/21

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  a=list(map(int,pin().split()))
  ave=sum(a)
  ans=0
  now=100*N
  for i in range(N):
    if abs(N*a[i]-ave)<now:
      now=abs(N*a[i]-ave)
      ans=i 
  print(ans)
  return 
main()

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=0
for i in range(len(a)):
    b+=a[i]
b=b/len(a)
c=[]
for i in range(len(a)):
    c.append(abs(a[i]-b))
for i in range(len(c)):
    if c[i]==min(c):
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0
for i in frames:
    sum += i

mean = sum/len(frames)

diff_lists = []
for j in frames:
    diff = j - mean
    diff_lists.append(abs(diff))

tmp_lists = diff_lists.copy()
tmp_lists.sort()
ans = diff_lists.index(tmp_lists[0])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

N_avg = sum(N_list)/N
N_avg_list=[]
for i in range(N):
  N_avg_list.append(abs(N_list[i]-N_avg))
  
print(N_avg_list.index(min(N_avg_list)))

Submission status: Accepted

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

ave = sum(a)/n
ans = -10
diff = 10**10

for i in range(n):
    diff1 = abs(ave - a[i])
    if diff1 < diff:
        diff = diff1
        ans = i

print(ans)

Submission status: Accepted

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

s = sum(A)
res = None
tmp = 10**18

for i in range(N):
    if abs(s - A[i] * N) < tmp:
        tmp = abs(s - A[i] * N)
        res = i

print(res)

Submission status: Accepted

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

s = sum(A)
res = None
tmp = 10**18

for i in range(N):
    if abs(s - A[i] * N) < tmp:
        tmp = abs(s - A[i] * N)
        res = i

print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ave = sum(a) / n
diff = float('inf')
for i in range(n):
    if diff > abs(a[i]-ave):
        diff = abs(a[i]-ave)
        ans = i

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import numpy
import sys
readline = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    avgA = numpy.average(A)
    B = list(map(lambda x: abs(x - avgA) ,A))
    minB = min(B)

    print(B.index(minB))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
avg = sum(A) / N

d = INF
ans = 0
for i in range(N):
    diff = abs(A[i] - avg)
    if diff < d:
        d = diff
        ans = i
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    if abs(a[ans] - a_ave) > abs(a[i] - a_ave):
        ans = i

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from decimal import Decimal

input = sys.stdin.readline


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

    ave = sum(A) / Decimal(N)
    min_diff = 100
    for i, a in enumerate(A):
        if abs(ave - a) < min_diff:
            min_diff = abs(ave - a)
            ans = i

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ave = sum(A)/len(A)
ans = []
for i in range(n):
    tmp = abs(A[i] - ave)
    ans.append(tmp)


print(ans.index(min(ans)))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
import numpy
B = numpy.array(A)
b = numpy.average(A)
ans = 0
dif = abs(A[0] - b)
for i in range(1, N):
    a = abs(A[i] - b)
    if a < dif:
        dif = a
        ans = i
print(ans)

Submission status: Accepted

Solution code:
from statistics import mean
_ = input()
A = [int(i) for i in input().split()]
m = mean(A)

min_d = 100
index = 0
for i in range(len(A)):
  if abs(A[i] - m) < min_d:
    min_d = abs(A[i] - m)
    index = i
print(index)

Submission status: Accepted

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

r=sum(a)/n
m=10000
ans=0
for i in range(n):
    if m>abs(a[i]-r):
        m=abs(a[i]-r)
        ans=i
print(ans)

Submission status: Accepted

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

ave_a=sum(a)/len(a)
import numpy as np
a=np.array(a)
de_a=abs(a-ave_a)
print(np.argmin(de_a))

Submission status: Accepted

Solution code:
n = int(input())
alst = list(map(int, input().split()))
ans = 0
ave = sum(alst) / n
d = abs(ave - alst[0])

for i, num in enumerate(alst):
    d_tmp = abs(ave - num)
    if d_tmp < d:
        ans = i
        d = d_tmp
print(ans)

Submission status: Accepted

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

ave=sum(a)/n
d=1001001001001
ans=0

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

Submission status: Accepted

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

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    ave = sum(a) / n
    ans = 0
    for i in range(n):
        ai = a[i]
        if abs(ai - ave) < abs(a[ans] - ave):
            ans = i
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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

md=sum(a)/n
dist=float("inf")
ans=float("inf")
for i in range(n):
    if abs(a[i]-md)<dist:
        ans=i
        dist=abs(a[i]-md)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
avg = sum(l)/n
idx=0
mindiff=101
for i,j in enumerate(l):
  if abs(avg-j)<mindiff:
    mindiff = abs(avg-j)
    idx = i
print(idx)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
aa = [i * n for i in a]
m = sum(a)
aaa = [abs(i - m) for i in aa]
mi = min(aaa)

for idx, elem in enumerate(aaa):
    if elem == mi:
        print(idx)
        exit()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = sum(a) / n
c = abs(a[0] - b)
d = 0

for i in range(1,n):
    if abs(a[i] - b) < c:
        c = abs(a[i] - b)
        d = i

print(d)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
s = sum(a)
m = inf
for i in range(n):
    if m > abs(s / n - a[i]):
        m = abs(s / n - a[i])
        idx = i
print(idx)

Submission status: Accepted

Solution code:
N = int(input())

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

avg = sum(a)/N

near_num = 101
res = 0

for i in range(N):
    if abs(a[i]-avg) < near_num:
        res = i
        near_num = abs(a[i]-avg)
print(res)

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()

ave=sum(a)/n
min_v=10**9
for i in range(n-1,-1,-1):
  if abs(a[i]-ave)<=min_v:
    min_v=abs(a[i]-ave)
    ans=i

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

median = sum(As)/N
lis = [(abs(a-median), i) for i, a in enumerate(As)]
lis.sort()
print(lis[0][1])

Submission status: Accepted

Solution code:

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

mean = sum(A)/N
mini = sum(A)
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ave=sum(a)/n
m=10**10
ans=0
for i in a:
  if m>abs(ave-i):
    m=abs(ave-i)
    ans=i
print(a.index(ans))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

median = sum(As)/N
lis = [(abs(a-median), i) for i, a in enumerate(As)]
lis.sort()
print(lis[0][1])

Submission status: Accepted

Solution code:
def solve():
  N = int(input())
  A = list(map(int, input().split()))
  ave = sum(A)/N
  B = list(map(lambda x:abs(x-ave),A))
  for i in range(N):
    B[i] = [B[i],i]
  B.sort(key=lambda x:(x[0],x[1]))
  ans = B[0][1]
  return ans
print(solve())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ave = sum(A) / N
ave_A = [0]*N
output = 10000007
for i in range(N):
  ave_A[i] = abs(A[i] - ave)
for i in range(N):
  output = min(output, ave_A[i])
print(ave_A.index(output))

Submission status: Accepted

Solution code:
def resolve():
  n = int(input())
  a = list(map(int, input().split()))
  avr = sum(a) / n
  b = []
  m = 100000
  for x in a:
    b.append(abs(x - avr))
    m = min(m, abs(x - avr))
  for i in range(len(b)):
    if b[i] == m:
      print(i)
      return
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

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

Submission status: Accepted

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

mean = sum(a)/n
now = 0
sa = 10**10

for i,j in enumerate(a):
    if abs(mean-j) < sa:
        now = i
        sa = abs(mean-j)

print(now)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    avg = sum(A)/N
    mi = abs(A[0] - avg)
    idx = 0
    for i, a in enumerate(A[1:], start=1):
        if abs(a - avg) < mi:
            mi = abs(a - avg)
            idx = i
    print(idx)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
m = sum(lst) / n
z = 10 ** 20
for i in range(n):
  a = abs(lst[i] - m)
  if a < z:
    z = a
    idx = i
print(idx)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ave_a = sum(a)/len(a)
diff = list(map(lambda x:abs(x-ave_a),a))
print(diff.index(min(diff)))

Submission status: Accepted

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

Submission status: Accepted

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

S=sum(A)
i=0
while i<N:
    A[i]*=N
    i+=1

now=float('inf')
i=0
while i<N:
    if abs(S-A[i])<now:
        now=abs(S-A[i])
        ans=i
    i+=1

print(ans)

Submission status: Accepted

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

ave = sum(a)/n
number = []
small = 10**3

for i in range(n):
    if abs(a[i] - ave) < small:
        number = []
        number.append(i)
        small = abs(a[i] - ave)

number.sort()

print(number[0])

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
a = [int(_) for _ in stdin.readline().rstrip().split()]
avg = sum(a) / len(a)
ans_idx = 0
ans_f = 101
for i, f in enumerate(a):
    diff = abs(f-avg)
    if diff < ans_f:
        ans_f = diff
        ans_idx = i
print(ans_idx)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
me = sum(l)/n
ans = -1
now = 10**10
for i in range(n):
    if abs(me-l[i])<now:
        now = abs(me-l[i])
        ans = i
print(ans)

Submission status: Accepted

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

ans = 0
j = 101
for i in range(n):
    tmp = abs(a[i]-av)
    if j > tmp:
        j = tmp
        ans = i

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_lis = list(map(int, input().split()))
ans = max(a_lis)
ans_a = n
a_avg = sum(a_lis)/len(a_lis)

for i, a in enumerate(a_lis):
    if abs(a - a_avg) < ans:
        ans = abs(a - a_avg)
        ans_a = i

print(ans_a)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
s=sum(a)
t=200
A=0
for i in range(N-1,-1,-1):
    d=abs(a[i]*N-s)
    if d<=t:
        t=d
        A=i
print(A)

Submission status: Accepted

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

total = sum(A)

diff = total
ans = -1
for index, a in enumerate(A):
    if diff > abs(total - N * a):
        ans = index
        diff = abs(total - N * a)

print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = []
    ave = sum(A)/N
    this = max(A)
    count = 0
    for i in A:
        ans.append(abs(ave-i))
    for j in range(N):
        if this > ans[j]:
            count = j
            this = ans[j]
    print(count)
resolve()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
a = LIST()

ave = sum(a)/N

b = [abs(x-ave) for x in a]

ans = b.index(min(b))
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
a = LIST()

ave = sum(a)/N

b = [[abs(x-ave), i] for i, x in enumerate(a)]

b.sort(key = lambda x: (x[0], x[1]))

print(b[0][1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mean = sum(a) / n
INF = 10**5
flg = INF
for i in range(n):
  if abs(mean - a[i]) < flg:
    idx = i
    flg = abs(mean - a[i])
print(idx)

Submission status: Accepted

Solution code:
n = int(input())
frame = list(map(int, input().split()))
avg = sum(frame) / n
ans= []
for d in frame:
    ans.append(abs(d-avg)) 
    
print(ans.index(min(ans)))

Submission status: Accepted

Solution code:
n = int(input())
a_l = list(map(int, input().split()))
import numpy as np
ave_a = np.mean(a_l)
a_l2 = [ (i, abs(j-ave_a)) for i,j in enumerate(a_l) ]
a_l3 = sorted(a_l2, key=lambda x: x[1])
print(a_l3[0][0])

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
A = IL()
M = sum(A)
B = [ (abs(A[i]*N-M),i) for i in range(N)]
B.sort()
print(B[0][1])

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
f = np.array(list(map(int, input().split())) )
print(np.where(abs(f - np.mean(f)) == min(abs(f - np.mean(f))))[0][0])

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)

minA = min(A)

print(A.index(minA))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    avg = sum(a) / n
    min = 101
    now = 0
    for i in range(n):
        if abs(avg -a[i]) < min:
           min = abs(avg -a[i])
           now = i
    print(now)

Submission status: Accepted

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

x = sum(li)/n
li = [abs(i-x) for i in li]

print(li.index(min(li)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=sum(a)/len(a)
dif=200
for i in range(n):
    if dif>abs(x-a[i]):
        dif=abs(x-a[i])
        ans=i
print(ans)

Submission status: Accepted

Solution code:
def hiku(k):
  return abs(k-c)
N=int(input())
L=list(map(int,input().split()))
c=sum(L)/len(L)
L=list(map(hiku,L))
t=min(L)
print(L.index(t))

Submission status: Accepted

Solution code:
import sys
import statistics

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    ave = statistics.mean(A)

    diff = f_inf
    res = 0
    for i in range(n):
        if diff > abs(A[i] - ave):
            res = i
            diff = abs(A[i] - ave)

    print(res)


if __name__ == '__main__':
    resolve()