Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n, k = map(int, input().split())
*a, = map(int, input().split())

c = Counter(a)
kv = sorted(c.items(), key=lambda x: x[1], reverse=True)

if n <= k:
    print(0)
else:
    ans = n
    for i in range(k):
        ans -= kv[i][1]
    print(ans)


Fixed submission:
from collections import Counter
n, k = map(int, input().split())
*a, = map(int, input().split())

c = Counter(a)
kv = sorted(c.items(), key=lambda x: x[1], reverse=True)

if n <= k:
    print(0)
else:
    ans = n
    for i in range(k):
        try:
            ans -= kv[i][1]
        except:
            pass
    print(ans)
Buggy python submission (verdict: Runtime Error):
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import shortest_path
from collections import defaultdict
h, w = map(int, input().split())
table = [list(map(int, input().split())) for _ in range(10)]
dd = defaultdict(int)
for _ in range(h):
    for x in map(int, input().split()):
        if x == -1:
            continue
        dd[x] += 1

trans_table = list(zip(*table))
scores = shortest_path(csr_matrix(trans_table), indices=1)

ans = 0
for k, v in dd.items():
    ans += int(scores[k])*v
print(ans)

Fixed submission:
from collections import defaultdict, deque
h, w = map(int, input().split())
table = [list(map(int, input().split())) for _ in range(10)]
dd = defaultdict(int)
for _ in range(h):
    for x in map(int, input().split()):
        if x == -1:
            continue
        dd[x] += 1

INF = 10**9
scores = [INF]*10
decided = [0]*10
queue = deque()
trans_table = list(zip(*table))
for i in range(10):
    x = trans_table[1][i]
    scores[i] = x

MIN = min(set(scores) ^ {0})

while 0 in decided:
    for idx, score in enumerate(scores):
        if score <= MIN:
            decided[idx] = 1

    for i in range(10):
        if i == 1:
            continue
        if decided[i]:
            for j in range(10):
                if not decided[j]:
                    queue.append((i, j))

    while queue:
        i, j = queue.popleft()
        x = trans_table[i][j]
        scores[j] = min(scores[j], scores[i]+x)

    MIN += 1



ans = 0
for k, v in dd.items():
    ans += scores[k]*v
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        if (4*h*n-N*n-N*h) == 0:
            continue
        w = N*h*n // (4*h*n-N*n-N*h)
        if w < 1:
            continue
        if w*(4*h*n-N*n-N*h) == N*h*n:
            print(h, n, w)
            exit()


Fixed submission:
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        if (4*h*n-N*n-N*h) == 0:
            continue
        w = N*h*n // (4*h*n-N*n-N*h)
        if w < 1:
            continue
        if w*(4*h*n-N*n-N*h) == N*h*n:
            print(h, n, w)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
A = input()
n = len(A)
c = Counter(A)

U = n
fact = [0]*(U+1)
fact[0] = 1
for i in range(1, U+1):
    fact[i] = fact[i-1]*i


def nCr(n, r):
    if r < 0 or n < r:
        return 0
    return fact[n]//fact[r]//fact[n-r]


ans = 1
ans += nCr(n, 2)
for v in c.values():
    ans -= nCr(v, 2)
print(ans)


Fixed submission:
from collections import Counter
A = input()
n = len(A)
c = Counter(A)

