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

Fixed submission:
import copy
from scipy.sparse.csgraph import floyd_warshall as wf

N, M = map(int, input().split())
INF = float('inf')

d = [[INF] * (N) for i in range(N)]
e_list = []
for i in range(N):
    d[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    d[a - 1][b - 1] = c
    d[b - 1][a - 1] = c
    e_list.append([a - 1, b - 1, c])
    
wf = wf(d)

cnt = M
for a, b, c in e_list:
    for i in range(N):
        if wf[i][a] + c == wf[i][b]:
            cnt -= 1
            break
    
print(cnt)

Buggy submission (verdict: Runtime Error):
import heapq
import copy

V, M = map(int, input().split())
d = [0] * V
prev = [0] * V

cost = [[INF] * V for i in range(V)]
for i in range(M):
    a, b, c = map(int,  input().split())
    cost[a - 1][b - 1] = c
    cost[b - 1][a - 1] = c
    
def dijkstra_back(s, t):
    for i in range(V):
        prev[i] = s
        d[i] = float('inf')
    d[s] = 0
    h = []
    heapq.heappush(h, [0, s])
    
    while h != []:
        p = heapq.heappop(h)
        v = p[1]
        if d[v] < p[0]:
            continue
         
        for i in range(V):
            if d[i] > d[v] + cost[v][i]: 
                d[i] = d[v] + cost[v][i]
                heapq.heappush(h, [d[i], i])
                prev[i] = v
        
    path = [t]
    while prev[t] != s:
        path.append(prev[t])
        prev[t] = prev[prev[t]]
    path.append(s)
    path = path[::-1]
    return path

cost2 = copy.deepcopy(cost)
for i in range(V - 1):
    for j in range(i + 1, V):
        g = dijkstra_back(i, j)
        # print(i, j, g)
        for k in range(len(g) - 1):
            cost2[g[k]][g[k + 1]] = INF
            cost2[g[k + 1]][g[k]] = INF
            
cnt = 0
for i in range(V):
    for j in range(V):
        if cost2[i][j] != INF:
            cnt += 1
                     
print(cnt // 2)

Buggy submission (verdict: Runtime Error):
import heapq
import copy

V, M = map(int, input().split())
d = [0] * V
prev = [0] * V

cost = [[INF] * V for i in range(V)]
for i in range(M):
    a, b, c = map(int,  input().split())
    cost[a - 1][b - 1] = c
    cost[b - 1][a - 1] = c
    
def dijkstra_back(s, t):
    for i in range(V):
        prev[i] = s
        d[i] = float('inf')
    d[s] = 0
    h = []
    heapq.heappush(h, [0, s])
    
    while h != []:
        p = heapq.heappop(h)
        v = p[1]
        if d[v] < p[0]:
            continue
         
        for i in range(V):
            if d[i] > d[v] + cost[v][i]: 
                d[i] = d[v] + cost[v][i]
                heapq.heappush(h, [d[i], i])
                prev[i] = v
        
    path = [t]
    while prev[t] != s:
        path.append(prev[t])
        prev[t] = prev[prev[t]]
    path.append(s)
    path = path[::-1]
    return path

cost2 = copy.deepcopy(cost)
for i in range(V - 1):
    for j in range(i + 1, V):
        g = dijkstra_back(i, j)
        # print(i, j, g)
        for k in range(len(g) - 1):
            cost2[g[k]][g[k + 1]] = INF
            cost2[g[k + 1]][g[k]] = INF
            
cnt = 0
for i in range(V):
    for j in range(V):
        if cost2[i][j] != INF:
            cnt += 1
                     
print(cnt // 2)
Problem p03854 (python)

Fixed submission:
s = list(input())
while len(s) > 0:
    if ''.join(s[-7:]) == 'dreamer':
        del s[-7:]    
    elif ''.join(s[-6:]) == 'eraser':
        del s[-6:]
    elif ''.join(s[-5:]) == 'dream' or ''.join(s[-5:]) == 'erase':
        del s[-5:]
    else:
        break
print('NO' if len(s) != 0 else 'YES')

Buggy submission (verdict: Runtime Error):
s = input()

def f(t):
    if len(t) > len(s):
        return False
    if t == s:
        return True
    return f(t + 'dream') or f(t + 'erase') or f(t + 'dreamer') or f(t + 'eraser')

if f(''):
    print('YES')
else:
    print('NO')
Problem p04026 (python)

Fixed submission:
S = input()
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        print(i + 1, i + 2)
        break
    if i < len(S) - 2 and S[i] == S[i + 2]:
        print(i + 1, i + 3)
        break
else:
    print(-1, -1)

Buggy submission (verdict: Runtime Error):
S = input()
if S[0] == S[2]:
        print(1, 3)
else:
    for i in range(1, len(S)):
        if S[i] == S[i - 1]:
            print(i, i + 1)
            break
    else:
        print(-1, -1)
Problem p04033 (python)

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

if a <= 0 and b >= 0:
    ans = 'Zero'
elif a < 0 and b < 0:
    if (abs(a) - abs(b) + 1) % 2 == 0:
        ans = 'Positive'
    else:
        ans = 'Negative'
elif a > 0 and b > 0:
    ans = 'Positive'
    
print(ans)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())

if a =< 0 and b >= 0:
    ans = 'Zero'
elif a < 0 and b < 0:
    if (abs(a) - abs(b) + 1) % 2 == 0:
        ans = 'Positive'
    else:
        ans = 'Negative'
elif a > 0 and b > 0:
    ans = 'Positive'
    
print(ans)
Problem p02995 (python)

Fixed submission:
import fractions

def lcm(x,y):
     return x * y // fractions.gcd(x,y)

a,b,c,d = map(int,input().split())

countB = b - (b // c) - (b // d) + (b // lcm(c,d))
countA = a - 1 - ((a - 1) // c) - ((a - 1) // d) + ((a - 1) // lcm(c,d))

print(countB - countA)

Buggy submission (verdict: Runtime Error):
import math

def lcm(x,y):
     return x * y // math.gcd(x,y)

a,b,c,d = map(int,input().split())

countB = b - (b // c) - (b // d) + (b // lcm(c,d))
countA = a - 1 - ((a - 1) // c) - ((a - 1) // d) + ((a - 1) // lcm(c,d))

print(countB - countA)
Problem p02952 (python)

Fixed submission:
def main():
    i = list(map(int, input().split()))
    n = i[0]

    if not (1 <= n and n <= 10**5):
        return

    num = 0
    for j in range(n):
        if(len(str(j+1)) % 2 != 0):
            num += 1

    print(num)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    i = list(map(int, input().split()))
    n = i[0]

    if not (1 <= n and n <= 10**5):
        return

    num = 0
    for j in range(n):
        if(len(n) % 2 != 0):
            num += 1

    print(num)

if __name__ == "__main__":
    main()
Problem p03035 (python)

Fixed submission:
def main():
    i = list(map(int, input().split()))
    a = i[0]
    b = i[1]

    #if isinstance(a, int) == False or isinstance(b, int) == False or a < 0 or 100 < a or b < 2 or 1000 < b or b % 2 != 0:
    #    return

    if 13 <= a and a <= 100:
        print(b)
    elif 6 <= a and a <= 12:
        print(b//2)
    elif 0 <= a and a <= 5:
        print(0)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
A = list(map(int, input().split()))

if B % 2 == 0:
    if A[0] >= 13 and A[0] <= 100:
        print(A[1])
    elif 6 <= A[0] and A[0] <= 12:
        print(A[1]/2)
    elif 0 <= A[0] and A[0] <= 5:
        print(0)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())

if A >= 13 and A <= 100:
    print(B)
elif 6 <= A and A <= 12:
    print(B/2)
elif 0 <= A and A <= 5:
    print(0)

Buggy submission (verdict: Runtime Error):
def cal(A, B):
    if A >= 13 and A <= 100:
        return B
    elif 6 <= A and A <= 12:
        return B/2
    elif 0 <= A and A <= 5:
        return 0

if __name__ == "__main__":
    print(cal(int(input()), int(input())))

Buggy submission (verdict: Runtime Error):
def cal(A, B):
    if A >= 13:
        return B
    elif 6 <= A and A <= 12:
        return B/2
    elif 0 <= A and A <= 5:
        return 0

if __name__ == "__main__":
    print(cal(int(input()), int(input())))

Buggy submission (verdict: Runtime Error):
def cal(A, B):
    if A >= 13:
        return B
    elif 6 <= A and A <= 12:
        return B/2
    elif 5 >= A:
        return 0

if __name__ == "__main__":
    print(cal(int(input()), int(input())))

Buggy submission (verdict: Runtime Error):
def cal(A, B):
    if A >= 13:
        return B
    elif 6 <= A and A <= 12:
        return B/2
    elif 5 <= A:
        return 0

if __name__ == "__main__":
    A = int(input())
    B = int(input())
    print(cal(A, B))

Buggy submission (verdict: Runtime Error):
def cal(A, B):
    if A >= 13:
        return B
    elif 6 <= A and A <= 12:
        return B/2
    elif 5 <= A:
        return 0

if __name__ == "__main__":
    A = input()
    B = input()
    print(cal(A, B))
Problem p03632 (python)

Fixed submission:
def main():
    i = list(map(int, input().split()))
    a = i[0]
    b = i[1]
    c = i[2]
    d = i[3]

    if not (0 <= a and a < b and b <= 100 and 0 <= c and c < d and d <= 100):
        return
    if not (isinstance(a, int) and isinstance(b, int) and isinstance(c, int) and isinstance(d, int)):
        return
    
    if(b <= c or d <= a):
        print(0)
    elif(a <= c and c < b and b <= d):
        print(b - c)
    elif(c <= a and a < d and d <= b):
        print(d - a)
    elif(a <= c and d <= b):
        print(d - c)
    elif(c <= a and b <= d):
        print(b - a)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    i = list(map(int, input().split()))
    a = i[0]
    b = i[1]
    c = i[2]
    d = i[3]

    if not (0 <= a and a < b and b <= 100 and 0 <= c and c < d and d <= 100):
        return

    alice = b - a
    bob = d -c

    if(b <= c or c < b):
        print(0)
    elif(c < b and b < d):
        print(b - c)
    elif(a < c and d < b):
        print(d - c)
    elif(a < d and d < b):
        print(d - a)
    elif(c < a and b < d):
        print(b - a)


if __name__ == "__main__":
    main(
Problem p03633 (python)

Fixed submission:
import fractions

def main():
    n = int(input())  #nは入力回数
    t = [int(input()) for _ in range(n)]

    if not (1 <= n and n <= 100 and isinstance(n, int)):
        return
    for i in t:
        if not (1 <= i and i <= 10**18 and isinstance(i, int)):
            return

    k = t[0]
    for i in range(1, n):
        k = k * t[i] // fractions.gcd(k, t[i])

    if k <= 10**18:
        print(k)

if __name__ == "__main__":
    main()

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

def main():
    n = int(input())  #nは入力回数
    t = [int(input()) for _ in range(n)]

    if not (1 <= n and n <= 100 and isinstance(n, int)):
        return
    for i in t:
        if not (1 <= i and i <= 10**18 and isinstance(i, int)):
            return

    k = lcm_list(t)
    if k <= 10**18:
        print(k)

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

if __name__ == "__main__":
    main()

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

def main():
    n = int(input())  #nは入力回数
    t = [int(input()) for _ in range(n)]

    if not (1 <= n and n <= 100 and isinstance(n, int)):
        return
    for i in t:
        if not (1 <= i and i <= 10**18 and isinstance(i, int)):
            return

    k = lcm_list(t)
    if k <= 10**18:
        print(k)

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

if __name__ == "__main__":
    main()
Problem p02993 (python)

Fixed submission:
s=input()
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
	print("Bad")
else:
	print("Good")

Buggy submission (verdict: Runtime Error):
s=input()   
if s[0]==s[1]:
	print("Bad")
elif s[1]==s[2]:
	print("Bad")
elif s[2]==s[3]:
	print("Bad")
else:
	print(good)

Buggy submission (verdict: Runtime Error):
s=input()
if s[1:]==s[1:2]:
    print("Bad")
elif s[1:2]==s[2:3]:
    print("Bad")
elif s[2:3]==s[3:4]:
    print("Bad")
else:
    print(good)
Problem p03555 (python)

Fixed submission:
s=input()
t=input()
if s[0]==t[2] and s[1]==t[1] and s[2]==t[0]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
s,t=input()
if s[0]==t[2] and s[1]==t[1] and s[2]==t[0]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
s,t=input()
if s[0]==t[2] and s[1]==t[1] and s[2]=t[0]:
    print("YES")
else:
    print("NO")
Problem p02991 (python)

Fixed submission:
from heapq import *
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
G=[[] for i in range(3*N)]
for i in range(M):
    u,v=map(int,input().split())
    u,v=u-1,v-1
    G[3*u+0].append([3*v+1,0])
    G[3*u+1].append([3*v+2,0])
    G[3*u+2].append([3*v+0,1])
S,T=map(int,input().split())
INF=10**9+7
def dijkstra(G,s):

  d=[INF]*(3*N)
  d[s]=0
  visited={s}
  que=[(0,s)]
  while(que):
    p=heappop(que)
    v=p[1]
    visited.add(v)
    for node,cost in G[v]:
      if (node not in visited) and d[node]>d[v]+cost:
        d[node]=d[v]+cost
        heappush(que,(d[node],node))
  return d
d=dijkstra(G,(S-1)*3)
if d[(T-1)*3]==INF:
  print(-1)
else:
  print(d[(T-1)*3])

Buggy submission (verdict: Runtime Error):
def main():
  from heapq import *
  import sys
  input=sys.stdin.readline
  N,M=map(int,input().split())
  G=[set() for i in range(N)]
  for i in range(M):
      u,v=map(int,input().split())
      u,v=u-1,v-1
      G[u].add(v)
  S,T=map(int,input().split())
  A=[set() for i in range(N)]
  for i in range(N):
      for v in G[i]:
          A[i]=A[i] | G[v]
  B=[set() for i in range(N)]
  for i in range(N):
      for v in G[i]:
          B[i]=B[i] | A[v]
  C=[[] for i in range(N)]
  for i in range(N):
      for j in B[i]:
          C[i].append([j,1])
  INF=10**9+7
  def dijkstra(G,s):

    d=[INF]*N
    d[s]=0
    visited={s}
    que=[(0,s)]
    while(que):
      p=heappop(que)
      v=p[1]
      visited.add(v)
      for node,cost in G[v]:
        if (node not in visited) and d[node]>d[v]+cost:
          d[node]=d[v]+cost
          heappush(que,(d[node],node))
    return d
  d=dijkstra(C,S-1)
  if d[T-1]==INF:
    print(-1)
  else:
    print(d[T-1])
if __name__=='__main__':#おまじない
  main()
Problem p03005 (python)

Fixed submission:
N,K=map(int,input().split())
if K==1:
    print(0)
else:
    print(N-K)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
dp=[N]*(N+1)
#dp[i];=i個目まで選んで交換したときの最大
C=[B[i]-A[i] for i in range(3)]
for i in range(N):
    dp[i+1]=max(dp[i+1],dp[i])
    for j in range(3):
        if i+1-A[j]>=0:
            dp[i+1]=max(dp[i+1],dp[i+1-A[j]]+C[j])
M=dp[N]
dp=[0]*(M+1)
C=[A[i]-B[i] for i in range(3) if A[i]-B[i]>=0]
for i in range(M):
    dp[i+1]=max(dp[i+1],dp[i])
    for j in range(len(C)):
        if i+1-B[j]>=0:
            dp[i+1]=max(dp[i+1],dp[i+1-B[j]]+C[j])
print(M+dp[M])
Problem p03007 (python)

Fixed submission:
from copy import deepcopy
N=int(input())
A=list(map(int,input().split()))
if N==2:
    print(max(A[0]-A[1],A[1],A[0]))
    print(max(A[0],A[1]),min(A[0],A[1]))
    quit()
A.sort()
ans=10**(-50)
S=sum(A)
for i in range(N-1):
    S=S-A[i]+(-A[i])
    if ans<S:
        ans=S
        j=i
print(ans)
for i in range(j+1,N-1):
    print(A[0],A[i])
    A[0]-=A[i]
for i in range(j+1):
    print(A[N-1],A[i])
    A[N-1]-=A[i]

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
N=int(input())
A=list(map(int,input().split()))
K=deepcopy(A)
A.sort()
ans=10**(-20)
S=sum(A)
for i in range(N-1):
    S=S-A[i]+(-A[i])
    if ans<S:
        ans=S
        j=i
print(ans)
for i in range(j+1,N-1):
    print(A[0],A[i])
    A[0]-=A[i]
print(A[N-1],A[0])
Problem p03014 (python)

Fixed submission:
H,W=map(int,input().split())
S=[]
for i in range(H):
    s=input()
    S.append(s)

Gh=[[0]*W for i in range(H)]
for i in range(H):
    tmp=0
    s=0
    j=0
    while(j!=W):
        if S[i][j]=="#":
            Gh[i][j]==0
            for k in range(s,j):
                Gh[i][k]=tmp
            s=j+1
            j+=1
            tmp=0
        else:
            tmp+=1
            j+=1
    if s!=j:
        for k in range(s,j):
            Gh[i][k]=tmp
Gv=[[0]*W for i in range(H)]
for j in range(W):
    tmp=0
    s=0
    i=0
    while(i!=H):
        if S[i][j]=="#":
            Gv[i][j]==0
            for k in range(s,i):
                Gv[k][j]=tmp
            s=i+1
            i+=1
            tmp=0
        else:
            tmp+=1
            i+=1
    if s!=i:
        for k in range(s,i):
            Gv[k][j]=tmp
ans=0
for i in range(H):
    for j in range(W):
        ans=max(ans,Gh[i][j]+Gv[i][j]-1)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
h, w = map(int, input().split())
S = []
for i in range(h):
    S.append(input())
 
sw = []
 
for i in range(h):
    c = []
    for j in range(w):
        if S[i][j] == '#':
            c.append(j)
    c.append(w)
    k = []
    p = c[0]
    k += [p] * p
    k += [0]
    for j in range(1, len(c)):
        p = c[j] - c[j-1] - 1
        k += [p] * p
        k += [0]
    sw.append(k[0:-1])
 
sh =[]
 
for i in range(w):
    c = []
    for j in range(h):
        if S[j][i] == '#':
            c.append(j)
    c.append(h)
    k = []
    p = c[0]
    k += [p] * p
    k += [0]
    for j in range(1, len(c)):
        p = c[j] - c[j-1] - 1
        k += [p] * p
        k += [0]
    sh.append(k[0:-1])
 
sw = np.array(sw)
sh = np.array(sh)
sh = sh.T
 
x = sw + sh
 
print(np.amax(x) - 1)
Problem p03032 (python)

Fixed submission:
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0

for i in range(1,N+1):#何個取るか
    if i>K:
        break
    for r in range(i+1):

        l=i-r
        a=V[:r]
        b=V[N-l:]
        f=max(0,K-i)
        c=a+b
        c.sort()
        k=0
        t=0
        for j in c:
            if t<f and j<0:
                t+=1
                continue
            k+=j
        ans=max(ans,k)
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
V=list(map(int,input().split()))
V_=list(reversed(V))
ans=0
for k in range(1,K+1):
    k_=min(k,N)
    for kk in range(k_+1):
        sum=0
        l=[]
        for i in range(kk):
            sum+=V[i]
            l.append(V[i])
        for i in range(k-kk):
            sum+=V_[i]
            l.append(V_[i])
        l.sort()
        for j in range(min(k_,K-k_)):
            if l[j]>=0:
                break
            sum-=l[j]
        ans=max(ans,sum)
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
KK=K
if K>N:
    KK=N
for i in range(KK+1):
    j=KK-i
    a=V[:i]
    b=V[N-j:]
    ans=max(ans,sum(a)+sum(b))
    k=sum(a)+sum(b)
    c=a+b
    c.sort(reverse=True)
    W=K+max(0,K-N)
    W-=2
    while(W>0):
        if c==[]:
            break
        t=c.pop()
        if t in a:
            a.remove(t)
        else:
            b.remove(t)
        if a!=[] and b!=[] :
            if a[-1]<=b[0]:
                h=a.pop(-1)
            else:
                h=b.pop(0)
        elif a!=[] and b==[]:
            h=a.pop(-1)
        elif b!=[] and a==[]:
            h=b.pop(0)
        else:
            break
        k=k-t-h
        ans=max(k,ans)
        W-=2
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
for i in range(K+1):
    j=K-i
    a=V[:i]
    b=V[N-j:]
    ans=max(ans,sum(a)+sum(b))
    k=sum(a)+sum(b)
    c=a+b
    c.sort(reverse=True)
    W=K
    W-=2
    while(W>0):
        if c==[]:
            break
        t=c.pop()
        if t in a:
            a.remove(t)
        else:
            b.remove(t)
        if a!=[] and b!=[] :
            if a[-1]<=b[0]:
                h=a.pop(-1)
            else:
                h=b.pop(0)
        elif a!=[] and b==[]:
            h=a.pop(-1)
        elif b!=[] and a==[]:
            h=b.pop(0)
        else:
            break
        k=k-t-h
        ans=max(k,ans)
        W-=2
print(ans)
Problem p03043 (python)

Fixed submission:
import math
from math import ceil
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
    k=ceil(math.log(K/i,2))
    k=max(0,k)
    ans+=(1/N)*(1/2)**k
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from math import ceil
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
    k=ceil(math.log2(K/i))
    k=max(0,k)
    ans+=(1/N)*(1/2)**k
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
    k=ceil(math.log2(K/i))
    k=max(0,k)
    ans+=(1/N)*(1/2)**k
print(ans)
Problem p03050 (python)

Fixed submission:
from collections import defaultdict
N=int(input())
if N==1 or N==2:
    print(0)
    quit()
def prime_factor(n):
    i = 2
    table = defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i]+=1
        i += 1
    if n > 1:
        table[n]+=1
    return table
table=prime_factor(N)
list=[1]
for fact,num in table.items():
    list_=[]
    for k in range(num+1):
        list_.extend([i*fact**k for i in list])
    list=list_
list.sort()
ans=0
for i in range(len(list)):
    if i==0:
        continue
    if list[i-1]+1==list[i]:
        continue
    m=list[i]-1
    if N//m==N%m:
        ans+=list[i]-1
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
if N==1 or N==2:
    print(0)
    quit()
def prime_factor(n):
    i = 2
    table = defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i]+=1
        i += 1
    if n > 1:
        table[n]+=1
    return table
table=prime_factor(N)
list=[1]
for fact,num in table.items():
    list_=[]
    for k in range(num+1):
        list_.extend([i*fact**k for i in list])
    list=list_
list.sort()
ans=0
for i in range(len(list)):
    if i==0:
        continue
    if list[i-1]+1==list[i]:
        continue
    m=list[i]-1
    if N//m==N%m:
        ans+=list[i]-1
print(ans)
Problem p03061 (python)

Fixed submission:
from fractions import gcd

N=int(input())
A=list(map(int,input().split()))
X=[A[0]]
Y=[A[-1]]
for i in range(N):
    X.append(gcd(X[-1],A[i]))
    Y.append(gcd(Y[-1],A[N-1-i]))
X=X[1:]
Y=Y[1:]
Y=Y[::-1]
ans=1
for i in range(N):
    if i==0:
        ans_=Y[i+1]
    elif i==N-1:
        ans_=X[i-1]
    else:
        ans_=gcd(X[i-1],Y[i+1])
    ans=max(ans,ans_)
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
n=0
i=0
while(n<N):
    i+=1
    n=2**i
INF=0
dat=[INF]*(2*n-1)
def update(i,x):
    i+=n-1
    dat[i]=x
    while(i>0):
        i=(i-1)//2
        dat[i]=gcd(dat[i*2+1],dat[i*2+2])
def find(a,b,k,l,r):
    if r<=a or b<=l:
        return INF
    if a<=l and r<=b:
        return dat[k]
    else:
        vl=find(a,b,k*2+1,l,(l+r)//2)
        vr=find(a,b,k*2+2,(l+r)//2,r)
        return gcd(vl,vr)
for i in range(N):
    update(i,A[i])
ans=0
for i in range(N):
    f=find(0,i,0,0,n)
    g=find(i+1,N,0,0,n)
    ans=max(gcd(f,g),ans)
print(ans)
Problem p03087 (python)

Fixed submission:
N,Q=map(int,input().split())
S=input()
l=[]
r=[]
lst1=[0 for i in range(N)]
for i in range(N-1):
    i+=1
    if S[i-1:i+1]=="AC":
        lst1[i]=lst1[i-1]+1
    else:
        lst1[i]=lst1[i-1]

for i in range(Q):
    l,r=map(int,input().split())
    l=l-1
    r-=1
    print(lst1[r]-lst1[l])

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
S=input()
count=[0]*(N)
for i in range(N-1):
    if S[i:i+2]=="AC":
        count[i]=1
sums=list(accumulate([0]+count))

for i in range(Q):
    l,r=map(int,input().split())
    l-=1
    r-=1
    print(sums[r]-sums[l])