Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m = map(int,input().split())
l = [[] for i in range(n+1)]
rl = [0 for i in range(n+1)]
for i in range(m):
    u,v = map(int,input().split())
    l[u].append(v)
s,t = map(int,input().split())
d = deque()
d.append([s,0])
rl[s] = 1
ans = -1
def kkp(l,rl,now,d,c,t):
    for i in l[now]:
        for j in l[i]:
            for k in l[j]:
                #print(k,now,c)
                if k == t:
                    return c+1
                else:
                    if rl[k] == 0:
                        d.append([k,c+1])
                        rl[k] = 1
    return 0
while len(d):
    now,c = d.popleft()
    if m == 0:
        break
    else:
        if kkp(l,rl,now,d,c,t) > 0:
            ans =  kkp(l,rl,now,d,c,t)
            break
print(ans)

Fixed submission:
from collections import deque
n,m = map(int,input().split())
l = [[] for i in range(n+1)]
rl = [[-1 for i in range(n+1)] for i in range(3)]
for i in range(m):
    u,v = map(int,input().split())
    l[u].append(v)
s,t = map(int,input().split())
d = deque()
ans = -1
d.append([s,0])
rl[0][s] = 0
while len(d):
    now,count = d.popleft()
    for i in l[now]:
        if i == t and count % 3 == 2:
            ans = (count + 1)//3
            break
        else:
            if rl[(count%3 + 1)%3][i] == -1:
                d.append([i,count+1])
                rl[(count%3+1)%3][i] = count+1
    if ans >= 0:
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m = map(int,input().split())
l = [[] for i in range(n+1)]
rl = [0 for i in range(n+1)]
for i in range(m):
    u,v = map(int,input().split())
    l[u].append(v)
s,t = map(int,input().split())
d = deque()
d.append([s,0])
rl[s] = 1
ans = -1
def kkp(l,rl,now,d,c,t):
    for i in l[now]:
        for j in l[i]:
            for k in l[j]:
                #print(k,now,c)
                if k == t:
                    return c+1
                else:
                    if rl[k] == 0:
                        d.append([k,c+1])
                        rl[k] = 1
    return 0
while len(d):
    now,c = d.popleft()
    if m == 0:
        break
    else:
        if kkp(l,rl,now,d,c,t) > 0:
            ans =  kkp(l,rl,now,d,c,t)
            break
print(ans)

Fixed submission:
from collections import deque
n,m = map(int,input().split())
l = [[] for i in range(n+1)]
rl = [[-1 for i in range(n+1)] for i in range(3)]
for i in range(m):
    u,v = map(int,input().split())
    l[u].append(v)
s,t = map(int,input().split())
d = deque()
ans = -1
d.append([s,0])
rl[0][s] = 0
while len(d):
    now,count = d.popleft()
    for i in l[now]:
        if i == t and count % 3 == 2:
            ans = (count + 1)//3
            break
        else:
            if rl[(count%3 + 1)%3][i] == -1:
                d.append([i,count+1])
                rl[(count%3+1)%3][i] = count+1
    if ans >= 0:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
dp = [0 for i in range(max(n,m))]
mod = 10**9+7
if n > m:
    a = s
    b = t
else:
    a = t
    b = s
    c = copy.copy(n)
    n = copy.copy(m)
    m = copy.copy(c)
l = []
for i in range(m):
    now = b[i]
    bl = []
    for j in range(n):
        if now == a[j]:
            bl.append(j)
    l.append(bl)
for i in range(m):
    if len(l[i]) > 0:
        dp2 = copy.copy(dp)
        now1 = 0
        k = 0
        k1 = len(l[i])
        count = 0
        while k < k1:
            if now1 == l[i][k]:
                dp[now1] += 1
                dp[now1] += count
                dp[now1] %= mod
                k += 1
            count += dp2[now1]
            count %= mod
            now1 += 1
        #print(dp)
