Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
List = sorted(list(map(int, input().split())))
for i in range(N):
  if List[i] == List[i + 1]:
    print("NO")
    break
else:
  print("YES")

Fixed submission:
N = int(input())
List = sorted(list(map(int, input().split())))
for i in range(N-1):
  if List[i] == List[i + 1]:
    print("NO")
    break
else:
  print("YES")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
List = sorted(list(map(int, input().split())))
for i in range (N):
  for j in range (i+1, N):
    if List[j] == List[i]:
      print("NO")
      break
  else:
    continue
  break
else:
  print("YES")

Fixed submission:
N = int(input())
List = sorted(list(map(int, input().split())))
for i in range(N-1):
  if List[i] == List[i + 1]:
    print("NO")
    break
else:
  print("YES")

Buggy python submission (verdict: Runtime Error):
N = int(input())
List = sort(list(map(int, input().split())))
for i in range (N):
  for j in range (i+1, N):
    if List[j] == List[i]:
      print("NO")
      break
  else:
    continue
  break
else:
  print("YES")

Fixed submission:
N = int(input())
List = sorted(list(map(int, input().split())))
for i in range(N-1):
  if List[i] == List[i + 1]:
    print("NO")
    break
else:
  print("YES")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
List = list(map(int, input().split()))
for i in range (N):
  for j in range (i+1, N):
    if List[j] == List[i]:
      print("NO")
      break
  else:
    continue
  break
else:
  print("YES")

Fixed submission:
N = int(input())
List = sorted(list(map(int, input().split())))
for i in range(N-1):
  if List[i] == List[i + 1]:
    print("NO")
    break
else:
  print("YES")
Buggy python submission (verdict: Runtime Error):
H, A=map(int, input().split)
if H % A == 0:
  print(H / A)
