Problem:


Score : 200 points

Problem Statement

Niwango-kun is an employee of Dwango Co., Ltd.

One day, he is asked to generate a thumbnail from a video a user submitted.

To generate a thumbnail, he needs to select a frame of the video according to the following procedure:

Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video.

Select t-th frame whose representation a_t is nearest to the average of all frame representations.

If there are multiple such frames, select the frame with the smallest index.

Find the index t of the frame he should select to generate a thumbnail.

Constraints

1 \leq N \leq 100

1 \leq a_i \leq 100

All numbers given in input are integers

Input

Input is given from Standard Input in the following format:

N
a_{0} a_{1} ... a_{N-1}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

1

Since the average of frame representations is 2, Niwango-kun needs to select the index 1, whose representation is 2, that is, the nearest value to the average.

Sample Input 2

4
2 5 2 5

Sample Output 2

0

The average of frame representations is 3.5.

In this case, every frame has the same distance from its representation to the average.

Therefore, Niwango-kun should select index 0, the smallest index among them.



Sample input:
3
1 2 3


Sample output:
1

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

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

ave = sum(a) / n
ans = 0
diff = abs(a[ans] - ave)
for i in range(1, 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()))
sum=0
for i in range(N):
    sum+=a[i]
ave=sum/N
ans=-1
min=100
for i in range(N):
    if min > abs(a[i]-ave):
        ans=i
        min=abs(a[i]-ave)