print((sum(dp)+1)%mod)

Fixed submission:
import copy
n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
dp = [0 for i in range(max(n,m))]
mod = 10**9+7
if n > m:
    a = s
    b = t
else:
    a = t
    b = s
    c = copy.copy(n)
    n = copy.copy(m)
    m = copy.copy(c)
l = []
for i in range(m):
    now = b[i]
    bl = []
    for j in range(n):
        if now == a[j]:
            bl.append(j)
    l.append(bl)
for i in range(m):
    if len(l[i]) > 0:
        dp2 = copy.copy(dp)
        now1 = 0
        k = 0
        k1 = len(l[i])
        count = 0
        while k < k1:
            if now1 == l[i][k]:
                dp[now1] += 1
                dp[now1] += count
                dp[now1] %= mod
                k += 1
            count += dp2[now1]
            count %= mod
            now1 += 1
        #print(dp)
print((sum(dp)+1)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
l = []
r = []
count = 0
def check(a,b,c):
    if a >= max(b) and a <= min(c):
        return 1
    else:
        return 0
for i in range(m):
    l0,r0 = map(int,input().split())
    l.append(l0)
    r.append(r0)
for y in range(n+1):
    count = count + check(y,l,r)
print(count)

Fixed submission:
n,m = map(int,input().split())
l = []
r = []
for i in range(m):
    l0,r0 = map(int,input().split())
    l.append(l0)
    r.append(r0)
ans = min(r)-max(l)+1
if ans >= 0:
    print(ans)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,input().split()))
l = []
for i in range(m):
    bc = list(map(int,input().split()))
    l.append(bc)
l.sort(key=lambda x:x[1],reverse=True)
a.sort()
b = 0
for i in range(m):
    count = 0
    while a[b] < l[i][1] and count < l[i][0]:
        a[b] = l[i][1]
        b = b + 1
        count = count + 1
    if i < m-1:
        if a[b] >= l[i+1][1]:
            break
print(sum(a))

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
l = []
for i in range(m):
    bc = list(map(int,input().split()))
    l.append(bc)
l.sort(key=lambda x:x[1],reverse=True)
a.sort()
b = 0
for i in range(m):
    count = 0
    while a[b] < l[i][1] and count < l[i][0]:
        a[b] = l[i][1]
        b = b + 1
        count = count + 1
        if b == n:
            break
    if b == n:
        break
    else:
        if i < m-1:
            if a[b] >= l[i+1][1]:
                break
print(sum(a))
Buggy python submission (verdict: Runtime Error):
s = input()
d = s.split("/")
m = int(d[1])
if m > 4:
 print("TBD")
else:
 print("Heisei")

Fixed submission:
a,b,t =(int(x) for x in input().split())
c = t//a
print(c*b)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
import functools
import math

n = int(input())
a = list(map(int,input().split()))
l = []
m = []
l.append(0)
m.append(0)
for i in range(n):
    l.append(math.gcd(l[i],a[i]))
    m.append(math.gcd(m[i],a[-(i+1)]))
b = [math.gcd(l[i],m[-(i+2)]) for i in range(n)]
print(max(b))

Fixed submission:
import fractions
n = int(input())
a = list(map(int,input().split()))
l = []
m = []
l.append(0)
m.append(0)
for i in range(n):
    l.append(fractions.gcd(l[i],a[i]))
    m.append(fractions.gcd(m[i],a[-(i+1)]))
b = [fractions.gcd(l[i],m[-(i+2)]) for i in range(n)]
print(max(b))

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
import functools
import math

n = int(input())
a = [int(i) for i in input().split()]
l = []
for i in range(n):
 b = a[i]
 del a[i]
 l.append(functools.reduce(gcd, a))
 a.insert(i,b)
print(max(l))

