Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

# dp[i][j]: i人目までに合計j個渡したときの場合の数
# i人目に配れるアメは0~A[i-1]個
# 例えばA[i-1]個をi人目に配っていたらi-1人目まではj-A[i-1]個を合計で配っている
# dp[i][j] = dp[i-1][j] + dp[i-1][j-1] + ... + dp[i-1][j-A[i-1]]
# 数列をずらして工夫すると
# dp[i][j-1] = dp[i-1][j-1] + dp[i-1][j-2] + ... + dp[i-1][j-A[i-1]-1]
# となるので、
# dp[i][j] - dp[i][j-1] = dp[i-1][j] - dp[i-1][j-A[i-1]-1]
# 最終的に
# dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-A[i-1]-1]


dp = [[0 for _ in range(K + 1)] for _ in range(N + 1)]
# i人目までに0個配る方法は1通り
for i in range(N + 1):
    dp[i][0] = 1

for i in range(1, N+1):
    for j in range(1, K + 1):
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j]
        # i-1人目までに渡すアメの数は0以上でなければならない
        if (j - A[i - 1] - 1) >= 0:
            dp[i][j] = dp[i][j] - dp[i - 1][j - A[i - 1] - 1]
            
print(dp[N][K]%1000000007)

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
m = 1000000007
# dp[i][j]: i人目までに合計j個渡したときの場合の数
# i人目に配れるアメは0~A[i-1]個
# 例えばA[i-1]個をi人目に配っていたらi-1人目まではj-A[i-1]個を合計で配っている
# dp[i][j] = dp[i-1][j] + dp[i-1][j-1] + ... + dp[i-1][j-A[i-1]]
# 数列をずらして工夫すると
# dp[i][j-1] = dp[i-1][j-1] + dp[i-1][j-2] + ... + dp[i-1][j-A[i-1]-1]
# となるので、
# dp[i][j] - dp[i][j-1] = dp[i-1][j] - dp[i-1][j-A[i-1]-1]
# 最終的に
# dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-A[i-1]-1]


dp = [[0 for _ in range(K + 1)] for _ in range(N + 1)]
# i人目までに0個配る方法は1通り
for i in range(N + 1):
    dp[i][0] = 1

for i in range(1, N+1):
    for j in range(1, K + 1):
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % m
        # i-1人目までに渡すアメの数は0以上でなければならない
        if (j - A[i - 1] - 1) >= 0:
            dp[i][j] = (dp[i][j] + m - dp[i - 1][j - A[i - 1] - 1]) % m
            
print(dp[N][K])
Buggy python submission (verdict: Time Limit Exceeded):
from math import pow
N, P = map(int, input().split())

def calc(n, p, x):
    return pow(p/float(x), 1/n)

for i in range(1, P+1):
    d = calc(N, P, i)
    if d.is_integer():
        print(int(d))
        break

Fixed submission:
from collections import Counter
N, P = map(int, input().split())

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            factors.append(i)
        i += 1
    if n > 1:
        factors.append(n)
    return factors

fs = Counter(prime_factors(P))

d = 1
for k, c in fs.most_common():
    if c >= N:
        for _ in range(int(c/N)):
            d *= k
print(d)
Buggy python submission (verdict: Runtime Error):
numbers = list(input())
y = 753
result = []
for i in range(len(numbers)-3):
    x = ''.join([int(x) for x in numbers[i:i+3]])
    d = abs(x-y)
    result.append(d)
print(min(result))

Fixed submission:
numbers = list(input())
y = 753
result = []
for i in range(len(numbers)-2):
    x = int(''.join(numbers[i:i+3]))
    d = abs(x-y)
    result.append(d)
print(min(result))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n, m = map(int, input().split())

city_to_pref, city_to_birth, pref_to_birth_list = {}, {}, defaultdict(list)
for i in range(m):
    pref, birth = map(int, input().split())
    city_to_pref[i] = pref
    city_to_birth[i] = birth
    pref_to_birth_list[pref].append(birth)


def get_city_index(i):
    pref = city_to_pref[i]
    birth = city_to_birth[i]
    years = pref_to_birth_list[pref]
    return years.index(birth)


