Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02658 (python)

Fixed submission:
n=int(input())
alis=sorted(list(map(int,input().split())))
p=alis[0]
if p==0:
  print(0)
  exit()
bre=False
for i in range(1,n):
  p*=alis[i]
  
  
  if len(list(str(p)))>18:
    bre=True
    break


if bre:
  sa=list(map(int,list(str(p))))
  if sum(sa)!=1:print(-1)
  else:print(p)
else:print(p)

Buggy submission (verdict: Runtime Error):
n=int(input())
alis=sorted(list(map(int,input().split())))
p=alis[0]
if p==0:
  print(0)
  exit()
for i in range(1,n):
  p*=alis[i]
  if len(list(str(p)))>18:
  sa=list(map(int,list(str(p))))
    
  if sum(sa)!=1:
    print(-1)
    exit()
print(p)
Problem p02660 (python)

Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1:
        arr.append([temp, 1])
 
    if arr==[]:
        arr.append([n, 1])
 
    return arr
 
t=int(input())
if t==1:
  print(0)
  exit()
 
fac=factorization(t)
 
def pcount(a):
  p=1
  cout=0
  while a>0:
    a=a-p
    p+=1
    if a<0:break
    cout+=1
  return cout
#print(fac)
tt=0
 
for po in fac:
  
  cc=pcount(po[1])
  #print(cc)
  tt+=cc

print(tt)

Buggy submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

t=int(input())
if t==1:
  print(0)
  exit()

fac=factorization(t)

def pcount(a):
  p=1
  cout=0
  while a>0:
    a=a-p
    p+=1
    if a<0:break
    cout+=1
  return cout

tt=0
for po in range(len(fac)):
  cc=pconut(po[i][1])
  tt+=cc

print(cc)
Problem p02664 (python)

Fixed submission:
t=input()
s=[0]*len(t)

for i in range(len(t)):
  
    if t[i]=='?':
        if i==0:
            if len(t)>=2:
                if t[i+1]=='D':
                    s[i]='P'
                else:
                    s[i]='D'
            else:s[i]='D'
      
      
        elif i==len(t)-1:
            s[i]='D'
        
    
        else:
            if s[i-1]=='P':s[i]='D'
            elif t[i+1]=='P':s[i]='D'
            else:s[i]='P'

    elif t[i]=='D' or t[i]=='P':s[i]=t[i]
    else:continue
#print(s)
print(''.join(s))

Buggy submission (verdict: Runtime Error):
t=input()
s=[0]*len(t)
for i in range(len(t)):
  
    if t[i]=='?':
        if i==0:
            if t[i+1]=='D':
                s[i]='P'
            else:
                s[i]='D'
      
      
        elif i==len(t)-1:
            s[i]='D'
        
    
        else:
            if s[i-1]=='P':s[i]='D'
            elif t[i+1]=='P':s[i]='D'
            else:s[i]='P'

    elif t[i]=='D' or t[i]=='P':s[i]=t[i]
    else:continue
#print(s)
print(''.join(s))

Buggy submission (verdict: Runtime Error):
t=input()
s=[0]*len(t)
for i in range(len(t)):
  
  if t[i]=='?':
    if i==0:
      if t[i+1]=='D':s[i]='P'
      else:s[i]='D'
      continue
      
    if i==len(t)-1:
        s[i]='D'
        continue
    
    if s[i-1]=='P':s[i]='D'
    elif t[i+1]=='P':s[i]='D'
    else:s[i]='P'
  else:s[i]=t[i]
#print(s)
print(''.join(s))

Buggy submission (verdict: Runtime Error):
t=input()
s=[0]*len(t)
for i in range(len(t)):
  
  if t[i]=='?':
    if i==0:
      if t[i+1]=='D':s[i]='P'
      else:s[i]='D'
      
    if i==len(t)-1:s[i]='D'
    
    if s[i-1]=='P':s[i]='D'
    elif t[i+1]=='P':s[i]='D'
    else:s[i]='P'
  else:s[i]=t[i]
print(''.join(s))