Fixed submission:
import fractions
n = int(input())
a = list(map(int,input().split()))
l = []
m = []
l.append(0)
m.append(0)
for i in range(n):
    l.append(fractions.gcd(l[i],a[i]))
    m.append(fractions.gcd(m[i],a[-(i+1)]))
b = [fractions.gcd(l[i],m[-(i+2)]) for i in range(n)]
print(max(b))

Buggy python submission (verdict: Runtime Error):
import functools
import math

n = int(input())
a = [int(i) for i in input().split()]
l = []
for i in range(n):
 b = a[i]
 del a[i]
 l.append(functools.reduce(math.gcd, a))
 a.insert(i,b)
print(max(l))

Fixed submission:
import fractions
n = int(input())
a = list(map(int,input().split()))
l = []
m = []
l.append(0)
m.append(0)
for i in range(n):
    l.append(fractions.gcd(l[i],a[i]))
    m.append(fractions.gcd(m[i],a[-(i+1)]))
b = [fractions.gcd(l[i],m[-(i+2)]) for i in range(n)]
print(max(b))
Buggy python submission (verdict: Runtime Error):
a,b = int(input().split())
print(max(a + b, a*2 - 1, b*2 - 1))

Fixed submission:
a,b =map(int,input().split())
print(max(a + b, a*2 - 1, b*2 - 1))
Buggy python submission (verdict: Runtime Error):
 = list(input())
count = 0
n = len(s)
if n % 2 == 0:
    for i in range(0,int((n/2)-1)):
        if s[(2*i)+1] == "0":
            count = count + 1
    for i in range(0,int((n/2)-1)):
        if s[2*i] == "1":
            count = count + 1
else:
    for i in range(0,int((n-1)/2)):
        if s[2*i] == "0":
            count = count + 1
    for i in range(0,int(((n-1)/2)-1)):
        if s[2*i + 1] == "1":
            count = count + 1
count2 = n - count
print(min(count,count2))

Fixed submission:
s = list(input())
count = 0
n = len(s)
if n % 2 == 0:
    for i in range(0,int(n/2)):
        if s[(2*i)+1] == "0":
            count = count + 1
    for j in range(0,int(n/2)):
        if s[2*j] == "1":
            count = count + 1
else:
    for i in range(0,int((n-1)/2)+1):
        if s[2*i] == "0":
            count = count + 1
    for j in range(0,int(((n-1)/2))):
        if s[2*j + 1] == "1":
            count = count + 1
count2 = n - count
print(min(count,count2))
Buggy python submission (verdict: Runtime Error):
a,b,c,d,e = [int(input()) for i in range(5)]
count = a + b + c + d + e
l = [a%10,b%10,c%10,d%10,e%10]
s = [a%10,b%10,c%10,d%10,e%10]
m = [a%10,b%10,c%10,d%10,e%10]
for x in range(len(l)):
    if l[x] == 0:
        m.remove(0)
for i in range (len(s)):
    count = count -s[i]
ans = count + 10*len(m) + min(m) -10
print(ans)

Fixed submission:
a,b,c,d,e = [int(input()) for i in range(5)]
count = a + b + c + d + e
l = [a%10,b%10,c%10,d%10,e%10]
s = [a%10,b%10,c%10,d%10,e%10]
m = [a%10,b%10,c%10,d%10,e%10]
for x in range(len(l)):
    if l[x] == 0:
        m.remove(0)
for i in range (len(s)):
    count = count -s[i]
if len(m) == 0:
    ans= count
    print(ans)
else:
    ans = count + 10*len(m) + min(m) -10
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = list(input())
l = []
p = []
for i in range(n-1):
        if s[i] == "A" and s[i+1] == "C":
                l.append(i+1)
for j in range(q):
        k,t = map(int,input().split())
        b = len([1 for x in l if x >= k and x < t])
        p.append(b)
for i in range(len(p)):
        print(p[i])