else:
  print(H // A + 1)

Fixed submission:
H, A=map(int, input().split())
if H % A == 0:
  print(H // A)
else:
  print(H // A + 1)
Buggy python submission (verdict: Runtime Error):
H, N=map(int, input().split())
List=list(map(int,input().split()))
a = 0:
for j in range(N):
  a = a + List[j]

if a >= H:
  print("Yes")
else:
  print("No")

Fixed submission:
H, N=map(int, input().split())
List=list(map(int,input().split()))
a = 0
for j in range(N):
  a = a + List[j]

if a >= H:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
H, N=map(int, input().split())
List=[int(i) for i in input().split()]
a = 0:
for j in range(N):
  a = a + List[j]

if a >= H:
  print("Yes")
else:
  print("No")

Fixed submission:
H, N=map(int, input().split())
List=list(map(int,input().split()))
a = 0
for j in range(N):
  a = a + List[j]

if a >= H:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N, K=map(int, input().split())
List=sorted(list(map(int,input().split())))
a = 0
for i in range(N - k):
  a = a + List[i]
print(a)

Fixed submission:
N, K=map(int, input().split())
List=sorted(list(map(int,input().split())))
a = 0
for i in range(N - K):
  a = a + List[i]
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
List = list(map(int, input().split()))
num = 0

for i in range(N):
  Sorted = sorted(List[:i+1])
  if Sorted[0] == List[i]:
    num += 1
print(num)

Fixed submission:
N = int(input())
List = list(map(int, input().split()))
num = 0
min = List[0]
for i in range(N):
  if List[i] <= min:
    num += 1
    min = List[i]
print(num)

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

for i in range(N):
  if min(List[:i+1]) == List[i]:
    num += 1

print(num)

Fixed submission:
N = int(input())
List = list(map(int, input().split()))
num = 0
min = List[0]
for i in range(N):
  if List[i] <= min:
    num += 1
    min = List[i]
print(num)

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

for i in range(N):
  for j in range(i):
    if List[i] > List[j]:
      break
  else:
    num += 1
print(num)

Fixed submission:
N = int(input())
List = list(map(int, input().split()))
num = 0
min = List[0]
for i in range(N):
  if List[i] <= min:
    num += 1
    min = List[i]
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
num = 10**12
for i in range(1, N+1):
  if N % i == 0:
    num = min(num, i + N // i - 2)
print(num)
  

Fixed submission:
import math
N = int(input())
num = 10**12
for i in range(1, math.floor(math.sqrt(N)+2)):
  if N % i == 0:
    num = min(num, i + N // i - 2)
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
List = list(map(int, input().split()))
Ans = [0 for _ in range(N)]
for i in range(N):
  Ans[i] = str(List.index(i+1)+1)
a =' '.join(Ans)
print(a)

Fixed submission:
N = int(input())
List = list(map(int, input().split()))
Ans = [0 for _ in range(N)]
for i in range(N):
  Ans[List[i]-1] = str(i+1)
a =' '.join(Ans)
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int, input().split()))
H.append(10**10)
Res = [0 for _ in range(N)]
for i in range(N-1):
  for j in range(i,N):
    if H[j+1] <= H[j]:
      Res[i] += 1
    else:
      break
print(max(Res))

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
H.append(10**10)
num = 0
ans = 0
for i in range(N):
  if H[i] >= H[i+1]:
    num += 1
  else:
    ans = max(num, ans)
    num = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
num = 0
    for i in range(1, n-1):
        if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
            num += 1
    print(num)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
num = 0
for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
        num += 1
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
List = [0 for _ in range(N)]

for k in range(N):
  List[k] = S[:k+1].count("AC")
  
for i in range(Q):
  l , r = map(int, input().split())
  print(List[r-1]-List[l-1])

Fixed submission:
N, Q = map(int, input().split())
S = input()
List = [0 for _ in range(N)]
num = 0
for k in range(1,N):
  if S[k-1] == "A" and S[k] == "C":
    num += 1
  List[k] = num
  
for i in range(Q):
  l , r = map(int, input().split())
  print(List[r-1]-List[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
for i in range(Q):
  l , r = map(int, input().split())
  print(S[l-1:r].count("AC"))

Fixed submission:
N, Q = map(int, input().split())
S = input()
List = [0 for _ in range(N)]
num = 0
for k in range(1,N):
  if S[k-1] == "A" and S[k] == "C":
    num += 1
  List[k] = num
  
for i in range(Q):
  l , r = map(int, input().split())
  print(List[r-1]-List[l-1])
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()) )
import math

se = A[0]
for i in range(1,N):
    se = math.gcd(se,A[i])
set_wise = se==1

NMAX = 10**6+2
divisors = [i for i in range(NMAX+1)]
p=2
while p*p <=NMAX:
    if divisors[p]==p:
        for r in range(2*p,NMAX+1,p):
            if divisors[r]==r:
                divisors[r]=p
    p+=1
    
from collections import defaultdict
def soinsu_osak(to_devide):
    d = defaultdict(int)
    while to_devide>1:
        d[divisors[to_devide]]+=1
        to_devide //= divisors[to_devide]
    return list(d.keys())

been=[0]*NMAX
f=False
for aa in A:
    soinsu = soinsu_osak(aa)
    for s in soinsu:
        if been[s]==0:
            been[s]=1
        else:
            pair_wise=False
            f=True
            break
    if f:
        break

if pair_wise:
    print("pairwise coprime")
elif set_wise:
    print("setwise coprime")
else:
    print("not coprime")

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

se = A[0]
for i in range(1,N):
    se = math.gcd(se,A[i])
set_wise = se==1

NMAX = 10**6+2
divisors = [i for i in range(NMAX+1)]
p=2
while p*p <=NMAX:
    if divisors[p]==p:
        for r in range(2*p,NMAX+1,p):
            if divisors[r]==r:
                divisors[r]=p
    p+=1
    
from collections import defaultdict
def soinsu_osak(to_devide):
    d = defaultdict(int)
    while to_devide>1:
        d[divisors[to_devide]]+=1
        to_devide //= divisors[to_devide]
    return list(d.keys())

been=[0]*NMAX
pair_wise=True
f=False
for aa in A:
    soinsu = soinsu_osak(aa)
    for s in soinsu:
        if been[s]==0:
            been[s]=1
        else:
            pair_wise=False
            f=True
            break
    if f:
        break

if pair_wise:
    print("pairwise coprime")
elif set_wise:
    print("setwise coprime")
else:
    print("not coprime")
Buggy python submission (verdict: Time Limit Exceeded):
#e
H,W,M = map(int,input().split())
h = [None]*M
w = [None]*M

for i in range(M):
    a,b = map(int,input().split())
    h[i],w[i] = a-1,b-1

exist = [[False]*W for _ in range(H)]
for i in range(M):
    exist[h[i]][w[i]]=True

from collections import Counter
ch = Counter(h)
cw = Counter(w)
#print( max(ch[x]+cw[y]-exist[x][y] for x in range(H) for y in range(W) ))

x_max=max(ch.values())
cand_x_max1 = [x for x in range(H) if ch[x]==x_max]
cand_x_max2 = [x for x in range(H) if ch[x]==x_max-1]

y_max=max(cw.values())
cand_y_max1 = [y for y in range(W) if cw[y]==y_max]
cand_y_max2 = [y for y in range(W) if cw[y]==y_max-1]

from itertools import product
found=False
for x, y in product(cand_x_max1,cand_y_max1):
    if not exist[x][y]:
        found=True
        break
if found:
    print(x_max+y_max)
else:
    print(x_max+y_max-1)
    
        

Fixed submission:
#e
H,W,M = map(int,input().split())
h = [None]*M
w = [None]*M
for i in range(M):
    a,b = map(int,input().split())
    h[i],w[i] = a-1,b-1


from collections import Counter
ch = Counter(h)
cw = Counter(w)

x_max=max(ch.values())
cand_x_max = [x for x in range(H) if ch[x]==x_max]

y_max=max(cw.values())
cand_y_max = [y for y in range(W) if cw[y]==y_max]

    
cnt=0
for i in range(M):
    if ch[h[i]]==x_max and cw[w[i]]==y_max:
        cnt+=1
if cnt<len(cand_x_max)*len(cand_y_max):
    print(x_max+y_max)
else:
    print(x_max+y_max-1)

Buggy python submission (verdict: Time Limit Exceeded):
#e
H,W,M = map(int,input().split())
h = [None]*M
w = [None]*M

for i in range(M):
    a,b = map(int,input().split())
    h[i],w[i] = a-1,b-1

exist = [[False]*W for _ in range(H)]
for i in range(M):
    exist[h[i]][w[i]]=True

from collections import Counter
ch = Counter(h)
cw = Counter(w)

print( max(ch[x]+cw[y]-exist[x][y] for x in range(H) for y in range(W) ))

Fixed submission:
#e
H,W,M = map(int,input().split())
h = [None]*M
w = [None]*M
for i in range(M):
    a,b = map(int,input().split())
    h[i],w[i] = a-1,b-1


from collections import Counter
ch = Counter(h)
cw = Counter(w)

x_max=max(ch.values())
cand_x_max = [x for x in range(H) if ch[x]==x_max]

y_max=max(cw.values())
cand_y_max = [y for y in range(W) if cw[y]==y_max]

    
cnt=0
for i in range(M):
    if ch[h[i]]==x_max and cw[w[i]]==y_max:
        cnt+=1
if cnt<len(cand_x_max)*len(cand_y_max):
    print(x_max+y_max)
else:
    print(x_max+y_max-1)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))

been = [False]*N
n_been=0
loops = []

while True:
    #スタート地点を選ぶ
    for i in range(N):
        if not been[i]:
            now=i
            break
    else:
        break
    cand=[]       
    for _ in range(N):
        if been[now]:
            break
        else:
            cand.append(C[now])
            been[now]=True

        now = P[now]-1
    loops.append(cand)

ans=-10**20
for l in loops:
    m=len(l)
    sum_l = sum(l)
    if sum_l>0:
        k_gene = range(max(0,K-m), K+1)
    else:
        k_gene = range(1,min(m,K)+1)
    for k in k_gene:
        for i in range(m):
            if m-i>=K:
                cand = sum(l[i:i+k]) 
            else:
                cand = sum(l[i:]) +sum_l* ((k-m+i)//m) + sum(l[:(k-m+i)%m] ) 
            ans=max(ans,cand)
            

print(ans)

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

been = [False]*N
n_been=0
loops = []

while True:
    #スタート地点を選ぶ
    for i in range(N):
        if not been[i]:
            now=i
            break
    else:
        break
    cand=[]       
    for _ in range(N):
        if been[now]:
            break
        else:
            cand.append(C[now])
            been[now]=True

        now = P[now]-1
    loops.append(cand)

ans=-10**20
for l in loops:
    m=len(l)
    sum_l = sum(l)
    
    rui =[None]*(m+1)
    rui[0]=0
    for i in range(m):
        rui[i+1] = rui[i]+l[i]

    if sum_l>0:
        k_gene = range(max(0,K-m), K+1)
    else:
        k_gene = range(1,min(m,K)+1)
    for k in k_gene:
        for i in range(m):
            if m-i>=k:
#                cand = sum(l[i:i+k]) 
                cand =rui[i+k]-rui[i]
            else:
#                cand = sum(l[i:])     +sum_l* ((k-m+i)//m) + sum(l[:(k-m+i)%m] ) 
                cand = rui[-1]-rui[i] +sum_l* ((k-m+i)//m) + rui[(k-m+i)%m] 
            ans=max(ans,cand)
            

print(ans)
Buggy python submission (verdict: Runtime Error):
import time
t0 =time.time()
D=int(input())
c = list(map(int,input().split()))

s=[None]*D
for i in range(D):
    s[i] = list(map(int,input().split()))

def maxarg(l):
    nl=len(l)
    ma=-10**20
    idx=-1
    for i in range(nl):
        if l[i]>ma:
            ma=l[i]
            idx=i
    return (idx,ma)

last=[0]*26
t_greed = []
for j,ss in enumerate(s):
    
    cand = [ss[i]+c[i]*(j+1-last[i]) for i in range(26)]
    idx,val = maxarg(cand)
    last[idx]=j+1
    t_greed.append(idx+1)
    
def calc_score(t):
    last=[0]*26
    satis=0
    pena=0
    delta_pena=0
    for j in range(D):
        ss=s[j]
        tt=t[j]
        satis += ss[tt-1]
        delta_pena += sumc - c[tt-1]*(j+1-last[tt-1])
        last[tt-1]=j+1   
        pena += delta_pena
    return satis-pena

import random
t_old=t_greed[:]
while True:
    if time.time()-t0>=1.7:
        break
    d = random.randrange(D+1)
    q = random.randrange(26+1)
    
    t_new = t_old[:]
    t_new[d-1] = q
    if calc_score(t_new)>calc_score(t_old):
        t_old=t_new[:]
        
for tt in t_old:
    print(tt)
    

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

s=[None]*d
for i in range(d):
    s[i] = list(map(int,input().split()))

def maxarg(l):
    nl=len(l)
    ma=-10**20
    idx=-1
    for i in range(nl):
        if l[i]>ma:
            ma=l[i]
            idx=i
    return (idx,ma)

for ss in s:
    print(maxarg(ss)[0]+1)
Buggy python submission (verdict: Time Limit Exceeded):
D=int(input())
c = list(map(int,input().split()))

s=[None]*D
for i in range(D):
    s[i] = list(map(int,input().split()))
t=[0]*D
for i in range(D):
    t[i]=int(input())
    
m=int(input())
d=[None]*m
q=[None]*m
for i in range(m):
    d[i],q[i] = map(int,input().split())

def calc_score(t):
    last=[0]*26
    satis=0
    pena=0
    for j in range(D):
        ss=s[j]
        tt=t[j]
        satis += ss[tt-1]
        last[tt-1]=j+1
        
        pena += sum(c[i]*(j+1-last[i]) for i in range(26))
    return satis-pena

# calc_score(t)-10**6
for i in range(m):
    t[d[i]-1] = q[i]
    print(calc_score(t))

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

s=[None]*D
for i in range(D):
    s[i] = list(map(int,input().split()))
t=[0]*D
for i in range(D):
    t[i]=int(input())
    
m=int(input())
d=[None]*m
q=[None]*m
for i in range(m):
    d[i],q[i] = map(int,input().split())
sumc=sum(c)



def calc_score(t):
    last=[0]*26
    satis=0
    pena=0
    delta_pena=0
    for j in range(D):
        ss=s[j]
        tt=t[j]
        satis += ss[tt-1]
        delta_pena += sumc - c[tt-1]*(j+1-last[tt-1])

        last[tt-1]=j+1   
        pena += delta_pena
    return satis-pena

for i in range(m):
    t[d[i]-1] = q[i]
    print(calc_score(t))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))

for l in range(k):
    if a==[n]*n: 
        break
    left_right = [(max(0,i-a[i]), min(n-1,i+a[i]) ) for i in range(n)]
#    print(left_right)
    a=[0]*n
    for i in range(n):
        for j in range(left_right[i][0], left_right[i][1]+1 ):
            a[j]+=1
#     a = [ sum(left_right[j][0]<=i<=left_right[j][1] for j in range(n)) for i in range(n)]

print(*a) 

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

for l in range(k):
    if a==[n]*n: 
        break
    imos = [0]*(n+1)
    for i in range(n):
        imos[max(0,i-a[i]) ]+=1
        imos[min(n-1,i+a[i])+1 ]-=1

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

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

ans=1
for aa in a:
    ans=ans*aa

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

Fixed submission:
n=int(input())
a = [int(i) for i in input().split() if i!="1"]

if 0 in a:
    print(0)
else:
    ans=1
    for aa in a:
        ans=ans*aa
        if ans>10**18:
            print(-1)
            break
    else:
        print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a=[int(aa)-1 for aa in input().split() ]

been = [0]*n

now=0
been[0]=1
for i in range(k):
    now=a[now]
    if been[now]==0:
        been[now]=1
    else:
        t_stack=sum(been)
        break


start=now

been = [0]*n
been[now]=1
for i in range(k):
    now=a[now]
    if been[now]==0:
        been[now]=1
    else:
        period=sum(been)
        break

now=start
for i in range((k-(t_stack-period))%period):
    now=a[now]
print(now+1)

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

now=0

been = [0]*n
been[0]=1
for i in range(n):
    now=a[now]
    if been[now]==0:
        been[now]=1
    else:
        t_stack=sum(been)
        break

start=now

been = [0]*n
been[now]=1
for i in range(n):
    now=a[now]
    if been[now]==0:
        been[now]=1
    else:
        period=sum(been)
        break

        
if k<=t_stack:
    now=0
    for i in range(k):
        now=a[now]
    print(now+1)
    
else:
    n_itr = (k-t_stack+period)%period
    now=start
    for i in range(n_itr):
        now=a[now]
    print(now+1)
Buggy python submission (verdict: Runtime Error):
s = input()
if s="ABC":
    print("ARC")
else:
    print("ABC")

Fixed submission:
s = input()
if s=="ABC":
    print("ARC")
else:
    print("ABC")
Buggy python submission (verdict: Runtime Error):
#d
s=input()
n=len(s)

ak10k = [(pow(10,n-k-1,m)*int(s[k]))%m for k in range(0,n)]

ruiseki=[0]*n
ruiseki[0]=ak10k[0]
for i in range(1,n):
    ruiseki[i]=(ruiseki[i-1]+ak10k[i])%2019

from collections import Counter
c = Counter(ruiseki)

ans=sum(cc*(cc-1)//2 for cc in c.values()) + list(c.keys()).count(0)

print(ans)

Fixed submission:
s=input()
n=len(s)
m=2019

ak10k = [(pow(10,n-k-1,m)*int(s[k]))%m for k in range(0,n)]+[0]

ruiseki=[0]*n
ruiseki[0]=ak10k[0]
for i in range(1,n):
    ruiseki[i]=(ruiseki[i-1]+ak10k[i])%2019

from collections import Counter
c = Counter(ruiseki)

ans=sum(cc*(cc-1)//2 for cc in c.values()) + c[0]

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

from collections import Counter
c = Counter(a)

answers=dict()
for k in range(n):
    ak = a[k]
    if ak in answers:
        ans = answers[ak]
    else:
        temp = [c[cc]-(ak==cc) for cc in c]
        ans = sum(t*(t-1)//2 for t in temp)
        answers[ak]=ans
    
    print(ans)

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

from collections import Counter
c = Counter(a)

ans0 = sum(cc*(cc-1)//2 for cc in c.values())

for k in range(n):
    m = c[a[k]]
    print(ans0-m+1)
Buggy python submission (verdict: Time Limit Exceeded):
n,p=map(int,input().split())
s=input()
ans=0
if p == 2:
    for i in range(n):
        if s[i] in ["0","2","4","6","8"]:
            ans+=i+1
elif p == 5:
    for i in range(n):
        if s[i] in ["0","5"]:
            ans+=i+1
else:
    mod=[0]*p
    for i in range(n+1):
        if s[i:]=="":
            si=0
        else:
            si =int(s[i:])
        ip = int(si)%p 
        mod[ip]+=1
    ans = sum(m*(m-1)//2 for m in mod)
print(ans)

Fixed submission:
#e
n,p=map(int,input().split())
s=input()
ans=0
if p == 2:
    for i in range(n):
        if s[i] in ["0","2","4","6","8"]:
            ans+=i+1
elif p == 5:
    for i in range(n):
        if s[i] in ["0","5"]:
            ans+=i+1
else:
    mod=[1] + [0]*(p-1)
    a=0
    for i in range(n):
        si = int( s[n-1-i] )
        a = si*pow(10,i,p) + a 
        mod[ a%p ]+=1
    ans =  sum(m*(m-1)//2 for m in mod)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,p=map(int,input().split())
s=input()
print( sum(int(s[i:j+1])%p==0 for i in range(n) for j in range(i,n)) )

Fixed submission:
#e
n,p=map(int,input().split())
s=input()
ans=0
if p == 2:
    for i in range(n):
        if s[i] in ["0","2","4","6","8"]:
            ans+=i+1
elif p == 5:
    for i in range(n):
        if s[i] in ["0","5"]:
            ans+=i+1
else:
    mod=[1] + [0]*(p-1)
    a=0
    for i in range(n):
        si = int( s[n-1-i] )
        a = si*pow(10,i,p) + a 
        mod[ a%p ]+=1
    ans =  sum(m*(m-1)//2 for m in mod)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#d
n,a,b = map(int,input().split())

def cmb(n, r, m,g1,g2):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % m

def nCrMOD(n,r,m):
    g1 = [1, 1]
    g2 = [1, 1]
    inverse = [0, 1]
    for i in range( 2, n + 1 ):
        g1.append( ( g1[-1] * i ) % m )
        inverse.append( ( -inverse[m % i] * (m//i) ) % m )
        g2.append( (g2[-1] * inverse[-1]) % m )
    return cmb(n,r,m,g1,g2)


m=10**9+7

ans = 2**(n%(m-1))%m -1 - nCrMOD(n,a,m) -nCrMOD(n,b,m)
print(ans%m)

Fixed submission:
#d
n,a,b = map(int,input().split())

def power(x, n, mod):
    """
    x**n mod in  O(log n)
    """
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = K * x % mod
            x = x ** 2 % mod
            n = (n - 1) // 2
        else:
            x = x ** 2 % mod
            n = n // 2
    return K * x % mod
 
def nCrMOD(a,b,m):
    c = 1
    for i in range(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = egcd(a, m)
    return inv % m

m=10**9+7

ans = power(2,n,m) -1 - nCrMOD(n,a,m) -nCrMOD(n,b,m)
print(ans%m)
Buggy python submission (verdict: Runtime Error):
s,t = input().split()
a,b = map(int,input().split())
u = input()

if u == s:
    print(a,b-1)
else u == t:
    print(a-1,b)

Fixed submission:
s,t = input().split()
a,b = map(int,input().split())
u = input()

if u == t:
    print(a,b-1)
else:
    print(a-1,b)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
p = [(int(i)+1)/2 for i in input().split()]

sump = [0]*n
sump[0]=p[0]
for i in range(n-1):
    sump[i+1] = sump[i]+p[i+1]
ans=max(sump[i+k]-sump[i] for i in range(n-k))
print(ans)

Fixed submission:
n,k = map(int,input().split())
p = [(int(i)+1)/2 for i in input().split()]


if n==k:
    print(sum(p))
else:
    sump = [0]*n
    sump[0]=p[0]
    for i in range(n-1):
        sump[i+1] = sump[i]+p[i+1]
    ans=max(sump[i+k]-sump[i] for i in range(n-k))
    print(ans)