Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def find(n):
    if root[n] < 0:
        return n
    else:
        root[n] = find(root[n])
        return root[n]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if root[x] > root[y]:
        x, y = y, x

    root[x] += root[y]
    root[y] = x

def size(x):
    return -root[find(x)]

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

def member(x):
    rt = find(x)
    return [i for i in range(n) if find(i) == rt]

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

def member_count(x):
    return len(roots())

def all_group_members():
    return {r: member(r) for r in roots()}

n , m = map(int,input().split())
root = [-1 for i in range(n)]
for i in range(m):
    a , b = map(lambda x:int(x)-1,input().split())
    unite(a,b)

d = all_group_members()
ans = 0
for v in d.values():
    ans = max(ans,len(v))
print(ans)

Fixed submission:
from collections import deque
n , m = map(int,input().split())
route = [[] for i in range(n)]

for _ in range(m):
    a , b = map(lambda x:int(x)-1,input().split())
    route[a].append(b)
    route[b].append(a)
    
visit = [False for i in range(n)]
ans = 0
for i in range(n):
    if visit[i]:
        continue
    cou = 1
    visit[i] = True
    d = deque()
    d.append(i)
    while d:
        now = d.popleft()
        for j in route[now]:
            if not visit[j]:
                visit[j] = True
                cou += 1
                d.append(j)
    ans = max(cou,ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def find(n):
    if root[n] < 0:
        return n
    else:
        root[n] = find(root[n])
        return root[n]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if root[x] > root[y]:
        x, y = y, x

    root[x] += root[y]
    root[y] = x

def size(x):
    return -root[find(x)]

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

def member(x):
    rt = find(x)
    return [i for i in range(n) if find(i) == rt]

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

def member_count(x):
    return len(roots())

def all_group_members():
    return {r: member(r) for r in roots()}

n , m = map(int,input().split())
root = [-1 for i in range(n)]
for i in range(m):
    a , b = map(lambda x:int(x)-1,input().split())
    unite(a,b)

d = all_group_members()
ans = 0
for v in d.values():
    ans = max(ans,len(v))
print(ans)

Fixed submission:
from collections import deque
n , m = map(int,input().split())
route = [[] for i in range(n)]

for _ in range(m):
    a , b = map(lambda x:int(x)-1,input().split())
    route[a].append(b)
    route[b].append(a)
    
visit = [False for i in range(n)]
ans = 0
for i in range(n):
    if visit[i]:
        continue
    cou = 1
    visit[i] = True
    d = deque()
    d.append(i)
    while d:
        now = d.popleft()
        for j in route[now]:
            if not visit[j]:
                visit[j] = True
                cou += 1
                d.append(j)
    ans = max(cou,ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h , w = map(int,input().split())
ch , cw = map(lambda x:int(x)-1,input().split())
dh , dw = map(lambda x:int(x)-1,input().split())
ma = [list(input()) for i in range(h)]
visit = [[-1 for i in range(w)] for j in range(h)]
cou = -1
p = [(0,1),(0,-1),(1,0),(-1,0)]
for i in range(h):
    for j in range(w):
        if visit[i][j] != -1 or ma[i][j] == "#":
            continue
        cou += 1
        visit[i][j] = cou
        d = deque()
        d.append((i,j))
        while d:
            now = d.popleft()
            for x , y in p:
                if 0 <= now[0]+x < h and 0 <= now[1]+y < w:
                    if ma[now[0]+x][now[1]+y] == "." and visit[now[0]+x][now[1]+y] == -1:
                        visit[now[0]+x][now[1]+y] = cou
                        d.append(((now[0]+x,now[1]+y)))

st = visit[ch][cw]
go = visit[dh][dw]
route = [set() for i in range(cou+1)]

for i in range(h):
    for j in range(w):
        if visit[i][j] == -1:
            continue
        for s in range(-2,3,1):
            for t in range(-2,3,1):
                if 0<=i+s<h and 0<=j+t<w:
                    if visit[i+s][j+t] != -1 and visit[i+s][j+t] != visit[i][j]:
                        route[visit[i][j]].add(visit[i+s][j+t])

kyori = [-1 for i in range(cou+1)]
kyori[st] = 0
d = deque()
d.append(st)

while d:
    now = d.popleft()
    for i in route[now]:
        if kyori[i] == -1:
            kyori[i] = kyori[now] + 1
            d.append(i)

print(kyori[go])

Fixed submission:
from collections import deque
h , w = map(int,input().split())
ch , cw = map(lambda x:int(x)-1,input().split())
dh , dw = map(lambda x:int(x)-1,input().split())
ma = [list(input()) for i in range(h)]
visit = [[-1 for i in range(w)] for j in range(h)]
cou = -1
p = [(0,1),(0,-1),(1,0),(-1,0)]
for i in range(h):
    for j in range(w):
        if visit[i][j] != -1 or ma[i][j] == "#":
            continue
        cou += 1
        visit[i][j] = cou
        d = deque()
        d.append((i,j))
        while d:
            now = d.popleft()
            for x , y in p:
                if 0 <= now[0]+x < h and 0 <= now[1]+y < w:
                    if ma[now[0]+x][now[1]+y] == "." and visit[now[0]+x][now[1]+y] == -1:
                        visit[now[0]+x][now[1]+y] = cou
                        d.append(((now[0]+x,now[1]+y)))

st = visit[ch][cw]
go = visit[dh][dw]
route = [set() for i in range(cou+1)]

for i in range(h):
    for j in range(w):
        if visit[i][j] == -1:
            continue
        for s in range(-2,3,1):
            for t in range(-2,3,1):
                if 0<=i+s<h and 0<=j+t<w:
                    if visit[i+s][j+t] != -1 and visit[i+s][j+t] != visit[i][j]:
                        route[visit[i][j]].add(visit[i+s][j+t])

kyori = [-1 for i in range(cou+1)]
kyori[st] = 0
d = deque()
d.append(st)

while d:
    now = d.popleft()
    for i in route[now]:
        if kyori[i] == -1:
            kyori[i] = kyori[now] + 1
            d.append(i)

print(kyori[go])
Buggy python submission (verdict: Runtime Error):
s = input()
if s = "SSS":
    print(0)
elif s = "RSS" or s = "SRS" or s = "SSR" or s = "RSR":
    print(1)
elif s = "RRR":
    print(3)
elif s = "RRS" or s = "SRR":
    print(2)

Fixed submission:
s = input()
if s == "SSS":
    print(0)
elif s == "RSS" or s == "SRS" or s == "SSR" or s == "RSR":
    print(1)
elif s == "RRR":
    print(3)
elif s == "RRS" or s == "SRR":
    print(2)
Buggy python submission (verdict: Runtime Error):
R , C , K = map(int,input().split())
masu = [[0 for i in range(C)] for j in range(R)]
for i in range(K):
    r , c , v = map(int,input().split())
    masu[r-1][c-1] = v

dp0 = [[0 for i in range(C)] for j in range(R)]
dp1 = [[0 for i in range(C)] for j in range(R)]
dp2 = [[0 for i in range(C)] for j in range(R)] 
dp3 = [[0 for i in range(C)] for j in range(R)]

if masu[0][0] != 0:
    dp1[0][0] = masu[0][0]
for i in range(1,C):
    dp0[0][i] = max(dp0[0][i],dp0[0][i-1])
    dp1[0][i] = max(dp1[0][i],dp1[0][i-1])
    dp2[0][i] = max(dp2[0][i],dp2[0][i-1])
    dp3[0][i] = max(dp3[0][i],dp3[0][i-1])
    if masu[0][i] != 0:
        dp3[0][i] = max(dp3[0][i],dp2[0][i]+masu[0][i])
        dp2[0][i] = max(dp2[0][i],dp1[0][i]+masu[0][i])
        dp1[0][i] = max(dp1[0][i],dp0[0][i]+masu[0][i])


if R == 1:
    print(dp[-1][-1])
    exit()

for i in range(1,R):
    for j in range(C):
        dp0[i][j] = max(dp0[i][j],dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j])
        if j != 0:
            dp0[i][j] = max(dp0[i][j],dp0[i][j-1])
            dp1[i][j] = max(dp1[i][j],dp1[i][j-1])
            dp2[i][j] = max(dp2[i][j],dp2[i][j-1])
            dp3[i][j] = max(dp3[i][j],dp3[i][j-1])
        if masu[i][j] != 0:
            dp3[i][j] = max(dp3[i][j],dp2[i][j]+masu[i][j])
            dp2[i][j] = max(dp2[i][j],dp1[i][j]+masu[i][j])
            dp1[i][j] = max(dp1[i][j],dp0[i][j]+masu[i][j])
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))