Buggy submission (verdict: Runtime Error):
t=input()
s=[0]*len(t)
for i in range(len(t)):
  
  if t[i]=='?':
    if i==0:
      if t[i+1]=='D':s[i]='P'
      else:s[i]='D'
      
    if i==len(t)-1:s[i]='D'
    
    if t[i-1]=='P':s[i]='D'
    elif t[i+1]=='P':s[i]='D'
    else:s[i]='P'
  else:s[i]=t[i]
print(''.join(s))

Buggy submission (verdict: Runtime Error):
t=input()
s=[0]*len(t)
for i in range(len(t)):
  
  if t[i]=='?':
    if i==0:
      if t[i+1]=='D':s[i]='P'
      else:s[i]='D'
      
    if i==len(t)-1:
      if t[i-1]=='D':s[i]='P'
      else:s[i]='D'
    
    if t[i-1]=='P':s[i]='D'
    elif t[i+1]=='P':s[i]='D'
    else:s[i]='P'
  else:s[i]=t[i]
print(''.join(s))
Problem p02675 (python)

Fixed submission:
N=input()
w=int(N[-1])
h=[2,4,5,7,9]
p=[0,1,6,8]
b=3
if w==b:
  print('bon')
elif w in p:
  print('pon')
else:
  print('hon')

Buggy submission (verdict: Runtime Error):
N=input()
w=int(n[-1])
h=[2,4,5,7,9]
p=[0,1,6,8]
b=3
if w==b:
  print('bon')
elif w in p:
  print('pon')
else:
  print('hon')
Problem p02678 (python)

Fixed submission:
from collections import deque
 
n,m=map(int,input().split())
node=[[] for _ in range(n)]
 
for _ in range(m):
    a,b=map(lambda x:int(x)-1,input().split())
    node[a].append(b)
    node[b].append(a)
    
#print(node)
 

seen=[False]*n
depth=[-1]*n
todo=deque([])
todo.append(0)
depth[0]=1

    
while len(todo)>0:
    p=todo[0]
    
    seen[p]=True
    to=node[p]
    for i in to:
        if seen[i]:continue
        if depth[i]==-1:
            depth[i]=depth[p]+1
            todo.append(i)
    todo.popleft()
 
 

if min(depth)==-1:
    print('No')
else:
    print("Yes")
    for i in range(1,n):
        for j in node[i]:
            if depth[i]>depth[j]:
                print(j+1)
                break

Buggy submission (verdict: Runtime Error):
from collections import deque
 
n,m=map(int,input().split())
node=[[] for _ in range(n)]
 
for _ in range(m):
    a,b=map(lambda x:int(x)-1,input().split())
    node[a].append(b)
    node[b].append(a)
    
#print(node)
 

seen=[False]*n
depth=[-1]*n
todo=deque([])
todo.append(0)
depth[0]=1

    
while len(todo)>0:
    p=todo[0]
    
    seen[p]=True
    to=node[p]
    for i in to:
        if seen[i]:continue
        if depth[i]==-1:
            depth[i]=depth[p]+1
            todo.append(i)
    todo.popleft()
 
 

if min(depth)==-1:
    print('No')
else:
    print("Yes")
    for i in range(1,n):
        for j in node(i):
            if depth[i]>depth[j]:
                print(j+1)
                break

Buggy submission (verdict: Runtime Error):
from collections import deque

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

for _ in range(m):
    a,b=map(lambda x:int(x)-1,input().split())
    node[a].append(b)
    node[b].append(a)
    
#print(node)


seen=[False]*n
depth=[0]*n
todo=deque([])
todo.append(0)
    
    
while len(todo)>0:
    p=todo[0]
    
    seen[p]=True
    to=node[p]
    for i in to:
        if seen[i]:continue
        if not (i in todo):
            depth[i]+=depth[p]+1
            todo.append(i)
    todo.popleft(0)



#print(depth)

sekai=[]

for i in range(1,n):
    for j in node[i]:
        if depth[j]<depth[i]:
            sekai.append(j+1)
            break
#print(sekai)

if len(sekai)!=(n-1):
    print('No')
else:
    print("Yes")
    for a in sekai:
        print(a)
Problem p02681 (python)

Fixed submission:
s = input()
t = input()
if s == t[:-1]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
S=list(input())
T=list(input())
flag = True
for i in range(N):
    s = S[i]
    t = T[i]
    if s != t:
        flag = False
        
