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:
import sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
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

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

# ここから書き始める
n = int(input())
a = list(map(int, input().split()))
average = sum(a) / n
b = [abs(i - average) for i in a]
# print("b =", b)
diff = INF
ans = 0
for i in range(n):
    if b[i] < diff:
        diff = b[i]
        ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a_li = list(map(int,input().split()))
a_ave = sum(a_li) / len(a_li)
ans = []
for i in range(N):
    ans.append([abs(a_li[i]-a_ave),i])
print(sorted(ans)[0][1])

Submission status: Accepted

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

Submission status: Accepted

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

avg = sum(a) / n

idx = 0
val = float('INF')
for i in range(n):
    if abs(a[i]-avg) < val:
        idx = i
        val = abs(a[i]-avg)
print(idx)

Submission status: Accepted

Solution code:
import statistics
N = int(input())
A = list(map(int,input().split()))
MEAN = statistics.mean(A)
D = [abs(a -MEAN) for a in A]
MIN = 100
MIN_I = 0
for i in range(N):
    if MIN > D[i]:
        MIN = D[i]
        MIN_I = i
print(MIN_I)

Submission status: Accepted

Solution code:
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    N = int(input().rstrip())
    vec =list(map(int, input().split())) 

    avg = sum(vec)/len(vec)
    for x in range(len(vec)):
        vec[x] = (vec[x] - avg)**2
    
    # print(vec)
    MIN = INF
    ANS = 0
    for i,x in enumerate(vec):
        if(MIN > x):
            MIN = x
            ANS = i

    print(ANS)


    print("")
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

sm = sum(a)
diff = 10000
ans = -1
for i, e in enumerate(a):
    diff_now = abs(e * n - sm)
    if diff_now < diff:
        ans = i
        diff = diff_now

print(ans)

Submission status: Accepted

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

b=sum(a)/len(a)
c=[abs(a[i]-b) for i in range(N)]

print(c.index(min(c)))

Submission status: Accepted

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

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    samunenum=100
    samune=10**18
    for i in range(n):
        x=abs(sum(l)-n*l[i])
        if x<samune:
            samunenum=i
            samune=x
    print(samunenum)
resolve()

Submission status: Accepted

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

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    heikin=sum(l)/n
    samunenum=100
    samune=10**18
    for i in range(n):
        x=abs(heikin-l[i])
        if x<samune:
            samunenum=i
            samune=x
    print(samunenum)
resolve()

Submission status: Accepted

Solution code:
import statistics
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    val=statistics.mean(A)
    d=[0]*n
    for i in range(n):
        d[i]=abs(val-A[i])
    ans=d.index(min(d))
    print(ans)

    
resolve()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = sum(a)/n
ans = []
for x,y in enumerate(a):
  ans.append([x, abs(m-y)])
ans.sort(key=lambda x:x[1])
print(ans[0][0])

Submission status: Accepted

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

Submission status: Accepted

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

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

me = sum(a)/n

for i in range(n):
    a[i]= abs(a[i]-me)

mia = min(a)
ans = a.index(mia)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
mu=sum(A)/n
diff=1000
ans=0
for i,a in enumerate(A):
    if abs(a-mu)<diff:
        diff=abs(a-mu)
        ans=i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
s = sum(a)
m = float("inf")
for i, j in enumerate(a):
  t = abs(s - n*j)
  if t < m:
    m = t
    k = i
print(k)

Submission status: Accepted

Solution code:
import numpy as np

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

m = np.mean(a)