Fixed submission:
R , C , K = map(int,input().split())
masu = [[0 for i in range(C)] for j in range(R)]
for i in range(K):
    r , c , v = map(int,input().split())
    masu[r-1][c-1] = v

dp0 = [[0 for i in range(C)] for j in range(R)]
dp1 = [[0 for i in range(C)] for j in range(R)]
dp2 = [[0 for i in range(C)] for j in range(R)] 
dp3 = [[0 for i in range(C)] for j in range(R)]

if masu[0][0] != 0:
    dp1[0][0] = masu[0][0]
for i in range(1,C):
    dp0[0][i] = max(dp0[0][i],dp0[0][i-1])
    dp1[0][i] = max(dp1[0][i],dp1[0][i-1])
    dp2[0][i] = max(dp2[0][i],dp2[0][i-1])
    dp3[0][i] = max(dp3[0][i],dp3[0][i-1])
    if masu[0][i] != 0:
        dp3[0][i] = max(dp3[0][i],dp2[0][i]+masu[0][i])
        dp2[0][i] = max(dp2[0][i],dp1[0][i]+masu[0][i])
        dp1[0][i] = max(dp1[0][i],dp0[0][i]+masu[0][i])




for i in range(1,R):
    for j in range(C):
        dp0[i][j] = max(dp0[i][j],dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j])
        if j != 0:
            dp0[i][j] = max(dp0[i][j],dp0[i][j-1])
            dp1[i][j] = max(dp1[i][j],dp1[i][j-1])
            dp2[i][j] = max(dp2[i][j],dp2[i][j-1])
            dp3[i][j] = max(dp3[i][j],dp3[i][j-1])
        if masu[i][j] != 0:
            dp3[i][j] = max(dp3[i][j],dp2[i][j]+masu[i][j])
            dp2[i][j] = max(dp2[i][j],dp1[i][j]+masu[i][j])
            dp1[i][j] = max(dp1[i][j],dp0[i][j]+masu[i][j])
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n , k = map(int,input().split())
p = list(map(int,input().split()))
a = []
for i in range(n):
    a.append([-p[i],-p[i],1])