if flag:
    if len(T) == N+1:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
S=input()
T=input()
flag = True
for i in range(N):
    s = S[i]
    t = T[i]
    if s != t:
        flag = False
        
if flag:
    if len(T) == N+1:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
flag = True
for i in range(N):
    s = S[i]
    t = T[i]
    if s != t:
        flag = False
        
if flag:
    if len(T) == N+1:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import numpy as np
S=np.array(list(input()))
T=np.array(list(input()))
if all(S==T[:-2]):
  print("Yes")
else:
  print('No')
Problem p02683 (python)

Fixed submission:
n,m,x=map(int,input().split())
clis=[]
alis=[]
for _ in range(n):
  tu=list(map(int,input().split()))
  clis.append(tu[0])
  alis.append(tu[1:])


ma_c=[]
for i in range(2**n):
  bag=[]
  price=0
  for j in range(n):
    if ((i>>j)&1):
      price+=clis[j]
      bag.append(alis[j])
  pac=[0]*m
  for t in range(len(bag)):
    for k in range(m):
        pac[k]+=bag[t][k]
  if all([pac[t]>=x for t in range(m)]):
    ma_c.append(price)


if len(ma_c)!=0:
  print(min(ma_c))
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
n,m,x=map(int,input().split())
clis=[]
alis=[]
for _ in range(n):
  tu=list(map(int,input().split()))
  clis.append(tu[0])
  alis.append(tu[1:])


ma_c=[]
for i in range(2**n):
  bag=[]
  price=0
  for j in range(n):
    if ((i>>j)&1):
      price+=clis[j]
      bag.append(alis[j])
  pac=[0]*m
  for t in range(len(bag)):
    for k in range(m):
        pac[k]+=bag[t][k]
  if all([pac[t]>=x for t in range(m)]):
    ma_c.append(price)

print(min(ma_c))

Buggy submission (verdict: Runtime Error):
import pandas as pd
import numpy as np
n,m,x=map(int,input().split())
zen=np.array(list(map(int,input().split()) for _ in range(n)))
a=pd.Series(zen.sum(1))
df=pd.DataFrame(zen)
df=df.join(a)
df=df.sort_values(a)

p=df.iloc[-1]
df=df.drop(df.index[[-1]])
while all(p[1:]>=x):
  p+=df.iloc[-1]
print(p[0].sum())
Problem p02684 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(lambda x:int(x)-1,input().split()))
town=[0]
set={0}
i=0
while True:
  idx=town[-1]
  if a[idx] in set:
    s=a[idx]
    i+=1
    break
  else:
    i+=1
    town.append(a[idx])
    set.add(a[idx])
if i!=n:
  idp=town.index(s)
  chain=len(town[:idp])
  cycle=len(town[idp:])
  if k<=chain:
    print(town[k]+1)
  else:
    p=(k-chain)%cycle + chain
    print(town[p]+1)
else:
  print(town[k%n]+1)

Buggy submission (verdict: Runtime Error):
import math
n,k=map(int,input().split())
a_lis=list(map(int,input().split()))
direct={ i+1:a_lis[i] for i in range(len(a_lis))}
 
d_lis=[1]
j=direct[1]
while True:
  d_lis.append(j)
  j=direct[j]
  if j==1:
    break
dp=d_lis*(math.floor(k/len(d_lis))+1)
 
print(dp[k-1])

Buggy submission (verdict: Runtime Error):
import math
n,k=map(int, input().split())
a_lis=[map(int,input().split())]
direct={ i+1:a_lis[i] for i in range(n)}

d_lis=[1]
j=direct[1]
while True:
  d_lis.append(j)
  j=direct[j]
  if j==1:
    break

dp=d_lis*(math.floor(k/len(d_lis))+1)

print(dp[k-1])
Problem p02687 (python)

Fixed submission:
S=input()
if S=="ABC":
  print("ARC")
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
import numpy as np
N,M =map(int,input().split())
h_lis=np.array(list(map(int,input().split())))
way_lis=[list(map(int,input().split())) for _ in range(M)]