ans = 1
ans += n*(n-1)//2
for v in c.values():
    ans -= v*(v-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**5
n = int(input())

graph = [[] for _ in range(n+1)]
d = [[INF]*(n+1) for _ in range(n+1)]

for _ in range(n-1):
    a, b, c = map(int, input().split())
    d[a][b] = d[b][a] = c
    graph[a].append(b)
    graph[b].append(a)

q, k = map(int, input().split())
dist = [INF]*(n+1)


def dfs(v1, parent, add):
    dist[v1] = add
    for v2 in graph[v1]:
        if v2 == parent:
            continue
        dfs(v2, v1, add + d[v1][v2])

dfs(k, -1, 0)

for _ in range(q):
    x, y = map(int, input().split())
    print(dist[x]+dist[y])


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**9+1
n = int(input())
graph = [[] for _ in range(n+1)]

for _ in range(n-1):
    a, b, c = map(int, input().split())
    graph[a].append((b, c))
    graph[b].append((a, c))

q, k = map(int, input().split())
dist = [INF]*(n+1)


def dfs(v1, parent, add):
    dist[v1] = add
    for v2, d in graph[v1]:
        if v2 == parent:
            continue
        dfs(v2, v1, add + d)

dfs(k, -1, 0)

for _ in range(q):
    x, y = map(int, input().split())
    print(dist[x]+dist[y])
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
ans = [[0]*w for _ in range(h)]
idx_ls = [(0, 0)]

i = j = 0
flip = 0
flag = 1
for _ in range(h*w-1):
    if (j == w-1 or j == 0)and not flag:
        i += 1
        flip ^= 1
        flag = 1
        idx_ls.append((i, j))
        continue
    flag = 0
    j = j+[1, -1][flip]
    idx_ls.append((i, j))


for color, a in enumerate(A):
    color += 1
    for _ in range(a):
        i, j = idx_ls.pop()
        ans[i][j] = color

for x in ans:
    print(*x)


Fixed submission:
h, w = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
ans = [[0]*w for _ in range(h)]

idx_ls = []

flip = 0
for i in range(h):
    if not flip:
        for j in range(w):
            idx_ls.append((i, j))
    else:
        for j in range(w-1, -1, -1):
            idx_ls.append((i, j))
    flip ^= 1


for color, a in enumerate(A):
    color += 1
    for _ in range(a):
        i, j = idx_ls.pop()
        ans[i][j] = color

for x in ans:
    print(*x)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = sorted(map(int, input().split()))
INF = 10**5
diff = INF
for x, y in zip(A, A[1:]):
    diff = min(diff, abs(x-y))

MAX = A[-1]
ans = False
for a in A:
    if a-k < 0:
        continue
    x, r = divmod((a-k), diff)
    if r == 0:
        ans = True
        break
print("POSSIBLE" if ans else "IMPOSSIBLE")


Fixed submission:
n, k = map(int, input().split())
A = sorted(map(int, input().split()))
INF = 10**9+1
diff = INF
for x, y in zip(A, A[1:]):
    z = abs(x-y)
    if z > 0:
        diff = min(diff, z)

MAX = A[-1]
ans = False
for a in A:
    if a-k < 0:
        continue
    x, r = divmod((a-k), diff)
    if r == 0:
        ans = True
        break
print("POSSIBLE" if ans else "IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
n, a = int(input()), list(map(int, input().split()))
print(*a[::-2], *a[n % 2::2])

Fixed submission:
from collections import deque

q = deque()

n = int(input())
*a, = map(int, input().split())
for i, x in enumerate(a):
    if i % 2 == 0:
        q.append(x)
    else:
        q.appendleft(x)
if n % 2:
    print(*reversed(q))
else:
    print(*q)
Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import csgraph_from_dense, bellman_ford
from scipy.sparse.csgraph._shortest_path import NegativeCycleError

n, m = map(int, input().split())
GRAPH = [[0]*n for _ in range(n)]

for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    GRAPH[a][b] = -c

try:
    sp = bellman_ford(csgraph_from_dense(GRAPH), indices=0)
except NegativeCycleError:
    print('inf')
else:
    print(-int(sp[-1]))


Fixed submission:
n, m = map(int, input().split())
edges = []
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges.append((a, b, -c))

init_v = 0
INF = float('inf')
dist = [INF]*n
dist[init_v] = 0
for i in range(n):
    for v, v2, c in edges:
        if dist[v2] <= dist[v]+c:
            continue
        dist[v2] = dist[v]+c

negative = [0]*n
for i in range(n):
    for v, v2, c in edges:
        if dist[v2] <= dist[v]+c:
            continue
        dist[v2] = dist[v]+c
        negative[v2] = 1

if negative[-1]:
    print('inf')
else:
    print(-dist[-1])
Buggy python submission (verdict: Runtime Error):
n, W = map(int, input().split())
dd = defaultdict(list)
for i in range(n):
    weight, value = map(int, input().split())
    dd[weight].append(value)

for k in dd.keys():
    dd[k].sort(reverse=True)

a = min(dd.keys())
b, c, d = a+1, a+2, a+3
ans = 0
for w in range(len(dd[a])+1):
    for x in range(len(dd[b])+1):
        for y in range(len(dd[c])+1):
            for z in range(len(dd[d])+1):
                if W < a*w+b*x+c*y+d*z:
                    break
                val = sum(dd[a][:w])+sum(dd[b][:x]) + \
                    sum(dd[c][:y])+sum(dd[d][:z])
                ans = max(ans, val)
print(ans)

Fixed submission:
n, w = map(int, input().split())
weights, values = zip(*[tuple(map(int, input().split()))for _ in range(n)])
min_w = min(weights)-1
weights = [weight-min_w for weight in weights]
W_MAX = 4*200
dp = [[0]*(W_MAX+1) for _ in range(n+1)]
for i in range(1, n+1):
    for k in reversed(range(1, n+1)):
        for j in range(1, W_MAX+1):
            if j-weights[i-1] < 0:
                continue
            dp[k][j] = max(dp[k][j], dp[k-1][j-weights[i-1]]+values[i-1])

ans = 0
for k in range(n+1):
    w_max = min(w-k*min_w, W_MAX)
    if w_max < 0:
        continue
    ans = max(ans, dp[k][w_max])
print(ans)

Buggy python submission (verdict: Runtime Error):
n, w = map(int, input().split())
weights, values = zip(*[tuple(map(int, input().split()))for _ in range(n)])
min_w = min(weights)-1
weights = [weight-min_w for weight in weights]
W_MAX = 4*200
dp = [[0]*(W_MAX+1) for _ in range(n+1)]
for i in range(1, n+1):
    for k in reversed(range(1, n+1)):
        for j in range(1, W_MAX+1):
            if j-weights[i-1] < 0:
                continue
            dp[k][j] = max(dp[k][j], dp[k-1][j-weights[i-1]]+values[i-1])

ans = 0
for k in range(n+1):
    w_max = w-k*min_w
    if w_max < 0 <= W_MAX:
        continue
    ans = max(ans, dp[k][w_max])
print(ans)

Fixed submission:
n, w = map(int, input().split())
weights, values = zip(*[tuple(map(int, input().split()))for _ in range(n)])
min_w = min(weights)-1
weights = [weight-min_w for weight in weights]
W_MAX = 4*200
dp = [[0]*(W_MAX+1) for _ in range(n+1)]
for i in range(1, n+1):
    for k in reversed(range(1, n+1)):
        for j in range(1, W_MAX+1):
            if j-weights[i-1] < 0:
                continue
            dp[k][j] = max(dp[k][j], dp[k-1][j-weights[i-1]]+values[i-1])

ans = 0
for k in range(n+1):
    w_max = min(w-k*min_w, W_MAX)
    if w_max < 0:
        continue
    ans = max(ans, dp[k][w_max])
print(ans)
Buggy python submission (verdict: Runtime Error):
import heapq
n = int(input())
A = list(map(int, input().split()))
heapq.heapify(A)

cnt = 1
prev = heapq.heappop(A)
while A:
    x = heapq.heappop(A)
    if prev > x:
        heapq.heappush(A, prev)
        prev = x
        continue
    print(prev, x, A, cnt)
    if 2*prev < x:
        cnt = 1
    else:
        cnt += 1
    prev += x

print(cnt)


Fixed submission:
import heapq
n = int(input())
A = list(map(int, input().split()))
heapq.heapify(A)

cnt = 1
prev = heapq.heappop(A)
while A:
    x = heapq.heappop(A)
    if prev > x:
        heapq.heappush(A, prev)
        prev = x
        continue
    if 2*prev < x:
        cnt = 1
    else:
        cnt += 1
    prev += x

print(cnt)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

tmp = []
for k in range(n):
    for i in range(n):
        if i+m <= n:
            for j in range(m):
                tmp.append(a[k+j][i:i+m])
        if tmp == b:
            print('Yes')
            exit()
        tmp = []
else:
    print('No')


Fixed submission:
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

for i in range(n):
    for j in range(n):
        if j+m <= n and i+m <= n:
            if [a[i+k][j:j+m] for k in range(m)] == b:
                print('Yes')
                exit()
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
cnt = 0
ls = [z for z in range(k+1)]
for x in range(k+1):
    for y in range(k+1):
        if s - x - y in ls:
            cnt += 1
print(cnt)


Fixed submission:
k, s = map(int, input().split())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= s-x-y <= k:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7
n = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
n_cases = [0]*n
n_cases[0] = n_cases[-1] = 1
height = [0]*n
if T[-1] != A[0]:
    print(0)
    exit()
height[0] = T[0]
height[-1] = A[-1]
for i, (t1, t2) in enumerate(zip(T, T[1:]), 1):
    if t1 != t2:
        n_cases[i] = 1
        height[i] = t2


for i, (a1, a2) in enumerate(zip(A[::-1], A[::-1][1:]), 2):
    if a1 != a2:
        n_cases[-i] = 1
        assert height[-i] == a2 or height[-i] == 0
        height[-i] = a2


for i, (t, a) in enumerate(zip(T, A)):
    if n_cases[i]:
        continue
    n_cases[i] = min(t, a)


ans = 1
for x in n_cases:
    ans *= x
    ans %= MOD
print(ans)


Fixed submission:
MOD = 10**9+7
n = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
n_cases = [0]*n
n_cases[0] = n_cases[-1] = 1
height = [0]*n
if T[-1] != A[0]:
    print(0)
    exit()
height[0] = T[0]
height[-1] = A[-1]
for i, (t1, t2) in enumerate(zip(T, T[1:]), 1):
    if t1 != t2:
        n_cases[i] = 1
        height[i] = t2

for i, (a1, a2) in enumerate(zip(A[::-1], A[::-1][1:]), 2):
    if a1 != a2:
        n_cases[-i] = 1
        if height[-i] == a2 or (height[-i] == 0 and a2 <= T[-i]):
            continue
        print(0)
        exit()

for i, (t, a) in enumerate(zip(T, A)):
    if n_cases[i]:
        continue
    n_cases[i] = min(t, a)


ans = 1
for x in n_cases:
    ans *= x
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

T = A = 1
for _ in range(n):
    t, a = map(int, input().split())
    total = T+A
    x = -(-total//(a+t))
    for x in range(x, 10**15):
        if T <= t*x and A <= a*x:
            T = t*x
            A = a*x
            break

print(T+A)

Fixed submission:
n = int(input())

T = A = 1
for _ in range(n):
    t, a = map(int, input().split())
    total = T+A
    x = -(-total//(a+t))
    x = max(x, -(-T//t))
    x = max(x, -(-A//a))
    T = t*x
    A = a*x

print(T+A)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H,W = map(int,input().split())
C = list(map(int,input().split()))
D = list(map(int,input().split()))

S = ["##" + input() + "##" for _ in range(H)]
for i in range(2):
    S.insert(0,"#"*(W+4))
    S.append("#"*(W+4))

INF = float("inf")
cost = [[INF for _ in range(W+4)] for _ in range(H+4)]
cost0 = deque()
ans = -1

cost0.append((C[0]+1, C[1]+1, 0))
cost[C[0]+1][C[1]+1] = 0

move = [(1,0), (0,1), (-1,0), (0,-1)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)]+move]

cost1 = deque()

while cost0:
    h,w,c = cost0.popleft()
    cost1.append((h,w,c))

    for i, j in move:
        dh = h+i
        dw = w+j
        if S[dh][dw] == "." and c < cost[dh][dw]:
            cost[dh][dw] = c
            cost0.appendleft((dh, dw, cost[dh][dw]))
    
    if len(cost0) == 0:
        while cost1:
            h, w, c = cost1.popleft()
            for i, j in warp:
                dh = h+i
                dw = w+j
                if S[dh][dw] == "." and c+1 < cost[dh][dw]:
                    cost[dh][dw] = c+1
                    cost0.append((dh,dw, cost[dh][dw]))
    
    if cost[D[0]+1][D[1]+1] != INF:
        ans = cost[D[0]+1][D[1]+1]

print(ans)

Fixed submission:
from collections import deque

def solve():
    H,W = map(int,input().split())
    C = list(map(int,input().split()))
    D = list(map(int,input().split()))

    S = ["##" + input() + "##" for _ in range(H)]
    for i in range(2):
        S.insert(0,"#"*(W+4))
        S.append("#"*(W+4))

    INF = float("inf")
    cost = [[INF for _ in range(W+4)] for _ in range(H+4)]
    cost0 = deque()
    ans = -1

    cost0.append((C[0]+1, C[1]+1, 0))
    cost[C[0]+1][C[1]+1] = 0

    move = [(1,0), (0,1), (-1,0), (0,-1)]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)]+move]

    cost1 = deque()

    while cost0:
        h,w,c = cost0.popleft()
        cost1.append((h,w,c))

        for i, j in move:
            dh = h+i
            dw = w+j
            if S[dh][dw] == "." and c < cost[dh][dw]:
                cost[dh][dw] = c
                cost0.appendleft((dh, dw, cost[dh][dw]))
        
        if len(cost0) == 0:
            while cost1:
                h, w, c = cost1.popleft()
                for i, j in warp:
                    dh = h+i
                    dw = w+j
                    if S[dh][dw] == "." and c+1 < cost[dh][dw]:
                        cost[dh][dw] = c+1
                        cost0.append((dh,dw, cost[dh][dw]))
        
        if cost[D[0]+1][D[1]+1] != INF:
            ans = cost[D[0]+1][D[1]+1]

    print(ans)

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

score=1
for i in range(K):
    score*=A[i]

for i in range(K,N):
    pre=score
    score//=A[i-K]
    score*=A[i]
    if score>pre:
        print("Yes")
    else:
        print("No")

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

score=1
for i in range(K):
    score+=A[i]

for i in range(K,N):
    pre=score
    score-=A[i-K]
    score+=A[i]
    if score>pre:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
def num_divisors_table(n):
    table=[0]*(n+1)

    for i in range(1,n+1):
        for j in range(i,n+1,i):
            table[j]+=1
    
    return table

N=int(input())
table=num_divisors_table(N)
ans=0
for K in range(1,N+1):
    ans+=K*table[K]
print(ans)

Fixed submission:
N=int(input())
ans=0
for i in range(1,N+1):
    m=N//i
    ans+=m*i*(m+1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
from itertools import accumulate

N=int(input())
alphabet=[chr(i) for i in range(97,97+26)]
num=[26**i for i in range(1,12)]
acc=list(accumulate(num))
ans=""
index=bisect.bisect_left(acc,N)
if index==0:
    ans+=alphabet[N-1]
else:
    N-=acc[index-1]
    while True:
        tmp=N//num[index-1]
        ans+=alphabet[tmp]
        N-=tmp*num[index-1]
        index=bisect.bisect_left(num,N)
        if index==0:
            break
    ans+=alphabet[N-1]
print(ans)

Fixed submission:
N=int(input())
alphabet=[chr(i) for i in range(97,123)]
ans=""
while N>0:
    N-=1
    ans=chr(97+(N%26))+ans
    N//=26
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

A.sort()
flag=[0]*N
ans=0
for i in range(N):
    if i!=N-1:
        if A[i]==A[i+1]:
            flag[i]=1
    
    for j in range(i+1,N):
        if flag[j]==1:
            continue
        else:
            if A[j]%A[i]==0:
                flag[j]=1
print(flag.count(0))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
flag=[0]*N

ans=0
M=A[-1]
B=[0]*(M+1)
for i in A:
    B[i]+=1

for i in A:
    if B[i]==1:
        ans+=1
    for j in range(i,M+1,i):
        B[j]+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())

A,B=[0]*M,[0]*M
route=[[float("inf")]*N for _ in range(N)]
for i in range(M):
    A[i],B[i]=map(int,input().split())
    A[i]-=1
    B[i]-=1
    route[A[i]][B[i]]=1
    route[B[i]][A[i]]=1

visited=1
not_visited=0

size=len(route)
cost=[float("inf") for _ in range(size)]
visited=[not_visited for _ in range(size)]
before=[None for _ in range(size)]
cost[0]=0

while True:
    MIN=float("inf")
    for i in range(size):
        if visited[i]==not_visited and cost[i]<MIN:
            x = i
            MIN = cost[x]
    if MIN == float("inf"):
        break
    visited[x] = visited

    for i in range(size):
        if cost[i]>route[x][i]+cost[x]:
            cost[i]=route[x][i]+cost[x]
            before[i]=x


def count(start,before):
    now=start
    ret=1
    while True:
        if before[now]==0:
            break
        else:
            ret+=1
            now=before[now]
    return ret

for i in range(1,N):
    if count(i,before)==cost[i]:
        continue
    else:
        print("No")
        exit()

print("Yes")
for i in range(1,N):
    print(before[i]+1)

Fixed submission:
from collections import deque

N,M=map(int,input().split())

graph=[[] for _ in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    A-=1
    B-=1
    graph[A].append(B)
    graph[B].append(A)

def bfs(maze,start):
    queue=deque([start])
    d=[float("inf")]*N
    d[start]=0
    while queue:
        x=queue.popleft()
        for y in graph[x]:
            if d[y]==float("inf"):
                d[y]=d[x]+1
                queue.append(y)
    return d

d=bfs(graph,0)
ans=[0]*N
for i in range(1,N):
    flag=0
    for vertex in graph[i]:
        if d[vertex]==d[i]-1:
            ans[i]=vertex+1
            flag=1
            break
    if flag==0:
        print("No")
        exit()
print("Yes")
print(*ans[1:])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

B=[0]*N
for i in range(N):
    if i-A[i]>0:
        B.append(i-A[i])

ans=0
for i in range(N):
    ans+=B.count(i+A[i])
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))

d={}
for i in range(N):
    if i-A[i]>0:
        if str(i-A[i]) in d:
            d[str(i-A[i])]+=1
        else:
            d[str(i-A[i])]=1

ans=0
for j in range(N):
    if str(j+A[j]) in d:
        ans+=d[str(j+A[j])]
print(ans)

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

B=[0]*N
for i in range(N):
    B[i]=A[i]+i
C=[]
for i in range(N):
    if i-A[i]>0:
        C.append(i-A[i])

ans=0
for i in B:
    ans+=C.count(i)
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))

