Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
h, n= list(map(int,input().split()))
a = []
b = []
for i in range(n):
    a_in, b_in = list(map(int,input().split()))
    a.append(a_in)
    b.append(b_in)

if h == 1:
    print(min(b))
else:
    dp = [0]*h
    dp[0] = min(b)
    for i in range(2,h+1):
        c = [0]*n
        for j in range(n):
            if i > a[j]:
                c[j] = b[j] + dp[i-a[j]-1]
            else:
                c[j] = b[j]
        dp[i-1] = min(c)
    print(dp[h-1])


Fixed submission:
h, n= list(map(int,input().split()))
a = []
b = []
for i in range(n):
    a_in, b_in = list(map(int,input().split()))
    a.append(a_in)
    b.append(b_in)

if h == 1:
    print(min(b))
else:
    dp = [0]*h
    dp[0] = min(b)
    for i in range(2,h+1):
        c = [0]*n
        for j in range(n):
            if i > a[j]:
                c[j] = b[j] + dp[i-a[j]-1]
            else:
                c[j] = b[j]
        dp[i-1] = min(c)
    print(dp[h-1])

Buggy python submission (verdict: Runtime Error):
h, n= list(map(int,input().split()))
a = []
b = []
for i in range(n):
    a_in, b_in = list(map(int,input().split()))
    a.append(a_in)
    b.append(b_in)

def ibis(h,a,b,n):
    if h <= 0:
        return 0
    else:
        c = [0]*n
        for i in range(n):
            c[i] = b[i] + ibis(h-a[i],a,b,n)
        return(min(c))
 
print(ibis(h,a,b,n))

Fixed submission:
h, n= list(map(int,input().split()))
a = []
b = []
for i in range(n):
    a_in, b_in = list(map(int,input().split()))
    a.append(a_in)
    b.append(b_in)

if h == 1:
    print(min(b))
else:
    dp = [0]*h
    dp[0] = min(b)
    for i in range(2,h+1):
        c = [0]*n
        for j in range(n):
            if i > a[j]:
                c[j] = b[j] + dp[i-a[j]-1]
            else:
                c[j] = b[j]
        dp[i-1] = min(c)
    print(dp[h-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int,input().split()))
flag = 0
ans = 0
for i in range(n):
  for j in range(i):
    if p[j] >= p[i]:
      pass
    else:
      flag = 1
  if flag == 0:
    ans += 1
  else:
    flag = 0
print(ans)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
if n == 1:
    print(1)
else:
    mn = p[0]
    ans = 1
    for i in range(1,n):
        if p[i] < mn:
            mn = p[i]
            ans += 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int,input().split()))
flag = 0
ans = 0
for i in range(n):
  for j in range(i):
    if p[j] >= p[i]:
      pass
    else:
      flag = 1
  if flag == 0:
    ans += 1
  else:
    flag = 0
print(ans)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
if n == 1:
    print(1)
else:
    mn = p[0]
    ans = 1
    for i in range(1,n):
        if p[i] < mn:
            mn = p[i]
            ans += 1
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,k,q = map(int, input().split())
b = []
for i in range(n):
    b.append(0)
for i in range(q):
    a = int(input())
    b[a] += 1
for i in range(n):
    if b[i] > q - k:
        print('Yes')
    else:
        print('No')

Fixed submission:
n,k,q = map(int, input().split())
b = []
for i in range(n):
    b.append(0)
for i in range(q):
    a = int(input())
    b[a-1] += 1
for i in range(n):
    if b[i] > q - k:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = list(map(int, input().split()))
a = b[0] + b[n-1]
for i in range(0,n-1):
    a = a + min(b[i],b[i+1])
print(a)

Fixed submission:
n = int(input())
b = list(map(int, input().split()))
a = b[0] + b[n-2]
if n > 2:
    for i in range(0,n-2):
        a = a + min(b[i],b[i+1])