Fixed submission:
n,q = map(int,input().split())
s = list(input())
l = [0]*(n)
for i in range(n-1):
        if s[i] == "A" and s[i+1] == "C":
                l[i+1] = l[i] + 1
        else:
                l[i+1] = l[i]  
for j in range(q):
        k,t = map(int,input().split())
        print(l[t-1] - l[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = list(input())
t = []

for i in range(q):
    l,r = map(int,input().split())
    s1 = s[l-1:r]
    s2 = "".join(s1)
    t1 = s2.count("AC")
    t.append(t1)
for x in range(len(t)):
        print(t[x])

Fixed submission:
n,q = map(int,input().split())
s = list(input())
l = [0]*(n)
for i in range(n-1):
        if s[i] == "A" and s[i+1] == "C":
                l[i+1] = l[i] + 1
        else:
                l[i+1] = l[i]  
for j in range(q):
        k,t = map(int,input().split())
        print(l[t-1] - l[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = list(input())
t = []
for i in range(q):
    l,r = map(int,input().split())
    s1 = s[l-1:r]
    count = 0
    for x in range(len(s1)-1):
        if s1[x] ==  "A" and s1[x+1] == "C":
            count = count + 1
    t.append(count)
for j in range(len(t)):
    print(t[j])

Fixed submission:
n,q = map(int,input().split())
s = list(input())
l = [0]*(n)
for i in range(n-1):
        if s[i] == "A" and s[i+1] == "C":
                l[i+1] = l[i] + 1
        else:
                l[i+1] = l[i]  
for j in range(q):
        k,t = map(int,input().split())
        print(l[t-1] - l[k-1])
Buggy python submission (verdict: Runtime Error):
s = input()
day = (s.split("/"))
if int(day[1]) <= "4":
 print("Heisei")
else:
 print("TBD")


Fixed submission:
s = input()
day = (s.split("/"))
if int(day[1]) <= 4:
 print("Heisei")
else:
 print("TBD")

Buggy python submission (verdict: Runtime Error):
s = input()
d = s.split("/")
if day[1] > 4:
 print("TBD")
else:
 print("Heisei")

Fixed submission:
s = input()
day = (s.split("/"))
if int(day[1]) <= 4:
 print("Heisei")
else:
 print("TBD")
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
count = 0
for x in range(n):
 if v[x] > c[x]:
  count = count + v[x] - c[x]
print(count)

Fixed submission:
n = int(input())
money = 0
for i in range(n):
    x,u = input().split()
    if u == "JPY":
        x = int(x)
        money = money + x
    else:
        x = float(x)
        money = money + x*380000
print(money)

Buggy python submission (verdict: Runtime Error):
n = int(input())
v = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
count = 0
for x in range(n):
 if v[x] > c[x]:
  count = count + v[x] - c[x]
print(count)

Fixed submission:
n = int(input())
money = 0
for i in range(n):
    x,u = input().split()
    if u == "JPY":
        x = int(x)
        money = money + x
    else:
        x = float(x)
        money = money + x*380000
print(money)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(n-2):
    g = math.gcd(g,a[i+2])
print(g)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
g = gcd(a[0],a[1])
for i in range(n-2):
    g = gcd(g,a[i+2])
print(g)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
for i in range(1,n):
    l = []
    for j in range(1,min(len(dp),k)+1):
        l.append(dp[i-j] + abs(h[i]-h[i-j]))
    dp.append(min(l))
print(dp[n-1])

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
for i in range(1,n):
    l = []
    for j in range(1,min(len(dp),k)+1):
        l.append(dp[i-j] + abs(h[i]-h[i-j]))
    dp.append(min(l))
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0
for i in range(1,n+1):
    count = count + i*i
print(count)

Fixed submission:
import math
x,y = map(int,input().split())
if x%y == 0:
    print(-1)
else:
    print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    b.append(a[i])
    b.reverse()
for i in b:
    print(i,end=" ")

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = []
if n % 2 == 0:
    for i in range(n//2):
        b.append(a[n-2*i-1])
    for i in range(n//2):
        b.append(a[2*i])
else:
    for i in range((n-1)//2):
        b.append(a[n-2-2*i])
    for i in range((n-1)//2):
        b.append(a[i*2])
    b.append(a[n-1])
    b.reverse()
for i in b:
    print(i,end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mod = 10**9 + 7
a = list(map(int,input().split()))
il = [[]for i in range(n)]
for i in range(n+1):
    il[a[i]-1].append(i)
    if len(il[a[i]-1]) > 1:
        p,q = il[a[i]-1]
comb = 1
comb2 = 1
c = p + n - q
for i in range(n+1):
    comb = comb*(n+1-i)//(i+1)
    if c >= i:
        print((comb-comb2)%mod)
        comb2 = comb2*(c-i)//(i+1)
    else:
        print(comb%mod)

Fixed submission:
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod + x % mod)% mod
n = int(input())
mod = 10**9 + 7
a = list(map(int,input().split()))
il = [[]for i in range(n)]
for i in range(n+1):
    il[a[i]-1].append(i)
    if len(il[a[i]-1]) > 1:
        p,q = il[a[i]-1]
comb = 1
comb2 = 1
c = p + n - q
for i in range(n+1):
    comb = (((comb*(n+1-i))%mod)*mod_inv(i+1,mod))%mod
    if c >= i:
        print((comb-comb2)%mod)
        comb2 = (((comb2*(c-i))%mod)*mod_inv(i+1,mod))%mod
    else:
        print(comb%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
l = []
for i in range(n):
    a,b = map(int,input().split())
    l1 = [a]*b
    l = l + l1
l.sort()
print(l[k-1])

Fixed submission:
n,k = map(int,input().split())
l = []
for i in range(n):
    a = list(map(int,input().split()))
    l.append(a)
l.sort(key=lambda x:x[0])
count = 0
i = 0
while count < k:
    count = count + l[i][1]
    i = i + 1
print(l[i-1][0])
Buggy python submission (verdict: Runtime Error):
n,t = map(int,input().split())
a = list(map(int,input().split()))
l = []
count = 0
for i in range(n-1):
    if a[i] <= a[i+1]:
        count = count + a[i+1] - a[i]
    else:
        l.append(count)
        count = 0
l.append(count)
l.remove(0)
d = max(l)
ans = l.count(d)
print(ans)

Fixed submission:
n,t = map(int,input().split())
a = list(map(int,input().split()))
mn = a[0]
l = []
for i in range(n-1):
    if a[i] < a[i+1]:
        l.append(a[i+1]-mn)        
    if a[i+1] < mn:
        mn = a[i+1]
if len(l) > 0:
    d = max(l)
ans = l.count(d)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,a = map(int,input().split())
x = list(map(int,input().split()))
dp = []
for i in range(n+1):
    dp.append([[] for j in range(i+1)])
    for k in range(i+1):
        dp[i][k] = [0 for y in range(50*k)]
for i in range(n+1):
        dp[i][0].append(0)
for i in range(1,n+1):
    for j in range(1,i+1):
        if j == 1:
                dp[i][j][x[i-1]-1] += 1
        for k in range(len(dp[i-1][j-1])):
                dp[i][j][k+x[i-1]] += dp[i-1][j-1][k]
                dp[i][j-1][k] += dp[i-1][j-1][k]
count = 0
for j in range(1,i+1):
        for k in range(len(dp[i][j])):
                if k + 1 == j*a:
                        count += dp[n][j][k]
print(count)

Fixed submission:
n,a = map(int,input().split())
x = list(map(int,input().split()))
dp = []
for i in range(n+1):
    dp.append([[] for j in range(i+1)])
    for k in range(i+1):
        dp[i][k] = [0 for y in range(50*k)]
for i in range(n+1):
        dp[i][0].append(0)
for i in range(1,n+1):
    for j in range(1,i+1):
        if j == 1:
                dp[i][j][x[i-1]-1] += 1
        for k in range(50*(j-1)):
                dp[i][j][k+x[i-1]] += dp[i-1][j-1][k]
                dp[i][j-1][k] += dp[i-1][j-1][k]
count = 0
for j in range(1,i+1):
        for k in range(len(dp[i][j])):
                if k + 1 == j*a:
                        count += dp[n][j][k]
print(count)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def main():
    _, K = map(int, input().split(' '))
    S = input()

    S[K - 1] = S[K - 1].lower()

    print(S)


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-

def main():
    _, K = map(int, input().split(' '))
    S = input()

    print(S[:K - 1] + S[K - 1].lower() + S[K:])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, Q = map(int, input().split(' '))
S = input()
len_S = len(S)

flags = [0] * len_S
AC = ('A', 'C')
for i, v in enumerate(zip(S[:-1], S[1:])):
  flags[i + 1] = 1 if v == AC else 0

sums = list(np.cumsum(flags))

for _ in range(Q):
  l, r = map(int, input().split(' '))
  print(sums[r - 1] - sums[l - 1])


Fixed submission:
import numpy as np

N, Q = map(int, input().split(' '))
S = input()
len_S = len(S)

flags = [0] * len_S
for i, v in enumerate(S[:-1]):
  if v == 'A' and S[i + 1] == 'C':
    flags[i + 1] = 1
  else:
    flags[i + 1] = 0

sums = list(np.cumsum(flags))

for _ in range(Q):
  l, r = map(int, input().split(' '))
  print(sums[r - 1] - sums[l - 1])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    S = input()
    count = 0

    while 'BW' in S:
        idx = S.index('BW')
        S = S[:idx] + 'WB' + S[idx + 2:]
        count += 1

    print(count)


Fixed submission:
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    S = input()

    W_count = S.count('W')
    idx, count, result = 0, 0, 0

    while count < W_count:
        if S[idx] == 'W':
            result += idx - count
            count += 1
        idx += 1

    print(result)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import numpy as np
import itertools

and_memo = {}


def list_subarray_sums(arr, length):
    cumsum = np.insert(np.cumsum(arr), 0, 0)
    for l in range(1, length + 1):
        for i in range(length - l + 1):
            yield cumsum[l + i] - cumsum[i]


def logical_and(arr, lenght, idx=0):
    if idx == lenght - 1:
        return arr[-1]
    if arr[idx] == 0:
        return 0

    key = tuple(arr[idx:])
    if key in and_memo:
        return and_memo[key]

    result = arr[idx] & logical_and(arr, lenght, idx + 1)
    and_memo[key] = result
    return result


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

    sums = set(list_subarray_sums(A, N))
    combinations = itertools.combinations(sums, K)
    ands = map(lambda arr: logical_and(arr, K), combinations)

    print(max(ands))


Fixed submission:
# -*- 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])

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import numpy as np
import itertools
import sys

sys.setrecursionlimit(3000)

and_memo = {}


def list_subarray_sums(arr, length):
    cumsum = np.insert(np.cumsum(arr), 0, 0)
    for l in range(1, length + 1):
        for i in range(length - l + 1):
            yield cumsum[l + i] - cumsum[i]


def logical_and(arr, lenght, idx=0):
    if idx == lenght - 1:
        return arr[-1]
    if arr[idx] == 0:
        return 0

    key = tuple(arr[idx:])
    if key in and_memo:
        return and_memo[key]

    result = arr[idx] & logical_and(arr, lenght, idx + 1)
    and_memo[key] = result
    return result


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

    sums = set(list_subarray_sums(A, N))
    combinations = itertools.combinations(sums, K)
    ands = map(lambda arr: logical_and(arr, K), combinations)

    print(max(ands))


Fixed submission:
# -*- 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])