a -= m
a = np.abs(a)
print(np.argmin(a))

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
def func(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
n = int(input())
a = list(map(int, input().split()))
print(a.index(func(a, sum(a) / n)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n =int(input())
a=[int(x) for x in input().split()]
 
s=sum(a)
ans=0
diff=abs(s-a[0]*n)
for i in range(n):
  if diff>abs(s-a[i]*n): 
    diff= abs(s-a[i]*n)
    ans=i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mu = sum(A) / N
diff = 1000
ans = 0
for i, a in enumerate(A):
  if abs(a - mu) < diff:
    diff = abs(a - mu)
    ans = i

print(ans)

Submission status: Accepted

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

b = sum(a)/n
for i in range(n):
    a[i] = abs(a[i]-b)

k = a.index(min(a))
print(k)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int ,input().split()))
avg = sum(a) / n
diffs = []
for i in range(n):
    diff = abs(a[i] - avg)
    diffs.append(diff)
minVal = 100
idx = 0
for k in range(n):
    if diffs[k] < minVal:
        minVal = diffs[k]
        idx = k
    else:
        continue
print(idx)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
###################################################
def main():
    n=int(input())
    A=list(map(int,input().split()))
    s=sum(A)
    mi=inf
    ans=inf
    for a in range(len(A)-1,-1,-1):
        if abs(A[a]*len(A)-s)<=mi:
            mi=abs(A[a]*len(A)-s)
            ans=a
    print(ans)
main()

Submission status: Accepted

Solution code:
#coding:utf-8
n = int(input())
a = list(map(int, input().split()))

avg = sum(a) / n
ans = 0
diff = abs(avg - a[0])

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

Submission status: Accepted

Solution code:
# A - Thumbnail
N = int(input())
a = list(map(int, input().split()))

avg = sum(a) / N
min = avg

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

print(ans)

Submission status: Accepted

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

diff = max(A)
ans = None
for i in range(N):
    if diff > abs(ave - A[i]):
        diff = abs(ave - A[i])
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    A=np.array(A)
    meanA=np.mean(A)
    A1=np.abs(A-meanA)
    print(np.argmin(A1))


if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
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()))
print(a.index(getNearestValue(a, sum(a) / n)))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
m = sum(A)/N
dif = [0]*N

for i in range(N):
    dif[i] = abs(m - A[i])

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

mean = sum(a) / n

ans = [200, 200]

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

print(ans[0])

Submission status: Accepted

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

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

mean = sum(a) / n

ans = [200, 200]

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

print(ans[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
av = sum(a) / n
aa = list(map(lambda x: abs(x - av), a))
aa = list(zip(aa, range(n)))
aa.sort()
print(aa[0][1])

Submission status: Accepted

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

for i in range(n):
    li.append(abs(ave-a[i]))
    
print(li.index(min(li)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LI()
    av = sum(a)/n
    aa = list(map(lambda x: abs(x - av), a))
    aa = list(zip(aa, range(n)))
    aa.sort()
    print(aa[0][1])
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
mean_a = sum(A)/N
distance_list = [abs(a - (mean_a)) for a in A]

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
ave = sum(A)/n
ans, idx = float('inf'), -1
for i in range(n):
    if abs(A[i]-ave) < ans:
        ans = abs(A[i]-ave)
        idx = i
print(idx)

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n = ii()
A = iil()
mean = sum(A)/n
diff = max(A)
ans = 0
for i in range(n):
    if abs(A[i] - mean) < diff:
        ans = i
        diff = abs(A[i] - mean)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
ave = sum(a) / n
hantei = 200000
ans = 0
for i, f in enumerate(a):
    if hantei > abs(ave - f):
        hantei = abs(ave - f)
        ans = i
 
print(ans)

Submission status: Accepted

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

ave = sum(a) / n
d = 200
ans = 0
for i, f in enumerate(a):
    if d > abs(ave - f):
        d = abs(ave - f)
        ans = i

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
ave = sum(a)/N
tmp = float('inf')
ans = 0
for i in range(N-1, -1, -1):
    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()))
av=sum(a)/len(a)
b=[abs(i-av) for i in a]
print(b.index(min(b)))

Submission status: Accepted

Solution code:
def main():
    frames = int(input())
    integer = list(map(int, input().split()))
    average = sum(integer) / frames
    answer = 0
    target = abs(average - integer[0])
    for i in range(1, frames):
        if abs(average - integer[i]) < target:
            target = abs(average - integer[i])
            answer = i
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
numlist = list(map(int, input().split()))
cal = 0
for i in numlist:
  cal = cal + i
ave = cal / (n)
dummy = abs(numlist[0]-ave)
index = 0
count = 0
for j in numlist:
  kyori = abs(j-ave)
  if dummy > kyori:
    dummy = kyori
    index = count
  count = count + 1 
print(index)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

mean_a = np.mean(a)
cnt = 0
num = 0
for i in range(N):
    if abs(a[i] - mean_a) < abs(cnt - mean_a):
        cnt = a[i]
        num = i
print(num)

Submission status: Accepted

Solution code:
N = int(input())

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

goke = 0
ans = 0

for i in range(len(a)):
    goke += a[i]

ave = goke / N

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


print(ans)

Submission status: Accepted

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

Amean = sum(A)/len(A)
res = 0
minFrameDist = 100
index = 0
for (i, a) in enumerate(A):
  frameDist = abs(Amean-a)
  if frameDist < minFrameDist:
    res = i
    minFrameDist = frameDist

print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
mid = sum(a) / len(a)
b = float('inf')
for i, j in enumerate(a):
  sa = abs(mid - j)
  if(sa < b):
    b = sa
    ans = i
print(ans)

Submission status: Accepted

Solution code:
from statistics import mean
def main():
    n = int(input())
    a = list(map(int, input().split()))
    m = mean(a)
    x = 10**6
    ans = -1
    for i in reversed(range(n)):
        if abs(a[i] - m) <= x:
            ans = i
            x = abs(a[i] - m)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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

ave = sum(A) / N
ans = 0
diff = ave
for i in range(N):
    d = abs(A[i] - ave)
    if diff > d:
        diff = d
        ans = i

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int,input().split()))
s = sum(b)/a
ans = -1
count = 10000
for i in range(a):
  k = abs(s-b[i])
  if k < count:
    ans = i
    count = k