print(a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
if n == 1:
    print('Yes')
else:
    i = 0
    f = 0
    while i < n-1:
        if h[i]-h[i+1] > 1:
            print('No')
            i = n 
        elif h[i]-h[i+1] == 1:
            f += 1
            if f == 2:
                print('No')
                i = n
            else:
                i += 1
        elif h[i] == h[i+1]:
            i += 1
        else:
            f = 0
            i += 1
if i == n-1:
    print('Yes')

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
if n == 1:
    print('Yes')
else:
    i = 0
    f = 0
    while i < n-1:
        if h[i]-h[i+1] > 1:
            print('No')
            i = n 
        elif h[i]-h[i+1] == 1:
            f += 1
            if f == 2:
                print('No')
                i = n
            else:
                i += 1
        elif h[i] == h[i+1]:
            i += 1
        else:
            f = 0
            i += 1
    if i == n-1:
        print('Yes')
Buggy python submission (verdict: Runtime Error):
a, b, c = list(map(int, input().split()))
if a + b >= c - 1:
    print(b+c)
else:
    print(a+2b+1)

Fixed submission:
a, b, c = list(map(int, input().split()))
if a + b >= c - 1:
    print(b+c)
else:
    print(a+2*b+1)
Buggy python submission (verdict: Runtime Error):
a, b, c = list(map(int, input().split()))
if a >= b && a >= c:
    print(10*a + b + c)
elif b >= a && b >= c:
    print(10*b + a + c)
else:
    print(10*c + a + b)   

Fixed submission:
a, b, c = list(map(int, input().split()))
if a >= b and a >= c:
    print(10*a + b + c)
elif b >= a and b >= c:
    print(10*b + a + c)
else:
    print(10*c + a + b)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(K: int, S: str):
    if (len(S) <= K):
        print(S)
    else:
        print(S[0:K], "...", sep='')
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(K, S)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int):
    mod = N % 10
    if mod in [2, 4, 5, 7, 9]:
        print("hon")
    elif mod in [0, 1, 6, 8]:
        print("pon")
    else:
        print("bon")
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(K: int, S: str):
    if (len(S) <= K):
        print(S)
    else:
        print(K[0:K+1], "...", sep='')
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(K, S)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

import sys

def solve(K: int, S: str):
    if (len(S) <= K):
        print(S)
    else:
        print(S[0:K], "...", sep='')
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(K, S)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(K: int, S: str):
    if (len(S) <= K):
        print(S)
    else:
        print(K[0:K+1], "...", sep='')
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(K, S)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

import sys

def solve(K: int, S: str):
    if (len(S) <= K):
        print(S)
    else:
        print(S[0:K], "...", sep='')
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(K, S)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys

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

loop = 1

while (1):
  for i in l:
    if (i % (2 ** (loop + 1)) != 0):
      print(loop )
      sys.exit(0)
  loop = loop + 1


Fixed submission:
l = input()

b = 0

for i in l[0], l[1], l[2]:
  if (int(i) == 1):
    b = b+1

print(b)

Buggy python submission (verdict: Runtime Error):
import sys

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

loop = 1

while (1):
  for i in l:
    if (i % (2 ** loop) != 0):
      print(loop - 1)
      sys.exit(0)
  loop = loop + 1


Fixed submission:
l = input()

b = 0

for i in l[0], l[1], l[2]:
  if (int(i) == 1):
    b = b+1

print(b)
Buggy python submission (verdict: Runtime Error):
imporet re

N = input()

if re.match(r'[2,4,5,7,9]', N[-1]):
	print('hon')
elif re.match(r'[0,1,6,8]', N[-1]):
	print('pon')
else:
	print('bon')

Fixed submission:
import re

N = input()

if re.match(r'[2,4,5,7,9]', N[-1]):
	print('hon')
elif re.match(r'[0,1,6,8]', N[-1]):
	print('pon')
else:
	print('bon')
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
votes = [int(i) for i in input().split()]
count = [1 for vote in votes if vote >= sum(votes) * 1 / (4 * M)]
if count >= M:
  print('Yes')
else:
  print('No')