print(str(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
*a,=map(int,input().split())
m=sum(a)/n
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: Accepted

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: Accepted

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

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split(' ')))

    A_average = sum(A) / N
    result = sorted(range(N), key=lambda i: abs(A[i] - A_average))

    print(result[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
N = int(input())
ls_a  = list(map(int,input().split()))
avg = sum(ls_a)/N
min_l = 1e+6
for i,a in enumerate(ls_a):
    if abs(a-avg)<min_l:
        min_l = abs(a-avg)
        min_idx = i
print (min_idx)

Submission status: Accepted

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

from statistics import mean
M = mean(A)
A = [abs(a - M) for a in A]

ans = 0
cur = float('inf')
for i, v in enumerate(A):
    if cur > v:
        ans = i
        cur = v


print(ans)

Submission status: Accepted

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

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

av = sum/len(A)
ans = 0
dis = 10000000

for i in range(len(A)):
    if abs(A[i]-av) < dis:
        dis = abs(A[i]-av)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mid = float(sum(a)/n)
mi = 0
for i in range(1, n):
	if abs(mid - a[i]) < abs(mid - a[mi]):
		mi = i
print(mi)

Submission status: Accepted

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

Submission status: Accepted

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

ans=N
min_=10**12
for i,x in enumerate(arr):
    if abs(mean-x)<min_:
        min_=abs(mean-x)
        ans=i
print(ans)

Submission status: Accepted

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

x = sum(a) / len(a)
y = 100

for i in range(len(a)):
    if abs(a[i]-x) < y:
        result = i
        y = abs(a[i]-x)

print(result)

Submission status: Accepted

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

Submission status: Accepted

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: Accepted

Solution code:
from statistics import mean, median,variance,stdev
# S = input()
n = int(input())
# N, K = map(int, input().split())
a = list(map(int, input().split()))
# LR = [list(map(int, input().split())) for _ in range(M)]

ans = 0

s = sum(a)
N = len(a)
mean = s / N

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

print(ans)

Submission status: Accepted

Solution code:
from statistics import mean

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

avg = mean(A)

mini = 0
mind = 101

for i in range(N):
    if abs(A[i] - avg) < mind:
        mini = i
        mind = abs(A[i] - avg)

print(mini)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
an = list(map(int, input().split()))

ave = sum(an)/len(an)

an2 = {i:abs(a-ave) for i,a in enumerate(an)}

ans,val = sorted(an2.items(), key=lambda x: x[1])[0] 

print(ans)

Submission status: Accepted

Solution code:
from sys import stderr, setrecursionlimit
from functools import reduce
from operator import add
from statistics import mean
setrecursionlimit(2147483647)
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n = int(input())
a = f()
m = mean(a)
min_ = 5000000000
ans = 0
for i, v in enumerate(a):
    if abs(v-m) < min_:
        min_ = abs(v-m)
        ans = i
print(ans)

Submission status: Accepted

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

me=A.mean()
min_diff=99999999999999999999999999999999999
for num,i in enumerate(A):
    diff=abs(me-i)
    if diff<min_diff:
        out=num
        min_diff=diff

print(out)

Submission status: Accepted

Solution code:
N = int(input())
a_list = [int(elem) for elem in input().split()]

avg_a = sum(a_list) / N

min_dist = float('inf')
idx = -1
for i, a in enumerate(a_list):
    dist = abs(a - avg_a)
    if min_dist > dist:
        idx = i
        min_dist = dist
    elif min_dist == dist and i < idx:
        idx = i

print(idx)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = sum(A)
for i in range(N):
    A[i] *= N
mi = float("inf")
imi = 0
for i, a in enumerate(A):
    if abs(a-s) < mi:
        imi = i
        mi = abs(a-s)
print(imi)

Submission status: Accepted

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

tar = total / n

d = tar
ans = 0
for i in range(n):
    k = abs(tar - a[i])
    if(k < d):
        d = k
        ans = i

print(ans)

Submission status: Accepted

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

avg = sum(a) / n
ans = -1
tmp = 1e10

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

print(ans)

Submission status: Accepted

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

ans = 0
diff = abs(a[0] - mean)
for i in range(1,N):
    if diff > abs(a[i] - mean):
        diff = abs(a[i] - mean)
        ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
a = list(map(int, input().split()))
b = np.array([abs(N * a[i] - sum(a)) for i in range(N)])
print(b.argmin())

Submission status: Accepted

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

idx = -1
mindiff = 100
ave = sum(a) / N
for i, ai in enumerate(a):
   diff = (ai - ave) if ai > ave else (ave - ai)
   if diff < mindiff:
       idx = i
       mindiff = diff

print(idx)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
a = [int(m) for m in a]
b = sum(a) / n
bli = []
for i in range(n):
    bli.append([abs(b - a[i]), i])
bli.sort()
print(bli[0][1])

Submission status: Accepted

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


def main():
    n = int(input())
    a = list(map(int, input().split()))
    diff = float('inf')
    ans = 0
    ave = sum(a) / n

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
S=sum(a)
b=[abs(N*a[i]-S) for i in range(N)]
L=[]
m=min(b)
for i in range(N):
    if b[i]==m:
        L.append(i)
print(min(L))

Submission status: Accepted

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

avg = sum(a) / N
near = None
near_n = float("inf")

for i, x in enumerate(a):
    if abs(avg - x) < near_n:
        near = i
        near_n = abs(avg - x)

print(near)

Submission status: Accepted

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

ave = sum(a) / len(a)
idx = -1
d = float('inf')
for i in range(n):
    t = abs(a[i] - ave)
    if t < d:
        d = t
        idx = i

print(idx)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
tyu = sum(A)/N
ans = [0] * N
for i in range(N):
    ans[i] = abs(tyu-A[i])
print(ans.index(min(ans)))

Submission status: Accepted

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

ava = sum(a) / n

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

mina = min(a)
for i in range(n):
    if a[i] == mina:
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ave = np.sum(a)/n
x = np.abs(a-ave)
m = np.min(x)
for i,s in enumerate(x):
    if s==m:
        print(i)
        sys.exit()

Submission status: Accepted

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

sum = sum(a)
min = 100000
ans = 0
for i in range(len(a)):
    if abs(a[i] * n - sum) < min:
        ans = i
        min = abs(a[i] * n - sum)

print(ans)

Submission status: Accepted

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


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

    ave = sum(a) / n
    ans, k = 0, 500
    for i in range(n):
        if abs(a[i]-ave) < k:
            ans = i
            k = abs(a[i]-ave)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ave = sum(a)/N

bestId = 0
bestScore = abs(a[0]-ave)
for i in range(1,N):
    score = abs(a[i]-ave)
    if bestScore>score:
        bestId=i
        bestScore = score
print(bestId)

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()
m = sum(A) / N

print(sorted([(abs(a-m), i) for i, a in enumerate(A)])[0][1])

Submission status: Accepted

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

avg = sum(A) / n

ans = 0
m = A[0]

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
from statistics import mean, median,variance,stdev
n = int(input())
l = list(map(int,input().split(" ")))
m = mean(l)
d = 1000
ans = 10000
for i in range(n):
    a = l[i]
    t = abs(m - a)
    if t < d:
        d = t
        ans = i
print(ans)

Submission status: Accepted

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

p = sum(A)/N

q = 10*9
for i in range(N) :
    r = abs(A[i] - p)
    if r < q :
        q = r
        ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
ave=sum(A)/len(A)
dif=abs(A[0]-ave)
idx=0
for i,a in enumerate(A):
    if abs(a-ave)<dif:
        dif=abs(a-ave)
        idx=i
print(idx)

Submission status: Accepted

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

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

num = float('inf')
ans = 0
for i in range(n-1, -1, -1):
    if num >= abs(k - a[i] * n):
        num = abs(k - a[i] * n)
        ans = i

print(ans)

Submission status: Accepted

Solution code:
def solve(N, As):
    avg = sum(As) / N
    return min([(abs(c - avg), i) for i, c in enumerate(As)])[1]

if __name__ == "__main__":
    N = int(input())
    As = [int(c) for c in input().split()]
    print(solve(N, As))

Submission status: Accepted

Solution code:
N = input()
a = [int(ai) for ai in input().split()]
m = sum(a) / len(a)
index = 0
min_diff = float('inf')
for i, ai in enumerate(a):
    diff = abs(m - ai)
    if diff < min_diff:
        index = i
        min_diff = diff
print(index)

Submission status: Accepted

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

ans = 0

ave = sum(A)/N

min1 = float(max(A))
for i in range(N):
    diff = abs(float(A[i]) - ave)

    if min1 > diff:
        ans = i
        min1 = diff

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
avg = sum(A) / N
ansi = None
ansv = float('inf')
for i, a in enumerate(A):
  d = abs(a-avg)
  if d < ansv:
    ansi = i
    ansv = d
print(ansi)

Submission status: Accepted

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

avgA = sum(A) / len(A)
diffA = [abs(a - avgA) for a in A]
mindiffA = min(diffA)
print(diffA.index(mindiffA))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split(" ")))
b = [(0,0)]*N
k = sum(a) / N