print(ans)

Submission status: Accepted

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

# avg = sum(A) / N
sum_a = sum(A)
ans = float('inf')
ansf = -1
for i, ai in enumerate(A):
    # diff = abs(ai - avg)
    diff = abs(N * ai - sum_a)
    if diff < ans:
        ans = diff
        ansf = i

print(ansf)

Submission status: Accepted

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

avg = sum(A) / N
ans = float('inf')
ansf = -1
for i, ai in enumerate(A):
    diff = abs(ai - avg)
    if diff < ans:
        ans = diff
        ansf = i

print(ansf)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
me=sum(a)/len(a)
l=[]
for i in range(N):
    l.append([abs(me-a[i]),i])
l.sort(key=lambda x:x[0])
print(l[0][1])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))

m = sum(A) / n
ans = -1
mi = float("inf")
for i in range(n):
    if abs(m - A[i]) < mi:
        ans = i
        mi = abs(m - A[i])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d=100
ans=1000
av=sum(a)/n
for i in range(n):
    res=abs(a[i]-av)
    if res<d:
        d=res
        ans=i
print(ans)

Submission status: Accepted

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

ans = 0
ans_diff = abs(ave - al[0])
for i, a in enumerate(al):
    if abs(ave-a) < ans_diff:
        ans = i
        ans_diff = abs(ave-a)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
ave_a = sum(a)/N
cnt = 101
ans = 0

for i in range(N):
    tmp = abs(ave_a-a[i])
    if(tmp < cnt):
        cnt = tmp
        ans = i
print(ans)

Submission status: Accepted

Solution code:
N, *A=map(int, open(0).read().split())
M=sum(A)/N
print(min((abs(M-a),i) for i,a in enumerate(A))[1])

Submission status: Accepted

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

sum_a = 0
for i in a:
    sum_a += int(i)

avg = sum_a / n

sa = []

for i in a:
    if avg - int(i) >= 0:
        sa.append(avg - int(i))
    elif avg - int(i) < 0:
        sa.append(int(i) - avg)

sa_answer = min(sa)

for i in range(len(a)):
    if sum_a / n + sa_answer == int(a[i]) or sum_a / n - sa_answer == int(a[i]):
        print(i)
        break

Submission status: Accepted

Solution code:
n = int(input())
dat = list(map(int, input().split()))
s = sum(dat) / n
mind = -1
mval = 9999
for i in range(n):
    if abs(dat[i] - s) < mval:
        mval = abs(dat[i] - s)
        mind = i
print(mind)

Submission status: Accepted

Solution code:
n = int(input())
a_lis = list(map(int, input().split()))
a_sum = sum(a_lis)
a_avg = a_sum / n
minimum = 1000
ans = 0
for i in a_lis:
    n = abs(a_avg - i)
    if n < minimum:
        minimum = n
        ans = i
print(a_lis.index(ans))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
ave = sum(a) / N
diff = 10**9
ans=0
for i,x in enumerate(a):
  if diff > abs(ave - x):
    diff = abs(ave - x)
    ans = i
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

a = abs(a - a.mean())

print(a.argmin())

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
mid=sum(A)/len(A)
b=float('inf')
for i,a in enumerate(A):
  sa=abs(mid-a)
  if(sa<b):
    b=sa
    res=i
print(res)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
a_str = input().split()
a = np.zeros(N)

for i in range(N):
  a[i] = int(a_str[i])

mu = np.average(a)
diff = a - mu
abs_diff = np.abs(diff)

min = np.amin(abs_diff)
index = np.where(abs_diff == min)

print(index[0][0])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
#S = str(input())
a = list(map(int, input().split()))

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

index = 0
absX = sys.maxsize
for i in range(N) :
  if absX > abs(ave - a[i]) :
    absX = abs(ave - a[i])
    index = i
    
print (index)

Submission status: Accepted

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