Fixed submission:
N, M = map(int, input().split())
votes = [int(i) for i in input().split()]
count = [1 for vote in votes if vote >= sum(votes) * 1 / (4 * M)]
if sum(count) >= M:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n, b, a = map(int, input().split())
print(n // (a + b) * b + min(n % (a + b), b)

Fixed submission:
def count_balls(n, b, a):
	if b == 0:
		return 0
	
	num = n // (a + b)
	mod = n % (a + b)
	if mod != 0:
		if mod < b:
			return num * b + mod
		else:
			return num * b + b
	else:
		return num * b

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

Fixed submission:
n = int(input())
b = list(map(int, input().split()))
s=0
if n==2:
  print(b[0]*2)
else:
  if(b[0]<b[1]):
  	s = b[0]*2+b[-1]
  else:
  	s = b[0]+b[1]+b[-1]
  for i in range(1,n-2):
  	s+=min(b[i],b[i+1])
    
  print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
temp = []
for i in range(n):
	temp.append(int(input()))

if n > 1:
	print(max(temp[1:n]))

	for i in range(1,n-1):
		print(max(max(temp[0:i]), max(temp[i+1:n])))

	print(max(temp[0:n-1]))

else:
	print(temp[0])

Fixed submission:
n = int(input())
temp = []
for i in range(n):
	temp.append(int(input()))

sort = temp[:]

sort.sort()

maximum = sort[-1]


for i in temp:
	if i != maximum:
		print(maximum)

	else:
		print(sort[-2])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
temp = []
for i in range(n):
	temp.append(int(input()))

if n > 1:
	print(max(temp[1:n]))

	for i in range(1,n-1):
		print(max(max(temp[0:i]), max(temp[i+1:n])))

	print(max(temp[0:n-1]))

else:
	print(temp[0])

Fixed submission:
n = int(input())
temp = []
for i in range(n):
	temp.append(int(input()))

sort = temp[:]

sort.sort()

maximum = sort[-1]


for i in temp:
	if i != maximum:
		print(maximum)

	else:
		print(sort[-2])
Buggy python submission (verdict: Runtime Error):
h a = list(map(int, input().split()))

a_total = 0
count = 0
for i in range(0,h):
  a_total += a
  count += 1
  if h <= a_total:
    print(count)
    break


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

q, mod = divmod(list[0], list[1])
if mod == 0 :
  print(q)
else :
  print(int(q+1))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p_list = list(map(int,input().split()))

count = 1
for i in range(1, n):
  if min(p_list[:i+1]) == p_list[i] :
    count += 1
      
print(count)

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

count = 1
min = min(p_list[:1]) 
for i in range(1, n):
  if min > p_list[i] :
    count += 1
    min = p_list[i] 

print(count)

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

count = 1
for i in range(1, len(p_list)):
  if len(p_list) >= 0 :
    if min(p_list[:i+1]) == p_list[i] :
      count += 1
      
print(count)

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

count = 1
min = min(p_list[:1]) 
for i in range(1, n):
  if min > p_list[i] :
    count += 1
    min = p_list[i] 

print(count)
Buggy python submission (verdict: Runtime Error):
c = str(input())

List = ['a','b','c','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

c_index = List.index(c)
ans = List[c_index+1]
print(ans)

Fixed submission:
c = str(input())

List = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

c_index = List.index(c)
ans = List[c_index+1]
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in A_index :
  if j != n-1 :
    if s[j+1] == 'B' :
      if s[j+2] == 'C' :
        count += 1

print(count)

Fixed submission:
n = int(input())
s = list(input())

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in A_index :
  if j != n-1 :
    if s[j+1] == 'B' :
      if j != n-2 :
        if s[j+2] == 'C' :
          count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())

A_index = [i for i, x in enumerate(s) if x == 'A']
print(A_index)

count = 0
for j in A_index :
  print(j)
  if j != n-1 :
    if s[j+1] == 'B' :
      if s[j+2] == 'C' :
        count += 1

print(count)

Fixed submission:
n = int(input())
s = list(input())

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in A_index :
  if j != n-1 :
    if s[j+1] == 'B' :
      if j != n-2 :
        if s[j+2] == 'C' :
          count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())

A_index = [i for i, x in enumerate(s) if x == 'A']
print(A_index)