for i in range(N):
    b[i] = (abs(a[i]-k),i)
b.sort()
print(b[0][1])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(float, input().split(' '))))
a -= a.mean()
a = abs(a)
print(list(a).index(a.min()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
S = sum(A)
min_res = S * N
ans = -1
for i, a in enumerate(A):
    if abs(N * a - S) < min_res:
        ans = i
        min_res = abs(N * a - S)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))

frame = 0
d = 1000
a_mean = sum(a_list)/n
for i in range(n):
    if abs(a_mean-a_list[i]) < d:
        frame = i
        d = abs(a_mean-a_list[i])
print(frame)

Submission status: Accepted

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

m = sum(a_list) / N
res = 0
d = 2000
for i in range(N):
    if abs(a_list[i] - m) < d:
        res = i
        d = abs(a_list[i] - m)
print(res)

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
s = sum(a)
d = 10000000
ans = 0
for i, x in enumerate(a):
    t = abs(x * n - s)
    if d > t:
        d = t
        ans = i
print ans

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import fractions
n = int(input())
a = list(map(fractions.Fraction, input().split()))
avg = sum(a) / n
_, i = min([ (abs(a[i] - avg), i) for i in range(n) ])
print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

M = sum(A) / N
B = sorted([((A[_] - M)**2, _) for _ in range(N)])
print(B[0][1])

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split()))
ave = 0
for e in arr:
    ave += e