def give_id(i):
    p = city_to_pref[i]
    x = get_city_index(i) + 1
    return '{:0=6}{:0=6}'.format(p, x)


for pref, births in pref_to_birth_list.items():
    pref_to_birth_list[pref] = sorted(births)

for i in range(m):
    print(give_id(i))

Fixed submission:
from collections import defaultdict, Counter
n, m = map(int, input().split())

city_to_pref, city_to_birth, pref_to_birth_list = {}, {}, defaultdict(list)
pref_counter = Counter()
city_id = {}
for i in range(m):
    pref, birth = map(int, input().split())
    city_to_pref[i] = pref
    city_to_birth[i] = birth
    pref_to_birth_list[pref].append(birth)


def get_city_index(i, pref):
    birth = city_to_birth[i]
    return pref_birth_to_id[pref][birth]


def give_id(i):
    p = city_to_pref[i]
    x = get_city_index(i, p) + 1
    return '{:0=6}{:0=6}'.format(p, x)


pref_birth_to_id = defaultdict(lambda : defaultdict(int))
for pref, births in pref_to_birth_list.items():
    for i, birth in enumerate(sorted(births)):
        pref_birth_to_id[pref][birth] = i

for i in range(m):
    print(give_id(i))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [1 if x == 'W' else 0 for x in list(input())]
print(min([sum(s[:i]) + (n-i-1) - sum(s[i+1:]) for i in range(n)]))


Fixed submission:
n = int(input())
ls = [(0, 0) for _ in range(n)]
s = list(input())
sum_ls = {}

for i in range(n):
    if i == 0:
        w = 0
        e = s[i+1:].count('E')
        sum_ls[i] = (w, e)
    else:
        _w, _e = sum_ls[i - 1]
        if s[i] == 'W':
            if s[i-1] == 'W':
                sum_ls[i] = (_w+1, _e)
            else:
                sum_ls[i] = (_w+1, _e-1)
        else:
            if s[i-1] == 'W':
                sum_ls[i] = (_w, _e)
            else:
                sum_ls[i] = (_w, _e-1)

print(min([sum(v) for v in sum_ls.values()]))
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())


def max_search(s, t):
    for i in range(s):
        if (s-i) % t == 0:
            return (s-i) // t
    return 0

a_max = max_search(a-1, x)
b_max = max_search(b, x)
if a == 0:
    b_max += 1
print(b_max-a_max)