count = 0
for j in A_index :
  print(j)
  if j != n-2 :
    if s[j+1] == 'B' :
      if s[j+2] == 'C' :
        count += 1

print(count)

Fixed submission:
n = int(input())
s = list(input())

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in A_index :
  if j != n-1 :
    if s[j+1] == 'B' :
      if j != n-2 :
        if s[j+2] == 'C' :
          count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in range(A_index[0], n-1) :
  if s[j+1] == 'B' :
    if s[j+2] == 'C' :
      count += 1

print(count)

Fixed submission:
n = int(input())
s = list(input())

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in A_index :
  if j != n-1 :
    if s[j+1] == 'B' :
      if j != n-2 :
        if s[j+2] == 'C' :
          count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
n = input()
s = list(input())

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in A_index :
  if s[j+1] == 'B' :
    if s[j+2] == 'C' :
      count += 1

print(count)


Fixed submission:
n = int(input())
s = list(input())

A_index = [i for i, x in enumerate(s) if x == 'A']

count = 0
for j in A_index :
  if j != n-1 :
    if s[j+1] == 'B' :
      if j != n-2 :
        if s[j+2] == 'C' :
          count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
n = list(input().split())
s, t = list(input().split())

ans = []
for i in range(0, int(len(n)+1)):
  ans.append(s[i])
  ans.append(t[i])
  
print(''.join(map(str,ans)))

Fixed submission:
n = list(input().split())
s, t = list(input().split())

ans = []
for i in range(0, int(n[0])):
  ans.append(s[i])
  ans.append(t[i])
  
print(''.join(map(str,ans)))
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())

if A =< 9:
  if B =< 9:
    x = A*B
  else x = -1
else x = -1

print(x)
		

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

if A <= 9:
  if B <= 9:
    x = A*B
  else:
    x = -1
else:
  x = -1

print(x)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = list(map(int,input().split()))

s = S(K)
s_large = s.upper()

S = [s_large if s=S(K) else 0 for s in S]

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

#print(N,K,S)

s = S[K-1]
#print(s)
s_large = s.lower()
#print(s_large)

S[K-1] = s_large
print(''.join(S))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
room_adjacent = [[] for _ in range(n)]
for _ in range(m):
  room1, room2 = map(int, input().split())
  room_adjacent[room1-1].append(room2)
  room_adjacent[room2-1].append(room1)

def label_rooms(old_room):
  for room in room_adjacent[old_room-1]:
    if room_labels[room-1] == 0: room_labels[room-1] = old_room
  for room in room_adjacent[old_room-1]:
    if room_labels[room-1] == old_room: label_rooms(room)

room_labels = [1]+[0]*(n-1)
label_rooms(1)
if 0 in room_labels:
  print("No")
else:
  print("Yes")
  [print(value) for value in room_labels[1:]]

Fixed submission:
from collections import deque
n, m = map(int, input().split())
room_adjacent = [[] for _ in range(n)]
for _ in range(m):
  room1, room2 = map(int, input().split())
  room_adjacent[room1-1].append(room2)
  room_adjacent[room2-1].append(room1)

room_labels = [1]+[0]*(n-1)
old_room = 1
path_queue = deque((old_room, room) for room in room_adjacent[old_room-1])
while path_queue:
  old_room, new_room = path_queue.pop()
  if room_labels[new_room-1] == 0:
    room_labels[new_room-1] = old_room
    for another_room in room_adjacent[new_room-1]:
      path_queue.appendleft((new_room, another_room))
  
if 0 in room_labels:
  print("No")
else:
  print("Yes")
  [print(value) for value in room_labels[1:]]
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil, sqrt
x = int(input())
# x = a**5 - b**5
# a**5 - b**5 = (a − b)(a**4 + a**3b + a**2b**2 + ab**3 + b**4)
def get_factors(n):
  set_factors = {n}
  q = n
  for i in range(1, ceil(sqrt(n))):
    if q%i == 0:
      set_factors.add(i)
      q = q//i
    if q<=1: return set_factors
  return set_factors