ave /= n
res = 0
by = ave
for i, e in enumerate(arr):
    if abs(ave - e) < by:
        by = abs(ave - e)
        res = i

print(res)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

ave = sum(a)/n

diff = 10**18
thum = -1
for i, ai in enumerate(a):
    if abs(ai-ave) < diff:
        diff = abs(ai-ave)
        thum = i

print(thum)

Submission status: Accepted

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

B=[(abs(A[i]-MID),i) for i in range(N)]
B.sort()

print(B[0][1])

Submission status: Accepted

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

ave = sum(a) / n
ret = 0
hoge = 1e9

for i in range(n):
    tmp = abs(ave - a[i])
    if  tmp < hoge:
        ret = i
        hoge = tmp

print(ret)

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
S = sum(A)
v = 10**18; p = None
for i, a in enumerate(A):
    if abs(S - a*N) < abs(S - v*N):
        v = a
        p = i
print(p)

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int, input().split()))
mean = sum(nums) / n
delta = float('inf')
ans = 0
for i, v in enumerate(nums):
  if abs(mean - v) < delta:
    ans = i
    delta = abs(mean - v)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

choose = 0
dist = abs(A[0] - av)
for i in range(1, N):
    if abs(A[i]-av) < dist:
        choose = i
        dist = abs(A[i]-av)
print(choose)

Submission status: Accepted

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

ans = min_d = 10**10
for i,a in enumerate(A):
    d = abs(ave - a)
    if d < min_d:
        min_d = d
        ans = i
print(ans)

Submission status: Accepted

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

min_i = 0
min_v = float('inf')

for i,v in enumerate(a):
    if abs(v-m) < min_v:
        min_i = i
        min_v = abs(v-m)
print(min_i)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().strip().split()]
pos = -1
m = 10000
avg = sum(a) / n
for i in range(n):
    if abs(a[i]-avg) < m:
        pos = i
        m = abs(a[i]-avg)
print(pos)

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

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

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

dist = 1e9
for i, a in enumerate(As):
    d = abs(a - avg)
    if d < dist:
        dist = d
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    av = 1.0 * sum(a) / len(a)
    m = inf
    mi = -1
    for i in range(n):
        c = a[i]
        t = abs(c-av)
        if m > t + eps:
            m = t
            mi = i

    return mi


print(main())

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

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: Runtime Error

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

s=sum(a)
ans=0
diff=abs(s-a[0]*n)
for i in range(len(a)):
  if diff<abs(s-a[i]*n):
    diff= abs(s-a[i]*n)
    ans=i
print(i)

Submission status: Runtime Error

Solution code:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int sum = 0;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }
    int dif = INF;
    int res = N - 1;
    for(int i = N - 1; i >= 0; i--) {
        if(abs(A[i] * N - sum) <= dif) {
            dif = abs(A[i] * N - sum);
            res = i;
        }
    }
    cout << res << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
def main():
    import numpy as np
    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: Runtime Error

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: Runtime Error

Solution code:
from itertools import accumulate,combinations
n,k = map(int,input().split())
a = list(map(int,input().split()))
acc = [0]+list(accumulate(a))
ls = []
for i,j in combinations(acc,2):
  ls.append(j-i)
x = max(ls).bit_length()
ans = 0
for i in range(x-1,-1,-1):
  cnt = 0
  for j in ls:
    if ans+2**i & j == ans+2**i:
      cnt += 1
  if cnt >= k:
    ans += 2**i
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
m = np.mean(a)
ans = 0
mx = 999999
for i in range(n):
  if abs(a[i] - m) < dist:
    dist = abs(a[i] - m)
    ans = i
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
ave = A/N
ans = 0
sa = 10**9
for i in range(N):
    t = i+1
    x = max(A[i]-ave,ave-A[i])
    if x < sa:
        sa = x
        ans = t
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
heikin=sum(A)/N
kouho = []