tes=0
for i in range(N):
    nears=[]
    for way in way_lis:
        if i+1 in way:
            nears.extend(way)
    for j,ne in enumerate(nears):
        if j==0:
            h=max(h_lis[ne[0]-1],h_lis[ne[1]-1])
            z=h
        else:
            k=z
            h=max(h_lis[ne[0]-1],h_lis[ne[1]-1])
            z=max(k,h)
    if z==h_lis[i]:
        tes+=1
print(tes)
Problem p02708 (python)

Fixed submission:
po=pow(10,9)+7
n,k=map(int,input().split())
cc=0
for i in range(k,n+2):
  cc+=(n*i-i*(i-1)+1)%po
print(cc%po)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
a=(N*(N+1)*(N+2)-(K*(K-1)*(3*N-2*K+4)))/6
print(a%(10**9+7)
Problem p02714 (python)

Fixed submission:
from collections import Counter
n=int(input())
stri=list(input())
cc=Counter(stri)

count=cc['R']*cc['G']*cc['B']


for i in range(n-2):
  for j in range(i+1,n-1):
    if stri[j]==stri[i]:continue
      
    lib=['R','G','B']
    lib.remove(stri[i])
    lib.remove(stri[j])
    t=lib.pop()
    
    skip_k=2*j-i
    #print(i,j,skip_k)
    if skip_k>n-1:continue
    if stri[skip_k]==t:
      count-=1
print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np
from bisect import bisect

n=int(input())
dic={ 'R':[], 'G':[], 'B':[] }

stri=list(input())
count=0
for i,v in enumerate(stri):
  #print(i,v)
  dic[v].append(i)
  
for name in dic:
  dic[name]=np.asarray(dic[name])
#print(dic)
for i in range(n):
  lib=['R','G','B']
  lib.remove(stri[i])
  #print(lib)
  for col in lib:
    for j in dic[col][dic[col]>i]:
      t=[i for i in lib if i != col].pop()
      skip_k=2*i-j
      idx=bisect(dic[t],skip_k)-1
      if dic[t][idx]==skip_k:
        count+=len(dic[t][dic[t]>j])-1
      else:
        count+=len(dic[t][dic[t]>j])
      
print(count)
Problem p02719 (python)

Fixed submission:
n,k=map(int,input().split())
if k>=n:
  print(min(k-n,n))
else:
  
  print(min(n%k,abs(n%k-k)))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
if k>=n:
  print(min(k-n,n))
else:
  
  print(min(n%k,abs(n%k-k))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
if k>=n:
  print(min(k-n,n))
else:
  
  print(min(n%k,abs(n%k-k))
Problem p02720 (python)

Fixed submission:
k=int(input())
from collections import deque
q=deque([])
i=0
while True:
  if i<=8:
    q.append(i+1)
    i+=1
    if i==k:break
    continue
  
  x=q.popleft()
  
  if x%10!=0:
    q.append(x*10+x%10-1)
    i+=1
    if i==k:break
    
  q.append(x*10+x%10)
  i+=1
  if i==k:break
  
  if x%10!=9:
    q.append(x*10+x%10+1)
    i+=1
    if i==k:break
      
print(q.pop())

Buggy submission (verdict: Runtime Error):
n=int(input())
from collections import deque
q=deque([])
i=0
while True:
  if i<=8:
    q.append(i+1)
    i+=1
    if i==k:break
    continue
  
  x=q.popleft()
  
  if x%10!=0:
    q.append(x*10+x%10-1)
    i+=1
    if i==k:break
    
  q.append(x*10+x%10)
  i+=1
  if i==k:break
  
  if x%10!=9:
    q.append(x*10+x%10+1)
    i+=1
    if i==k:break
      
print(q.pop())
Problem p02730 (python)

Fixed submission:
s=list(input())
n=len(s)
a=all([p==q for p,q in zip(s,reversed(s))])
b=all([p==q for p,q in zip(s[:(n-1)//2],reversed(s[:(n-1)//2]))])
c=all([p==q for p,q in zip(s[(n+3)//2-1:],reversed(s[(n+3)//2-1:]))])

if a and b and c:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
a=list(input())
b=a[:int((n-1)/2)+1]
c=a[int((n+3)/2):]
n=len(a)
anal = a==reversed(a)
manco = b==reversed(b)
portio = c==reversed(c)

if anal and manco and portio:
  print('Yes')
esle:
  print('No')
Problem p02732 (python)

Fixed submission:
def combi(count):
  if n==1:return 0
  elif n==2:return 1
  else:return int(count*(count-1)/2)
 
 
n=int(input())
alis=list(map(int,input().split()))
dick={st:0 for st in set(alis)}
for i in range(n):
  p=alis[i]
  dick[p]+=1
#print(dick)
point=0
for v in dick.values():
  point+=combi(v)
 
 
for i in range(n):
  idx=alis[i]
  minus=dick[idx]-1
  print(point-minus)

Buggy submission (verdict: Runtime Error):
def combi(count):
  if n==1:return 0
  elif n==2:return 1
  else:return int(count*(count-1)/2)


n=int(input())
alis=list(map(int,input().split()))
dick=dict()
for i in range(n):
  p=alis[i]
  dick[p]+=1

point=0
for k,v in dick:
  point+=combi(v)


for i in range(n):
  idx=alis[i]
  minus=dick[idx]-1
  print(point-minus)

Buggy submission (verdict: Runtime Error):
"""from operator import mul
from functools import reduce
 
def cmb(n,r):
  if n<2: return 0
  r = min(n-r,r)
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under
"""
from math import factorial
def cmb(n,r=2):
  
  return factorial(n) / factorial(r) / factorial(n - r)
 
 
N=int(input())
a_lis=list(map(int,input().split()))
 
olt={i:0 for i in set(a_lis)}
for i in a_lis:
  olt[i]+=1
#print(olt)
for j in range(N):
  index=a_lis[j]
  olt[index]-=1
  #print(olt)
  san=0
  for i in set(a_lis):
    if olt[i] <2:
      continue
    #print(i,olt[i])
    san+=cmb(olt[i])
  
  print(int(san))
  olt[index]+=1

Buggy submission (verdict: Runtime Error):
"""from operator import mul
from functools import reduce

def cmb(n,r):
  if n<2: return 0
  r = min(n-r,r)
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under
"""
from math import factorial
def cmb(n,r=2):
  
  return factorial(n) / factorial(r) / factorial(n - r)


N=int(input())
a_lis=list(map(int,input().split()))

olt={i:0 for i in set(a_lis)}
for i in a_lis:
  olt[i]+=1
#print(olt)
for j in range(N):
  index=a_lis[j]
  olt[index]-=1
  #print(olt)
  san=0
  for i in set(a_lis):
    if olt[i] <2:
      continue
    #print(i,olt[i])
    san+=cmb(olt[i])
  
  print(int(san))
  olt[index]+=1

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n,r):
  	if n == 1 or n == 0: return 0
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

olt={i:0 for i in set(a_lis)}
for i in a_lis:
  olt[i]+=1
for j in range(n):
  index=a_lis[j]
  olt[index]-=1
  
  z=sum([cmb(k,2) for key,k in olt])
  print(z)
  olt[index]+=1
Problem p03086 (python)

Fixed submission:
s=list(input())
n=len(s)
ans=[]
if n==1:
  if s.pop() in list('ATCG'):
    print(1)
    exit()

for i in range(n-1):
  for j in range(i+1,n+1):
    part=set(s[i:j])
    flag=True
    for p in part:
      if p not in list('ATGC'):
        flag=False
        break
    if flag==True:
      ans.append(len(s[i:j]))
#print(ans)
if ans:
  print(max(ans))
else:
  print(0)

Buggy submission (verdict: Runtime Error):
s=list(input())
n=len(s)
ans=[]
for i in range(n-1):
  for j in range(i+1,n+1):
    part=set(s[i:j])
    flag=True
    for p in part:
      if p not in list('ATGC'):
        flag=False
        break
    if flag==True:
      ans.append(len(part))
print(max(ans))
Problem p03087 (python)

Fixed submission:
n,q=map(int,input().split())
st=input()
ssum=[0,0]
for i in range(1,n):
    if st[i-1]=="A" and st[i]=='C':
        ssum.append(ssum[-1]+1)
    else:
        ssum.append(ssum[-1])
#print(len(ssum))
for i in range(q):
    a,b=map(int,input().split())
    print(ssum[b]-ssum[a])

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
st=input()
ssum=[0,0]
for i in range(1,n):
    if st[i-1]=="A" and st[i]=='C':
        ssum.append(ssum[-1]+1)
    else:
        ssum.append(ssum[-1])

for i in range(q):
    a,b=map(int,input().split())
    print(ssum[b+1]-ssum[a])
Problem p03281 (python)

Fixed submission:
n=int(input())
if n<105:
  print(0)
  exit()
else:
  c=0
  for i in range(105,n+1,2):
    p=0
    for j in range(1,i//2+1,2):
      if i%j==0:
        p+=1
    if p==7:
      c+=1
print(c)

Buggy submission (verdict: Runtime Error):
n=int(input())
if n<105:
  print(0)
else:
  c=0
  for i in range(105,n+1,2):
    p=0
    for j in range(1,i//2+1,2):
      if i%j==0:
        p+=1
    if p==7:
      c+=1
print(c)
Problem p03609 (python)

Fixed submission:
x,t=map(int,input().split())
print(max(0,x-t))

Buggy submission (verdict: Runtime Error):
n=int(input())
alis=list(map(int,input().split()))
xlis=set()
for i in alis:
    xlis.add(i-1)
    xlis.add(i+1)
    xlis.add(i)
#print(xlis)
counter=[0 for _ in range(len(xlis))]
t=-1
for x in xlis:
    t+=1
    for i in range(n):
        if x-1<=alis[i] and alis[i]<=x+1:
            counter[t]+=1
print(max(counter))
Problem p03611 (python)

Fixed submission:
n=int(input())
alis=list(map(int,input().split()))
xlis=dict()
for i in set(alis):
    xlis[i-1]=0
    xlis[i+1]=0
    xlis[i]=0
for i in alis:
    xlis[i-1]+=1
    xlis[i+1]+=1
    xlis[i]+=1
print(max(xlis.values()))

Buggy submission (verdict: Runtime Error):
n=int(input())
alis=list(map(int,input().split()))
xlis=set(alis)
for al in alis:
    alis.add(al-1)
    alis.add(al+1)
counter=[0 for _ in range(n)]
for x in xlis:
    for i in range(n):
        if x-1<=alis[i]<=x+1:
            counter[i]+=1
print(max(counter))
Problem p02691 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

CNT = [0] * (10 ** 7)

ans = 0
for i in range(N):
    a = A[i]
    p = i - a

    if 0 <= p <= (10 ** 7):
        ans += CNT[p]

    if 0 <= i + a <= (10 ** 7):
        CNT[i + a] += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

CNT = [0] * (10 ** 6)

ans = 0
for i in range(N):
    a = A[i]
    p = i - a

    if p > 0:
        ans += CNT[p]

    CNT[i + a] += 1

print(ans)
Problem p02715 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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


# nの約数列挙
def divisor(n):
    ans = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ans.append(i)
            if i**2 == n:
                continue
            ans.append(n // i)
    return ans  # sortされていない


MOD = 10 ** 9 + 7

ans = 0
num = 0
CNT = [0] * (K+1)
for i in range(K, 1, -1):
    n = K // i
    c = pow(n, N, MOD)

    c -= CNT[i]

    num += c

    f = divisor(i)
    for n in f:
        CNT[n] += c

    ans += c * i
    ans %= MOD


al = pow(K, N, MOD)
ans += al - num
ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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


# nの約数列挙
def divisor(n):
    ans = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ans.append(i)
            if i**2 == n:
                continue
            ans.append(n // i)
    return ans  # sortされていない


MOD = 10 ** 9 + 7

ans = 0
num = 0
CNT = [0] * (K+1)
for i in range(K, 1, -1):
    n = K // i
    c = pow(n, N, MOD)

    c -= CNT[i]

    num += c

    f = divisor(i)
    for n in f:
        CNT[n] += c

    ans += c * i
    ans %= MOD


al = pow(K, N, MOD)
ans += al - num
ans %= MOD

print(ans)