Fixed submission:
a, b, x = map(int, input().split())
a_max = max(((a-1) // x, 0))
b_max = b // x
if a == 0:
    b_max += 1
print(b_max-a_max)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
mu = 1
for i in range(n):
    mu = mu*a[i]
if mu>10**18: print(-1)
else:
    print(mu)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mu = 1
if 0 in a:
    print(0)
else:
    fl=0
    for i in range(n):
        mu = mu*a[i]
        if mu>10**18:
            print(-1)
            fl=1
            break
    # print(mu)
    if fl==0:
        print(mu)
Buggy python submission (verdict: Runtime Error):
a,b = map(input().split())
b = b*100
print(a*b/100)

Fixed submission:
from decimal import Decimal
from fractions import Fraction
a,b = input().split()
print(int(int(a)*Fraction(b)))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(t) - 1 for t in input().split()]

loc = 0
visited_bkt = [-1 for _ in range(2 * 10 ** 5 + 1)]
count = 0
loop_len = -1
while True:
    visited_bkt[loc + 1] = count
    loc = a[loc]
    if visited_bkt[loc + 1] > 0:
        loop_len = count - visited_bkt[loc + 1] + 1
        break
    count += 1
start_len = count - loop_len
# print(visited_bkt)
# print(start_len, loop_len)
# print(start_len + (k - start_len) % loop_len if k >= count else k)
print(visited_bkt.index(start_len + (k - start_len) % loop_len) if k >= count else visited_bkt.index(k))


Fixed submission:
n, k = map(int, input().split())
a = [int(t) - 1 for t in input().split()]

loc = 0
visited_bkt = [-1 for _ in range(2 * 10 ** 5 + 1)]
count = 0
loop_len = -1
while True:
    visited_bkt[loc + 1] = count
    loc = a[loc]
    count += 1
    if visited_bkt[loc + 1] >= 0:
        loop_len = count - visited_bkt[loc + 1]
        break
start_len = count - loop_len
print(visited_bkt.index(start_len + (k - start_len) % loop_len) if k >= count else visited_bkt.index(k))

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = [int(t) - 1 for t in input().split()]

loc = 0
visited_list = []
loop_idx = -1
while True:
    visited_list.append(loc + 1)
    loc = a[loc]
    if loc + 1 in visited_list:
        loop_idx = visited_list.index(loc + 1)
        break
loop_len = len(visited_list) - loop_idx
start_len = len(visited_list) - loop_len
print(visited_list[start_len + (k - start_len) % loop_len] if k >= len(visited_list) else visited_list[k])


Fixed submission:
n, k = map(int, input().split())
a = [int(t) - 1 for t in input().split()]

loc = 0
visited_bkt = [-1 for _ in range(2 * 10 ** 5 + 1)]
count = 0
loop_len = -1
while True:
    visited_bkt[loc + 1] = count
    loc = a[loc]
    count += 1
    if visited_bkt[loc + 1] >= 0:
        loop_len = count - visited_bkt[loc + 1]
        break
start_len = count - loop_len
print(visited_bkt.index(start_len + (k - start_len) % loop_len) if k >= count else visited_bkt.index(k))
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

def bin_s(l, r, a):
    while l <= r:
        mid = l + r // 2
        if a ** 5 - mid ** 5 == x:
            return (mid, True)
        elif a ** 5 - mid ** 5 > x:
            l = mid + 1
        else:
            r = mid - 1
    return (-1, False)

def search(x: int) -> (int, int):
    a = 1
    while True:
        if a ** 5 - (a - 1)** 5 <= x <= a ** 5 + (a - 1)** 5:
            b, j = bin_s(-a + 1, a - 1, a)
            if j:
                return (a, b)
        a += 1

a, b = search(x)
print(f"{a} {b}")


Fixed submission:
x = int(input())

def search(x: int) -> (int, int):
    for a in range(-1000, 1001):
        for b in range(-1000, 1001):
            if a ** 5 - b ** 5 == x:
                return (a, b)
    return (-2000, -2000)

a, b = search(x)
print(f"{a} {b}")
Buggy python submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
req = []
[req.append(tuple(map(int, input().split()))) for _ in range(q)]
a = [0 for _ in range(m)]

def check():
    res = 0
    for i in range(q):
        ra, rb, rc, rd = req[i]
        if a[rb - 1] - a[ra - 1] == rc:
            res += rd
    return res

def set_a(idx: int, au: int):
    ans = 0
    for i in range(au, m + 1):
        a[idx] = i
        if idx + 1 < n:
            ans = max(set_a(idx + 1, i), ans)
        else:
            ans = max(check(), ans)
    return ans

print(set_a(0, 1))


Fixed submission:
n, m, q = map(int, input().split())
req = []
[req.append(tuple(map(int, input().split()))) for _ in range(q)]
a = [0 for _ in range(n)]

def check():
    res = 0
    for i in range(q):
        ra, rb, rc, rd = req[i]
        if a[rb - 1] - a[ra - 1] == rc:
            res += rd
    return res

def set_a(idx: int, au: int):
    ans = 0
    for i in range(au, m + 1):
        a[idx] = i
        if idx + 1 < n:
            ans = max(set_a(idx + 1, i), ans)
        else:
            ans = max(check(), ans)
    return ans

print(set_a(0, 1))

Buggy python submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
req = []
[req.append(tuple(map(int, input().split()))) for _ in range(q)]
a = [0 for _ in range(m)]

def check():
    res = 0
    for i in range(q):
        ra, rb, rc, rd = req[i]
        if a[rb - 1] - a[ra - 1] == rc:
            res += rd
    return res

def set_a(idx: int, au: int):
    ans = 0
    for i in range(au, m + 1):
        a[idx] = i
        if idx + 1 < n:
            ans = max(set_a(idx + 1, i), ans)
        else:
            ans = max(check(), ans)
    return ans

print(set_a(0, 0))


Fixed submission:
n, m, q = map(int, input().split())
req = []
[req.append(tuple(map(int, input().split()))) for _ in range(q)]
a = [0 for _ in range(n)]

def check():
    res = 0
    for i in range(q):
        ra, rb, rc, rd = req[i]
        if a[rb - 1] - a[ra - 1] == rc:
            res += rd
    return res

def set_a(idx: int, au: int):
    ans = 0
    for i in range(au, m + 1):
        a[idx] = i
        if idx + 1 < n:
            ans = max(set_a(idx + 1, i), ans)
        else:
            ans = max(check(), ans)
    return ans

print(set_a(0, 1))
Buggy python submission (verdict: Time Limit Exceeded):
MAX_K: int = 200

gt = [[0 for _ in range(MAX_K + 1)] for _ in range(MAX_K + 1)]

def gcd(x: int, y: int) -> int:
    ret: int = 0
    if x < y:
        ret = gcd(y, x)
    elif y == 0:
        ret = x
    elif y == 1:
        ret = 1
    else:
        ret = gcd(y, x % y)
    gt[x][y] = ret
    # print(f"gcd({x}, {y}) = {ret}")
    return ret

k = int(input())
print(sum([gcd(gcd(i + 1, j + 1), l + 1) for i in range(k) for j in range(k) for l in range(k)]))


Fixed submission:
MAX_K: int = 200

gt = [[0 for _ in range(MAX_K + 1)] for _ in range(MAX_K + 1)]

def gcd(x: int, y: int) -> int:
    if gt[x][y] > 0:
        return gt[x][y]
    ret: int = 0
    if x < y:
        ret = gcd(y, x)
    elif y == 0:
        ret = x
    elif y == 1:
        ret = 1
    else:
        ret = gcd(y, x % y)
    gt[x][y] = ret
    # print(f"gcd({x}, {y}) = {ret}")
    return ret

k = int(input())
print(sum([gcd(gcd(i + 1, j + 1), l + 1) for i in range(k) for j in range(k) for l in range(k)]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A=list(map(int, input().split())) 
ans = 1

for a in A:
    ans *= a

if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
n = int(input())
A=list(map(int, input().split())) 
ans = 1
if A.count(0) >= 1:
    print(0)
    exit()

for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        exit()
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
a=list(map(int,list(input().split())))

exist = [a[0]]
ex = {}

cnt = 1
while(True):
    if a[exist[-1]-1] in ex:
        idx = exist.index(a[exist[-1]-1])
        exist.append(a[exist[-1]-1])
        break
    exist.append(a[exist[-1]-1])
    ex[a[exist[-1]-1]] = 0
    
    cnt += 1
    if cnt >= k-1:
        print(exist[-1])
        exit()


#k = k-idx
#print(idx,exist,cnt)
d = (k-idx) % (cnt-idx)

print(exist[d+idx-1])


Fixed submission:
n,k = map(int, input().split())
a=list(map(int,list(input().split())))

exist = [1]
#exist.append(a[0])
ex = {}
ex[1] = 0
#ex[a[0]] = 0
if k == 1:
    print(a[0])
    exit()

cnt = 0
while(True):
    if a[exist[-1]-1] in ex:        
        idx = exist.index(a[exist[-1]-1])
        exist.append(a[exist[-1]-1])
        break
    ex[a[exist[-1]-1]] = 0
    exist.append(a[exist[-1]-1])
    
    cnt += 1
    if cnt-1 >= k-1:
        print(exist[-1])
        exit()


#k = k-idx
d = (k-idx) % (cnt-idx+1)

print(exist[d+idx])
Buggy python submission (verdict: Time Limit Exceeded):

import math



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

x = 1

num = math.floor(n/b)

if num == 0:
    x = n
    print(math.floor(a*x/b)-a*math.floor(x/b))
    exit()
else:
    ans = 0
    for i in range(1,num+1):
        x = b*i-1
        ans = max(ans,math.floor(a*x/b)-a*math.floor(x/b))
print(ans)

Fixed submission:

import math



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

x = 1

num = math.floor(n/b)

if num == 0:
    x = n
    print(math.floor(a*x/b)-a*math.floor(x/b))
    exit()
if num >= 100000:
    print(b-1)
    exit()
else:
    ans = 0
    for i in range(1,num+1):
        x = b*i-1
        ans = max(ans,math.floor(a*x/b)-a*math.floor(x/b))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
from collections import defaultdict
import math
import numpy as np
import re
import itertools


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

x = 1

num = math.floor(n/b)

if num == 0:
    x = n
    print(math.floor(a*x/b)-a*math.floor(x/b))
    exit()
else:
    ans = 0
    for i in range(1,num+1):
        x = b*i-1
        ans = max(ans,math.floor(a*x/b)-a*math.floor(x/b))
print(ans)


Fixed submission:

import math



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

x = 1

num = math.floor(n/b)

if num == 0:
    x = n
    print(math.floor(a*x/b)-a*math.floor(x/b))
    exit()
if num >= 100000:
    print(b-1)
    exit()
else:
    ans = 0
    for i in range(1,num+1):
        x = b*i-1
        ans = max(ans,math.floor(a*x/b)-a*math.floor(x/b))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())

for _ in range(q):
    i = list(map(str, input().split()))
    if i[0] == '1':
        s = s[::-1]
    else:
        if i[1] == '1':
            s = i[2] + s
        else:
            s = s + i[2]

print(s)

Fixed submission:
s = str(input())
q = int(input())

head = ''
back = ''
flg = 1
for _ in range(q):
    i = list(map(str, input().split()))
    if i[0] == '1':
        #head, back = back, head
        flg *= -1
    else:
        if i[1] == '1':
            if flg == 1:
                head = head + i[2]
            else:
                back = back + i[2]
        else:
            if flg == 1:
                back = back + i[2]
            else:
                head = head+ i[2]

if flg == 1:
    print(head[::-1]+s+back)
else:
    print(back[::-1]+s[::-1]+head)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
A=list(map(int, input().split()))  
num=0
for j in range(0,K):
    num += sum(range(1,A[j]+1))/A[j]  
#num = sum(A[0:K])
#ind = 0
#max_num =0
ans = num
for i in range(N-K):
    num -= sum(range(1,A[i]+1))/A[i] 
    num += sum(range(1,A[i+K]+1))/A[i+K] 
    ans = max(num,ans)


print(ans)

Fixed submission:
N,K = map(int, input().split())
A=list(map(int, input().split()))  
 
num = sum(A[0:K])
ind = 0
max_num =0
for i in range(N-K):
    num -= A[i]
    num += A[i+K]
    if num> max_num:
        ind = i+1
        max_num = num
 
ans = 0
for i in range(ind,ind+K):
    ans += (1+A[i])/2
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
A=list(map(int, input().split()))  

num = sum(A[0:K])
ind = 0
max_num =0
for i in range(N-K):
    num -= A[i]
    num += A[i+K]
    if num> max_num:
        ind = i+1
        max_num = num

ans = 0
for i in range(ind,ind+K):
    ans += sum(range(1,A[i]+1))/A[i]
    
print(ans)

Fixed submission:
N,K = map(int, input().split())
A=list(map(int, input().split()))  
 
num = sum(A[0:K])
ind = 0
max_num =0
for i in range(N-K):
    num -= A[i]
    num += A[i+K]
    if num> max_num:
        ind = i+1
        max_num = num
 
ans = 0
for i in range(ind,ind+K):
    ans += (1+A[i])/2
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

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

max_num = 0
ind = 0
for i in range(N-K+1):
    if sum(A[i:i+K])> max_num:
        ind = i
        max_num = max(max_num,sum(A[i:i+K]))

ans = 0
for i in range(ind,ind+K):
    ans += sum(range(1,A[i]+1))/A[i]
    
print(ans)

Fixed submission:
N,K = map(int, input().split())
A=list(map(int, input().split()))  
 
num = sum(A[0:K])
ind = 0
max_num =0
for i in range(N-K):
    num -= A[i]
    num += A[i+K]
    if num> max_num:
        ind = i+1
        max_num = num
 
ans = 0
for i in range(ind,ind+K):
    ans += (1+A[i])/2
    
print(ans)
Buggy python submission (verdict: Runtime Error):
H = int(input())
A = math.log(H, 2)

ans = 0
for i in range(0,int(A)+1):
    ans += 2**i

print(ans)

Fixed submission:
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect
from fractions import Fraction
 
H = int(input())
A = math.log(H, 2)

ans = 0
for i in range(0,int(A)+1):
    ans += 2**i

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
import pprint
import numpy as np

h, w = map(int, input().split())
maze = [['*']*(w+2) for j in range(h+2)]
for i in range(1,h+1):
    maze[i][1:] = map(str,list(input()))
    maze[i].append('*')

score = []
def bfs(maze):
    for i in range(1,h+1):
        for l in range(1,w+1):
            if i == '#' or j == '#':
                continue
            visited = [[-1]*(w+1) for j in range(h+1)]
            queue = deque()
            queue.append([i, l])
            visited[i][l] = 0
            while(queue):
                y, x = queue.popleft()
                for j,k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                    new_x, new_y = x+j, y+k
                    if maze[new_y][new_x] == '.' and visited[new_y][new_x] == -1:
                        queue.append([new_y, new_x])
                        visited[new_y][new_x] = visited[y][x] + 1
            idx = np.unravel_index(np.argmax(np.array(visited)), np.array(visited).shape)
            score.append(np.array(visited)[idx])
    return (max(score))

print(bfs(maze))


Fixed submission:
from collections import deque
import pprint
import numpy as np

h, w = map(int, input().split())
maze = [['*']*(w+2) for j in range(h+2)]
for i in range(1,h+1):
    maze[i][1:] = map(str,list(input()))
    maze[i].append('*')

score = []
def bfs(maze):
    for i in range(1,h+1):
        for l in range(1,w+1):
            if maze[i][l] == '#':
                continue
            visited = [[-1]*(w+1) for j in range(h+1)]
            queue = deque()
            queue.append([i, l])
            visited[i][l] = 0
            while(queue):
                y, x = queue.popleft()
                for j,k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                    new_x, new_y = x+j, y+k
                    if maze[new_y][new_x] == '.' and visited[new_y][new_x] == -1:
                        queue.append([new_y, new_x])
                        visited[new_y][new_x] = visited[y][x] + 1
            idx = np.unravel_index(np.argmax(np.array(visited)), np.array(visited).shape)
            score.append(np.array(visited)[idx])
    return (max(score))

print(bfs(maze))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int, input().split())
R,S,P=map(int, input().split()) 
T = input()
 
ten = [0] * N
for i in range(N):
    if (T[i] == 'r'):
        ten[i] = P
    elif(T[i] == 's'):
        ten[i] = R
    else:
        ten[i] = S
 
ten2 = ten[:]
T2 = T
for i in range(N-K):
    if(T[i] == T[i+K]):
        ten[i+K] = 0
        str_list = list(T)
        str_list[i+K] = 'o'
        T = "".join(str_list)
for i in range(N-1,K-1,-1):
    if(T2[i] == T2[i-K]):
        ten2[i-K] = 0
        str_list = list(T2)
        str_list[i-K] = 'o'
        T2 = "".join(str_list)


print(max(sum(ten),sum(ten2)))

Fixed submission:
N,K=map(int, input().split())
R,S,P=map(int, input().split()) 
T = list(input())

ten = [0] * N
for i in range(N):
    if (T[i] == 'r'):
        ten[i] = P
    elif(T[i] == 's'):
        ten[i] = R
    else:
        ten[i] = S
 

for i in range(N-K):
    if(T[i] == T[i+K]):
        ten[i+K] = 0
        T[i+K] = 'o'


print(sum(ten))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

l.sort()

ans = 0
for i in range(n):
    for j in range(i+1,n):
        num = abs(l[i]-l[j])
        idx_l = bisect.bisect_right(l,num)
        idx_r = bisect.bisect_left(l,min(l[i],l[j]))
        ans += max(0,idx_r-idx_l)
print(ans)

Fixed submission:
import bisect

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

l.sort()

ans = 0
for i in range(n):
    for j in range(i+1,n):
        idx = bisect.bisect_left(l,l[i]+l[j])
        ans += idx-1-j
print(ans)