if heikin in A:
    print(A.index(heikin))
else:
    for i in A:
        kouho.append(abs(heikin-i))
    ans = kouho.copy()
    ans.sort()
print(kouho.index(ans[0]))

Submission status: Runtime Error

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

b = []
s = int(sum(a)/len(a))
for i in range(len(a)):
    b.append(abs(a[i]-s)

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

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split());print(asorted((abs(a[i]-sum(a)/n),i)for i in range(n))[0][1])

Submission status: Runtime Error

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

S = sum(A)
d = 10**14
for i, a in enumerate(A):
  if abs(a*N-S) < d:
    d = abs(a*N-S)
    ind = i
    
print(ind)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
average = sum(a) / N
A = list(map(lambda n:abs(n-average), a))
A.sort()
A1 = int(average - A[0])
A2 = int(average + A[0])
print(min(a.index(A1), a.index(A2)))

Submission status: Runtime Error

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

mean = sum(flame_list)

if mean % 2 == 0:
  print(flame_list.index(mean//2))
else:
  print(min(flame_list.index((mean-1)//2),flame_list.index((mean+1)//2)))

Submission status: Runtime Error

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

sum = 0


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

avg = sum /n

min = avg

for i in range(n):
  difference = abs(framelist[i]-avg)
  if min>difference:
    min = difference
    
print(framelist.index(difference))

Submission status: Runtime Error

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

num=0
a_sum=[0]
for i in range(N):
  num+=a[i]
  a_sum.append(num)
  

a_mat=[[0 for i in range(N)] for j in range(N)]
non_zero=[]
for i in range(N):
  for j in range(i,N):
    a_mat[i][j] = a_sum[j+1]-a_sum[i]
    non_zero.append([i,j])

a_mat2=copy.deepcopy(a_mat)

maxbit=1
while True:
  if a_sum[N]<2**maxbit and a_sum[N]>=2**(maxbit-1): 
    break
  else:
    maxbit+=1
maxnum=0
num_rest=int(N*(N+1)/2)
num_rest_now=int(N*(N+1)/2)
for bit in range(maxbit):
  non_zero2=[]
  for i, j in non_zero:
    if a_mat[i][j]&(2**(maxbit-bit-1)) == 0 and a_mat[i][j]!=0:
      num_rest_now-=1
      a_mat2[i][j]=0
    else:
      non_zero2.append([i,j])
  #print(non_zero)
  #print(a_mat)
  #print(num_rest_now)
  
  if num_rest_now >= K:
    maxnum+=2**(maxbit-bit-1)
    a_mat=copy.deepcopy(a_mat2)
    num_rest=num_rest_now
    non_zero=copy.deepcopy(non_zero2)
  else:
    a_mat2=copy.deepcopy(a_mat)
    num_rest_now=num_rest
    
  
  
print(maxnum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
sums = sum(A)/N
avg = round(sums)
avg2 = avg-1 if avg == math.ceil(sums) else avg+1

result = 0
for i in range(N):
    if A[i] == avg:
        result = i
        break
    if A[i] == avg2:
        result = i
print(result)

Submission status: Runtime Error

Solution code:
from itertools import accumulate, combinations
N, K = map(int, input().split())
A = list(map(int, input().split()))

SA = list(accumulate(A)) + [0]
B = A[:]

for l, r in combinations(range(N), 2):
    B.append(SA[r] - SA[l-1])

ans = 0
for i in range(42, -1, -1):
    ans *= 2
    B1 = [b for b in B if 2**i & b]
    if len(B1) >= K:
        ans += 1
        B = B1[:]

print(ans)