all_factors = get_factors(x)
def test_factor(factor):
  upper = x
  lower = 0
  while upper!=lower:
    a = (upper+lower)//2
    if a**5-(a-factor)**5 < x:
      lower = a
    elif a**5-(a-factor)**5 == x:
      return (a, a-factor)
    else:
      upper = a
  return None
for factor in all_factors:
  result = test_factor(factor)
  if result!=None:
    print(result[0], result[1])
    break

Fixed submission:
def eval_pair(A, B, x):
  return A**5-B**5 == x

def get_pair(x):
  # exit early for x a power of 5.
  # apart from this, A,B don't need to be zero.
  A = int(round(x**(1/5)))
  if A**5 == x: return (A, 0)
  # try A, B:
  # +,+ and +,-
  # don't need -,- (same as +,-)
  # can't do -,+ because x is constrained positive
  # for +,+ A>=120 would give x>10**9
  # so 1<=A<120 and 1<=B<119
  valid = [(A,B) for A in range(1,120) for B in range(1,119) if eval_pair(A,B,x)]
  if valid: return valid.pop()
  # for +,- both are positive so A>=64 would give x=10**9
  # so 1<=A<64 and -64<B<-1
  valid = [(A,B) for A in range(1,64) for B in range(-1,-64, -1) if eval_pair(A,B,x)]
  if valid: return valid.pop()

x = int(input())
valid_pair = get_pair(x)
print(*valid_pair)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

dict_diffs = dict()
for i in range(1, n+1):
  dict_diffs[i+a[i-1]] = dict_diffs1.get(i+a[i-1], 0) + 1
total = 0
for j in range(1, n+1):
  total += dict_diffs1.get(j-a[j-1], 0)
print(total)

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

dict_diffs1 = dict()
dict_diffs2 = dict()
for i in range(1, n+1):
  dict_diffs1[i+a[i-1]] = dict_diffs1.get(i+a[i-1], 0) + 1
  dict_diffs2[i-a[i-1]] = dict_diffs2.get(i-a[i-1], 0) + 1
total = 0
for j in range(1, n+1):
  total += dict_diffs1.get(j-a[j-1], 0)
  total += dict_diffs2.get(j+a[j-1], 0)
total = total//2
print(total)

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

total = 0
for i in range(n):
  for j in range(i+1, n):
    total += int(abs(j-i) == a[i]+a[j])
print(total)

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

dict_diffs1 = dict()
dict_diffs2 = dict()
for i in range(1, n+1):
  dict_diffs1[i+a[i-1]] = dict_diffs1.get(i+a[i-1], 0) + 1
  dict_diffs2[i-a[i-1]] = dict_diffs2.get(i-a[i-1], 0) + 1
total = 0
for j in range(1, n+1):
  total += dict_diffs1.get(j-a[j-1], 0)
  total += dict_diffs2.get(j+a[j-1], 0)
total = total//2
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
num_R = sum(int(val=="R") for val in s)
num_G = sum(int(val=="G") for val in s)
num_B = sum(int(val=="B") for val in s)
total_triplets = num_R*num_G*num_B
num_missing = 0
for centre_point in range(1, n-1):
  for halfwidth in range(1, 1+min(centre_point, n-centre_point-1)):
    first_possible = s[centre_point-halfwidth] != s[centre_point]
    second_possible = s[centre_point] != s[centre_point+halfwidth]
    third_possible = s[centre_point-halfwidth] != s[centre_point+halfwidth]
    if first_possible and second_possible and third_possible: num_missing += 1
print(total_triplets-num_missing)

Fixed submission:
n = int(input())
s = input()
total_triplets = sum(int(val=="R") for val in s)*sum(int(val=="G") for val in s)*sum(int(val=="B") for val in s)
num_missing = 0
for centre_point in range(1, n-1):
  for halfwidth in range(1, 1+min(centre_point, n-centre_point-1)):
    if s[centre_point-halfwidth] != s[centre_point]:
      if s[centre_point] != s[centre_point+halfwidth]:
        if s[centre_point-halfwidth] != s[centre_point+halfwidth]: num_missing += 1
print(total_triplets-num_missing)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split)
print(c, a, b)

Fixed submission:
a, b, c = map(int, input().split())
print(c, a, b)