d={}
for i in range(N):
    if i-A[i]>0:
        if str(i-A[i]) in d:
            d[str(i-A[i])]+=1
        else:
            d[str(i-A[i])]=1

ans=0
for j in range(N):
    if str(j+A[j]) in d:
        ans+=d[str(j+A[j])]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,N=map(int,input().split())
C=A%B
ans=0
for i in range(1,min(B,N+1)):
    b=i
    ans=max(ans, (A*b-C*b%B)//B)
print(ans)

Fixed submission:
A,B,N=map(int,input().split())
C=A%B
ans=0
b=min(B-1,N)
ans=(A*b-C*b%B)//B
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A,B,N=map(int,input().split())
C=A%B
ans=0
for i in range(1,min(B,N+1)):
    b=i
    ans=max(ans, (A*b-C*b%B)//B)
print(ans)

Fixed submission:
A,B,N=map(int,input().split())
C=A%B
ans=0
b=min(B-1,N)
ans=(A*b-C*b%B)//B
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

ans=0
for i in range(1,N+1):
  ans=A.count(i)
  print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))

ans=[0]*N
for i in range(N-1):
  ans[A[i]-1]+=1

for i in range(N):
  print(ans[i])
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
n=[i for i in range(N+1)]
mod=10**9+7141421 35623

min_value=[0]*(N+1)
max_value=[0]*(N+1)
min_value[0]=0
max_value[0]=N
for i in range(1,N+1):
  min_value[i]=min_value[i-1]+n[i]
  max_value[i]=max_value[i-1]+n[-(i+1)]

ans=0
for i in range(K-1,N+1):
  ans+=max_value[i]-min_value[i]+1
  ans%=mod
print(ans)

Fixed submission:
N,K=map(int,input().split())
n=[i for i in range(N+1)]
mod=10**9+7

min_value=[0]*(N+1)
max_value=[0]*(N+1)
min_value[0]=0
max_value[0]=N
for i in range(1,N+1):
  min_value[i]=min_value[i-1]+n[i]
  max_value[i]=max_value[i-1]+n[-(i+1)]

ans=0
for i in range(K-1,N+1):
  ans+=max_value[i]-min_value[i]+1
  ans%=mod
print(ans)