heapq.heapify(a)
for i in range(k):
    now , moto , kazu = heapq.heappop(a)
    heapq.heappush(a,[moto//(kazu+1),moto,kazu+1])
ans = heapq.heappop(a)
print(-ans[0])

Fixed submission:
import heapq
n , k = map(int,input().split())
a = list(map(int,input().split()))
lef = 0
rig = max(a)
while rig - lef != 1:
    now = -(-(lef+rig)//2)
    cou = 0
    for i in range(n):
        cou += -(-a[i]//now) - 1
    if cou <= k:
        rig = now
    elif cou > k:
        lef = now
print(rig)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n , k = map(int,input().split())
p = list(map(int,input().split()))
a = []
for i in range(n):
    a.append([-p[i],-p[i],1])
heapq.heapify(a)
for i in range(k):
    now , moto , kazu = heapq.heappop(a)
    heapq.heappush(a,[moto//(kazu+1),moto,kazu+1])
ans = heapq.heappop(a)
print(-ans[0])

Fixed submission:
import heapq
n , k = map(int,input().split())
a = list(map(int,input().split()))
lef = 0
rig = max(a)
while rig - lef != 1:
    now = -(-(lef+rig)//2)
    cou = 0
    for i in range(n):
        cou += -(-a[i]//now) - 1
    if cou <= k:
        rig = now
    elif cou > k:
        lef = now
print(rig)
Buggy python submission (verdict: Time Limit Exceeded):
def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod
mod = 10**9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0,1]

k = int(input())
s = input()
t = len(s)
n = k + t
for i in range(2,n+1):
    fact.append((fact[-1] * i) % mod)
    inv.append((inv[mod % i] * (mod - (mod // i))) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)
ans = 0
for i in range(k+1):
    ans += (cmb(k-i+t-1,t-1,mod)*pow(25,k-i,mod)*pow(26,i,mod))%mod
    ans %= mod
print(ans)

Fixed submission:
def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod
mod = 10**9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0,1]

k = int(input())
s = input()
t = len(s)
n = k + t
for i in range(2,n+1):
    fact.append((fact[-1] * i) % mod)
    inv.append((inv[mod % i] * (mod - (mod // i))) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)
ans = 0
for i in range(k+1):
    ans += (cmb(k-i+t-1,t-1,mod)*pow(25,k-i,mod)*pow(26,i,mod))%mod
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n , s = map(int,input().split())
a = list(map(int,input().split()))
dp = [[0 for j in range(s+1)] for i in range(n+1)]
mod = 998244353
for i in range(1,n+1):
    if 0 <= a[i-1] <= s:
        if dp[i][a[i-1]] == 0:
            dp[i][a[i-1]] += pow(2,i-1,mod)
    for j in range(0,s+1):
        dp[i][j] += dp[i-1][j]*2
        if j - a[i-1] >= 0:
            dp[i][j] += dp[i-1][j-a[i-1]]
        dp[i][j] %= mod

print(dp[n][s])

Fixed submission:
n , s = map(int,input().split())
a = list(map(int,input().split()))
dp = [[0 for j in range(s+1)] for i in range(n+1)]
mod = 998244353
for i in range(1,n+1):
    if 0 <= a[i-1] <= s:
        if dp[i][a[i-1]] == 0:
            dp[i][a[i-1]] += pow(2,i-1,mod)
    for j in range(0,s+1):
        dp[i][j] += (dp[i-1][j]*2)%mod
        if j - a[i-1] >= 0:
            dp[i][j] += dp[i-1][j-a[i-1]]
        dp[i][j] %= mod

print(dp[n][s])
Buggy python submission (verdict: Runtime Error):
n = int(input())
mod = 10**9 + 7
cou = 0
pdic = {}
kan = []
for i in range(n):
    a , b = map(int,input().split())
    p = a/b
    q = -b/a
    if pdic.get(q,-1) != -1:
        kan[pdic[q]][1] += 1
    elif pdic.get(p,-1) == -1:
        pdic[p] = cou
        kan.append([1,0])
        cou += 1
    elif pdic.get(p,-1) != -1:
        kan[pdic[p]][0] += 1
        
ans = 1
for i in range(len(kan)):
    if kan[i][1] == 0:
        ans *= pow(2,kan[i][0],mod)
    elif kan[i][1] != 0:
        ans *= (pow(2,kan[i][0],mod) + pow(2,kan[i][1],mod)-1) % mod
    ans %= mod

print(ans-1)

Fixed submission:
import math
n = int(input())
mod = 10**9 + 7
cou = 0
pdic = {}
kan = []
betu = [0,0,0]

for i in range(n):
    a , b = map(int,input().split())
    if a*b != 0:
        g = math.gcd(abs(a),abs(b))
        if a*b > 0:
            m = 1
        elif a*b < 0:
            m = -1
        p = (m*abs(a)//g,abs(b)//g)
        q = ((-m)*abs(b)//g,abs(a)//g)
        if pdic.get(q,-1) != -1:
            kan[pdic[q]][1] += 1
        elif pdic.get(p,-1) == -1:
            pdic[p] = cou
            kan.append([1,0])
            cou += 1
        elif pdic.get(p,-1) != -1:
            kan[pdic[p]][0] += 1
    elif a*b == 0:
        if a == 0 and b == 0:
            betu[2] += 1
        elif a == 0:
            betu[0] += 1
        elif b == 0:
            betu[1] += 1
        
        
ans = 1
for i in range(len(kan)):
    ans *= (pow(2,kan[i][0],mod) + pow(2,kan[i][1],mod) - 1) % mod
    ans %= mod
ans *= (pow(2,betu[0],mod) + pow(2,betu[1],mod) - 1) % mod
print((ans-1+betu[2])%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
mod = 998244353
f = [m]
for i in range(1,n):
    f.append((f[i-1]*(m-1))%mod)
p = [1]
buns = 1
bunb = 1
for i in range(k):
    buns *= (n-1-i)
    buns %= mod
    bunb *= pow(i+1,mod-2,mod)
    p.append((bunb*buns)%mod)
ans = 0 
for i in range(k+1):
    ans += f[n-1-i]*p[i]
    ans %= mod
print(ans)

Fixed submission:
def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

n,m,k = map(int,input().split())

mod = 998244353
fact = [1, 1]
factinv = [1, 1]
inv = [0,1]
rui = [1,m-1]

for i in range(2,n+1):
    fact.append((fact[-1] * i) % mod)
    inv.append((inv[mod % i] * (mod - (mod // i))) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)
    rui.append(rui[-1]*(m-1) % mod)

ans = 0
for i in range(k+1):
    ans += cmb(n-1,i,mod)*m*rui[n-1-i]
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
mod = 998244353
f = [m*pow(m-1,n-1,mod)]
for i in range(1,k+1):
    f.append((f[i-1]*pow(m-1,mod-2,mod))%mod)
p = [1]
buns = 1
bunb = 1
for i in range(k):
    buns *= (n-1-i)
    buns %= mod
    bunb *= pow(i+1,mod-2,mod)
    p.append((bunb*buns)%mod)
ans =0 
for i in range(k+1):
    ans += f[i]*p[i]
    ans %= mod
print(ans)

Fixed submission:
def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

n,m,k = map(int,input().split())

mod = 998244353
fact = [1, 1]
factinv = [1, 1]
inv = [0,1]
rui = [1,m-1]

for i in range(2,n+1):
    fact.append((fact[-1] * i) % mod)
    inv.append((inv[mod % i] * (mod - (mod // i))) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)
    rui.append(rui[-1]*(m-1) % mod)

ans = 0
for i in range(k+1):
    ans += cmb(n-1,i,mod)*m*rui[n-1-i]
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
i = 0
j = 1
ans = 0
p = 0
nextj = 0
while True:
    if j == n:
        i += 1
        p = 0
        j = min(n-1,min(i+a[i]+1,nextj))

    
    if p == 0 and a[i] + a[j] == j-i:
        ans += 1
        nextj = j
        p = 1
    elif p == 1 and a[i] + a[j] == j-i:
        ans += 1
    j += 1
    
    if i == n-1:
        print(ans)
        exit()
        

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mae = {}
ans = 0
for i in range(n):
    mae[i+a[i]]=mae.get(i+a[i],0)+1
    ans += mae.get(i-a[i],0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
i = 0
j = 1
ans = 0
p = 0
nextj = 0
while True:
    if j == n:
        i += 1
        j = min(n-1,i+a[i]+1)

    
    if a[i] + a[j] == j-i:
        ans += 1

    j += 1
    
    if i == n-1:
        print(ans)
        exit()

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mae = {}
ans = 0
for i in range(n):
    mae[i+a[i]]=mae.get(i+a[i],0)+1
    ans += mae.get(i-a[i],0)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
i = 0
j = 1
ans = 0
p = 0
nextj = 0
while True:
    if j == n:
        j = min(i+1,nextj)
        p = 0
        i += 1
    
    if p == 0 and a[i] + a[j] == j-i:
        ans += 1
        nextj = j
        p = 1
    elif p == 1 and a[i] + a[j] == j-i:
        ans += 1
    j += 1
    
    if i == n-1:
        print(ans)
        exit()

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mae = {}
ans = 0
for i in range(n):
    mae[i+a[i]]=mae.get(i+a[i],0)+1
    ans += mae.get(i-a[i],0)
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
i = 0
j = 1
ans = 0
p = 0
while True:
    if j == n:
        j = min(i+1,nextj)
        p = 0
        i += 1
    
    if p == 0 and a[i] + a[j] == j-i:
        ans += 1
        nextj = j
        p = 1
    elif p == 1 and a[i] + a[j] == j-i:
        ans += 1
    j += 1
    
    if i == n-1:
        print(ans)
        exit()

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mae = {}
ans = 0
for i in range(n):
    mae[i+a[i]]=mae.get(i+a[i],0)+1
    ans += mae.get(i-a[i],0)
print(ans)
Buggy python submission (verdict: Runtime Error):
n , m , q = map(int,input().split())
p = []
for i in range(q):
    a , b , c , d = map(int,input().split())
    p.append([a,b,c,d])
ans = 0
for a1 in range(1,m+1):
    for a2 in range(a1,m+1):
        for a3 in range(a2,m+1):
            for a4 in range(a3,m+1):
                for a5 in range(a4,m+1):
                    for a6 in range(a5,m+1):
                        for a7 in range(a6,m+1):
                            for a8 in range(a7,m+1):
                                for a9 in range(a8,m+1):
                                    for a10 in range(a9,m+1):
                                        tyu = [a1,a2,a3,a4,a5,a6,a7,a8,a9,a10]
                                        kar = 0
                                        for x,y,z,w in p:
                                            if tyu[y] - tyu[x] == z:
                                                kar += w
                                        ans = max(kar,ans)
print(ans)
                                        
                        

Fixed submission:
n , m , q = map(int,input().split())
p = []
for i in range(q):
    a , b , c , d = map(int,input().split())
    p.append([a,b,c,d])
ans = 0
for a1 in range(1,m+1):
    for a2 in range(a1,m+1):
        for a3 in range(a2,m+1):
            for a4 in range(a3,m+1):
                for a5 in range(a4,m+1):
                    for a6 in range(a5,m+1):
                        for a7 in range(a6,m+1):
                            for a8 in range(a7,m+1):
                                for a9 in range(a8,m+1):
                                    for a10 in range(a9,m+1):
                                        tyu = [0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10]
                                        kar = 0
                                        for x,y,z,w in p:
                                            if tyu[y] - tyu[x] == z:
                                                kar += w
                                        ans = max(kar,ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = [[0 for i in range(n+1)] for j in range(n+1)]
p = []
for i in range(n):
    p.append([a[i],i])
p.sort(reverse=True)

for i in range(1,n+1):
    ans[0][i] = ans[0][i-1] + p[i-1][0]*abs(p[i-1][1]-i+1)
for i in range(1,n+1):
    ans[i][0] = ans[i-1][0] + p[i-1][0]*abs(n-i-p[i-1][1])

for i in range(1,n):
    for j in range(1,n-i+1):
        ans[i][j] = max(ans[i][j-1] + p[i+j -1][0]*abs(p[i+j -1][1]-j+1),
        ans[i-1][j] + p[i+j - 1][0]*abs(n-i-p[i+j-1][1]))

ma = 0
for i in range(n):
    ma = max(ma,ans[0+i][n-i])
print(ma)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = [[0 for i in range(n+1)] for j in range(n+1)]
p = []
for i in range(n):
    p.append([a[i],i])
p.sort(reverse=True)

for i in range(1,n+1):
    ans[0][i] = ans[0][i-1] + p[i-1][0]*abs(p[i-1][1]-i+1)
for i in range(1,n+1):
    ans[i][0] = ans[i-1][0] + p[i-1][0]*abs(n-i-p[i-1][1])

for i in range(1,n):
    for j in range(1,n-i+1):
        ans[i][j] = max(ans[i][j-1] + p[i+j -1][0]*abs(p[i+j -1][1]-j+1),
        ans[i-1][j] + p[i+j - 1][0]*abs(n-i-p[i+j-1][1]))

ma = 0
for i in range(n):
    ma = max(ma,ans[0+i][n-i])
print(ma)
Buggy python submission (verdict: Runtime Error):
k = int(input())
cou = 0
while True:
    cou += 1
    t = q.get()
    if cou == k:
        print(t)
        exit()
    if t % 10 == 0:
        q.put(t*10)
        q.put(t*10 + 1)
    elif t % 10 == 9:
        q.put(t*10 + 8)
        q.put(t*10 + 9)
    else:
        s = t % 10
        q.put(t*10 + s -1)
        q.put(t*10 + s)

Fixed submission:
import queue

q = queue.Queue()
for i in range(1,10):
    q.put(i)

k = int(input())
cou = 0
while True:
    cou += 1
    t = q.get()
    if cou == k:
        print(t)
        exit()
    if t % 10 == 0:
        q.put(t*10)
        q.put(t*10 + 1)
    elif t % 10 == 9:
        q.put(t*10 + 8)
        q.put(t*10 + 9)
    else:
        s = t % 10
        q.put(t*10 + s -1)
        q.put(t*10 + s)
        q.put(t*10 + s + 1)