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

Fixed submission:
#最初に置いておくもの
import copy
import sys
sys.setrecursionlimit(50000000) 

#入出力関係
N, M = map(int, input().split())
l = []

for i in range(M):
    l.append(list(map(lambda x: int(x)-1 , input().split())))

lis = [[] for i in range(N)]

for i in range(M):
    lis[l[i][0]].append(l[i][1])
    lis[l[i][1]].append(l[i][0])

def dfs():
    re=0
    q1 =[[0]*N]
    q2=[0]
    while len(q1) != 0:
         
        visited=q1.pop()
        v=q2.pop()
        visited[v]=1
        if all(visited[c]==1 for c in range(N)):
            re += 1
        elif len(lis[v]) != 0:
            for i in lis[v]:
                if visited[i] == 0:
                    hoge=copy.deepcopy(visited)                    
                    q1.append(hoge)
                    q2.append(i)
    return re

print(dfs())

Buggy submission (verdict: Runtime Error):
#最初に置いておくもの
import copy
import sys
sys.setrecursionlimit(50000000) 

#入出力関係
N, M = map(int, input().split())
l = []

for i in range(N):
    l.append(list(map(lambda x: int(x)-1 , input().split())))

lis = [[] for i in range(N)]

for i in range(M):
    lis[l[i][0]].append(l[i][1])
    lis[l[i][1]].append(l[i][0])

def dfs():
    re=0
    q1 =[[0]*N]
    q2=[0]
    while len(q1) != 0:
         
        visited=q1.pop()
        v=q2.pop()
        visited[v]=1
        if all(visited[c]==1 for c in range(N)):
            re += 1
        elif len(lis[v]) != 0:
            for i in lis[v]:
                if visited[i] == 0:
                    hoge=copy.deepcopy(visited)                    
                    q1.append(hoge)
                    q2.append(i)
    return re

print(dfs())

Buggy submission (verdict: Runtime Error):
#最初に置いておくもの
import queue
import copy
import sys
from astropy.io.fits.convenience import append
sys.setrecursionlimit(50000000) 
input=sys.stdin.readline

#入出力関係
N, M = map(int, input().split())
l = []

for i in range(M):
    l.append(list(map(lambda x: int(x)-1 , input().split())))

lis = [[] for i in range(N)]

for i in range(M):
    lis[l[i][0]].append(l[i][1])
    lis[l[i][1]].append(l[i][0])


def dfs():
    re=0
    q1 =[[0]*N]
    q2=[0]
    while len(q1) != 0:
         
        visited=q1.pop()
        v=q2.pop()
        visited[v]=1
        if all(visited[c]==1 for c in range(N)):
            re += 1
        elif len(lis[v]) != 0:
            for i in lis[v]:
                if visited[i] == 0:
                    hoge=copy.deepcopy(visited)                    
                    q1.append(hoge)
                    q2.append(i)
    return re

print(dfs())
Problem p02873 (python)

Fixed submission:
s = input()
a = 0
ans = 0
b = 0
d = [0]
e = []
now = 0

for i in range(len(s)):
    if s[i] == '<':
        
        if a != 0:
            if a > now:
                ans = ans - d[-1] + a
                
            for j in range(a):
                ans = ans + j
                d.append(a - j)
                e.append(">")
            now = 0
            a = 0
        
        ans = ans + now + 1
        now = now + 1
        d.append(now)
        
    else:
        a = a + 1
        b = 0
    
if a != 0:
    if a > now:
        ans = ans - d[-1] + a
                
    for j in range(a):
        ans = ans + j
        d.append(a - j)
        e.append(">")
    
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
a = 0
ans = 0
b = 0
d = []
e = []
now = 0

for i in range(len(s)):
    if s[i] == '<':
        
        if a != 0:
            if a > now:
                ans = ans - d[-1] + a
                
            for j in range(a):
                ans = ans + j
                d.append(a - j)
                e.append(">")
            now = 0
            a = 0
        
        ans = ans + now + 1
        now = now + 1
        d.append(now)
        
    else:
        a = a + 1
        b = 0
    
if a != 0:
    if a > now:
        ans = ans - d[-1] + a
                
    for j in range(a):
        ans = ans + j
        d.append(a - j)
        e.append(">")
    
print(ans)
Problem p02676 (python)

Fixed submission:
K = int(input())
S = input()

if len(S) <= K:
  print(S)
else:
  print(S[:K] + '...')

Buggy submission (verdict: Runtime Error):
K = input()
S = input()

if len(S) <= K:
  print(S)
else:
  print(S[:K] + '...')
Problem p02879 (python)

Fixed submission:
ar=list(map(int,input().split()))
if ar[1]<10 and ar[0]<10:
  print(ar[0]*ar[1])
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
ar=map(int,input().split())
print(ar[0]<10 and ar[1]<10)
Problem p02693 (python)

Fixed submission:
k = int(input())
abs = [int(e) for e in input().split()]

for i in range(abs[0],abs[1]+1):
  if i % k == 0:
    print("OK")
    break
else :
  print("NG")

Buggy submission (verdict: Runtime Error):
k = int(input())
a = int(input())
b = int(input())

for i in range(a,b+1):
  if i % k == 0:
    print("OK")
    break
else :
  print("NG")
Problem p02699 (python)

Fixed submission:
s,w = map(int,input().split())
print("unsafe" if s <= w else "safe")

Buggy submission (verdict: Runtime Error):
s,w = map(int,input())
print("unsafe" if s <= w else "safe")
Problem p02897 (python)

Fixed submission:
N = int(input())
if N % 2 ==0:
  ans = 0.5
else:
  ans = (N+1)/(2*N)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N % 2 ==0:
  ans = 0.5
else:
  ans = (N+1)/2N
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N % 2 ==0:
  print(0.5)
else:
  print((N+1)/2N)
Problem p02693 (python)

Fixed submission:
K=int(input())

ARGS=input().split()
A=int(ARGS[0])
B=int(ARGS[1])

if A <= B//K*K:
    print('OK')
else:
    print('NG')

Buggy submission (verdict: Runtime Error):
K=int(input())

ARGS=input().split()
A=int(ARGS[0])
B=int(ARGS[1])

largest=B / K * K
if A <= largest
    print('OK')
else:
    print('NG')

Buggy submission (verdict: Runtime Error):
K=int(input())

ARGS=input().split()
A=int(ARGS[0])
B=int(ARGS[1])

largest=b / k * k
if A <= largest
    print('OK')
else:
    print('NG')
Problem p02729 (python)

Fixed submission:
import math

ARGS=input().split()
N=int(ARGS[0])
M=int(ARGS[1])
R=2

COMB=0
if N >= R:
    COMB=math.factorial(N) // math.factorial(N - R) // math.factorial(R)
if M >= R:
    COMB+=math.factorial(M) // math.factorial(M - R) // math.factorial(R)

print(str(COMB))

Buggy submission (verdict: Runtime Error):
from scipy.special import comb

ARGS=input().split()
N=int(ARGS[0])
M=int(ARGS[1])

COMB=int(comb(N, 2) + comb(M, 2))

print(str(COMB))
Problem p02682 (python)

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

if K >= A:
    Anum = A
    N = K - A
else:
    Anum = K
    N = 0

if N >= B:
    Bnum = B
    N = N - B
else:
    Bnum = N
    N = 0

Cnum = N

Total = Anum * 1 + Bnum * 0 + Cnum * (-1)

print(Total)

Buggy submission (verdict: Runtime Error):
A, B, C, K = input().split()
A, B, C, K = int(A), int(B), int(C), int(K)

if K >= A:
    Anum = A
    N = K - A
else:
    Anum = K

if N >= B:
    Bnum = B
    N = N - B
else:
    Bnum = N

Cnum = N

Total = Anum * 1 + Bnum * 0 + Cnum * (-1)

print(Total)
Problem p02912 (python)

Fixed submission:
import heapq

n, m = map(int, input().split())
a = [-int(i) for i in input().split()]

heapq.heapify(a)

for _ in range(m):
    temp = heapq.heappop(a)
    temp = -(-temp//2)
    heapq.heappush(a, temp)

print(-sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))

if n == 1:
    for _ in range(m):
        a[0] //=2
    print(a[0])
    exit()

temp = []
temp.append(a.pop())

while m > 0:
    if temp[-1] < a[-1]:
        temp.append(a.pop())
    else:
        temp = sorted(temp)
        temp[-1] //= 2
        m -= 1

print(sum(temp)+sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))

if n == 1:
    for _ in range(m):
        a[0] //=2
    print(a[0])
    exit()

temp = []
temp.append(a.pop())

while m > 0:
    if sorted(temp)[-1] < a[-1]:
        temp.append(a.pop())
    else:
        temp = sorted(temp)
        temp[-1] //= 2
        m -= 1

print(sum(temp)+sum(a))
Problem p03017 (python)

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

a -= 1; b -= 1; c -= 1; d -= 1

#ABCD
if c < d:
    for i in range(a, d-1):
        if s[i] == "#" and s[i+1] == "#":
            print("No")
            exit()
    print("Yes")

#ABDC
elif d < c:
    flag_a = False
    for i in range(b, d+1):
        if s[i-1] == "." and s[i] == "." and s[i+1] == ".":
            flag_a = True

    flag_b = True
    for i in range(a, d-1):
            if s[i] == "#" and s[i+1] == "#":
                flag_b = False

    if flag_a and flag_b:
        print("Yes")
    else:
        print("No")

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

a -= 1; b -= 1; c -= 1; d -= 1

#ABCD
if c < d:
    for i in range(a, d-1):
        if s[i] == "#" and s[i+1] == "#":
            print("No")
            exit()
    print("Yes")

#ABDC
elif d < c:
    flag_a = False
    for i in range(b, c+1):
        if s[i-1] == "." and s[i] == "." and s[i+1] == ".":
            flag_a = True

    flag_b = True
    for i in range(a, d-1):
            if s[i] == "#" and s[i+1] == "#":
                flag_b = False

    if flag_a and flag_b:
        print("Yes")
    else:
        print("No")
Problem p03038 (python)

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

bc = []

for _ in range(m):
    b, c = map(int, input().split())
    bc.append((b, c))

bc = sorted(bc, key=lambda x: x[1], reverse=True)

cnt = 0

for b, c in bc:
    cnt += b
    a += [c] * b
    if cnt >= n:
        break

print(sum(sorted(a,reverse=True)[:n]))

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

heapq.heapify(a) # in-place

for _ in range(m):
    b, c = map(int, input().split())
    for _ in range(b):
        temp = heapq.heappop(a)
        if c > temp:
            heapq.heappush(a, c)
        else:
            heapq.heappush(a, temp)
            break

print(sum(a))
Problem p03821 (python)

Fixed submission:
n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)

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

n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

ans = 0

for i in range(n-1, -1, -1):
    if not A[i] % B[i] == 0:
        temp = B[i]*((A[i]//B[i])+1) - A[i]
        ans += temp
        A += temp
print(int(ans))

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

n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

ans = 0

for i in range(n-1, -1, -1):
    if A[i] % B[i] == 0:
        pass
    else:
        temp = B[i]*((A[i]//B[i])+1) - A[i]
        ans += temp
        A += temp
print(int(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

Buggy submission (verdict: Runtime Error):
ans = 0

for i in range(10**9):
  ans += 1
  
print(ans
Problem p03835 (python)

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

ans = 0

for x in range(k+1):
  for y in range(k+1):
    z = s - x - y
    if 0 <= z <= k:
      ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
k, s = map(int, input().split())

ans = 0

for x in range(k+1):
  if x > s:
    break
  for y in range(k+1):
    if sum(x, y) > s:
      break
    for z in range(k+1):
      if sum(x, y, z) > s:
        break
      if sum(x, y, z) == s:
        ans += 1

print(ans)
Problem p02897 (python)

Fixed submission:
N = int(input())
ans = 0

if (N%2 == 0):
    ans = 0.5
else:
    ans = (N+1)/2/N

print(ans)

Buggy submission (verdict: Runtime Error):

import numpy as np

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

ans = np.zeros(N)

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

for i in range(N):
    print(int(ans[i]), end=' ')
Problem p02676 (python)

Fixed submission:
# -*- coding: utf-8 -*-


S=int(input())
K=input()


if(len(K)>S):
    print(K[0:S]+"...")

else:
    print(K)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


S=input()
K=input()


if(len(K)>=S):
    print(K[0:S]+"...")

else:
    print(K)
Problem p03107 (python)

Fixed submission:
# S = '0011'
# S = '11011010001011'
# S = '0'
S = input()

red = 0
blue = 0

for i in S:
    if i == '0':
        red += 1
    else:
        blue += 1

print(min(red,blue) * 2)

Buggy submission (verdict: Runtime Error):
# S = '0011'
# S = '11011010001011'
# S = '0'
S = input()

cnt = 0


def www(s):
    global cnt

    if len(s) <= 1:
        return

    index = 0
    tmp = []
    c = 0

    while True:
        if len(s) < index + 1:
            break
        if s[index] == '0' and s[index + 1] == '1':
            index += 1
            c += 2
        else:
            tmp.append(S[index])
        index += 1
    cnt += c

    if 0 < c:
        www(tmp)


www(S)
print(cnt)
Problem p02676 (python)

Fixed submission:
import sys
#a = []
#for l in sys.stdin:
#    a.append(int(l))
k = int(input())
s = input()
if len(s) <= k:
   print(s)
else:
   for i in range(k):
      print(s[i], end="")
   for i in range(3):
      print('.', end="")

Buggy submission (verdict: Runtime Error):
import sys
#a = []
#for l in sys.stdin:
#    a.append(int(l))
k = input()
s = input()
if len(s) <= len(k):
   print(s)
else:
   print(k)
   while i in range(len(k)-len(s)):
      print('.')
Problem p03017 (python)

Fixed submission:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,a,b,c,d = f()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    s = input()

    has_2_consecu = 0
    for i in range(a+1, max(c,d)-1):
        if s[i]=='#' and s[i+1] == '#':
            has_2_consecu = 1
            break



    if has_2_consecu:
        print('No')
        return

    if d>c:
        print('Yes')
        return
    else:
        has_3_consecu = 0
        for i in range(b-1, d):
            if s[i]=='.' and s[i+1] == '.' and s[i+2]=='.':
                has_3_consecu = 1
                break
        
        if has_3_consecu:
            print('Yes')
            return
        
        if a+1 == b and s[b+1] == '.':
            print('Yes')
            return
    
    print('No')




solve()

Buggy submission (verdict: Runtime Error):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,a,b,c,d = f()
    s = input()

    has_2_consecu = 0
    for i in range(a+1, max(c,d)-1):
        if s[i]=='#' and s[i+1] == '#':
            has_2_consecu = 1
            break



    if has_2_consecu:
        print('No')
        return

    if d>c:
        print('Yes')
        return
    else:
        has_3_consecu = 0
        for i in range(b+1, d):
            if s[i]=='.' and s[i+1] == '.' and s[i+2]=='.':
                has_3_consecu = 1
                break
        
        if has_3_consecu:
            print('Yes')
            return
    
    print('No')




solve()
Problem p03018 (python)

Fixed submission:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    slen = len(s)
    cnt_a = 0

    idx = 0
    ans = 0
    while idx<slen:
        while idx < slen and s[idx] == 'A':
            cnt_a += 1
            idx += 1
        
        if idx<slen and idx+1 < slen:
            if s[idx] == 'B' and s[idx+1] == 'C':
                ans += cnt_a
                idx += 2
            else:
                idx += 1
                cnt_a = 0
        else:
            break
    
    print(ans)



solve()

Buggy submission (verdict: Runtime Error):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    slen = len(s)
    cnt_a = 0

    idx = 0
    ans = 0
    while idx<slen:
        while s[idx] == 'A':
            cnt_a += 1
            idx += 1
        
        if idx<slen and idx+1 < slen:
            if s[idx] == 'B' and s[idx+1] == 'C':
                ans += cnt_a
                idx += 2
            else:
                idx += 1
                cnt_a = 0
        else:
            break
    
    print(ans)



solve()
Problem p03631 (python)

Fixed submission:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()


    for i in range(len(s)//2):
        if s[i] != s[len(s)-1 -i]:
            print('No')
            return
    
    print('Yes')

solve()

Buggy submission (verdict: Runtime Error):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()

    for i in range(len(s)/2):
        if s[i] = s[len(s)-1 -i]:
            print('No')
            return
    
    print('Yes')

solve()
Problem p03776 (python)

Fixed submission:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def fac(n):
    if n== 1 or n == 0:
        return 1
    return n * fac(n-1)

def comb(n, k):
    if k >n:
        return 0
    return fac(n)/(fac(k) * fac(n-k))

def solve():
    n, a, b = f()
    v = f()
    
    v = sorted(v, reverse = True)

    c = v[a-1]

    cnt1 = 0
    total = 0

    for i in range(n):
        if v[i] == c:
            total += 1
            if i < a:
                cnt1 += 1


    print("{:.7f}".format(sum(v[0:a])/a))
    if v[0] == c:
        ans = 0
        for i in range(a, b+1):
            ans += comb(total, i)
        print(int(ans))
    else:
        print(int(comb(total, cnt1)))

solve()

Buggy submission (verdict: Runtime Error):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def fac(n):
    if n== 1 or n == 0:
        return 1
    return n * fac(n-1)

def comb(n, k):
    return fac(n)/(fac(k) * fac(n-k))

def solve():
    n, a, b = f()
    v = f()
    
    v = sorted(v, reverse = True)

    c = v[a-1]

    cnt1 = 0
    total = 0

    for i in range(n):
        if v[i] == c:
            total += 1
            if i < a:
                cnt1 += 1


    print("{:.7f}".format(sum(v[0:a])/a))
    if v[0] == c:
        ans = 0
        for i in range(a, b+1):
            ans += comb(total, i)
        print(ans)
    else:
        print(int(comb(total, cnt1)))

solve()
Problem p02819 (python)

Fixed submission:
from math import sqrt


def isPrime(n):
    if n > 2 and n % 2 == 0: return False
    i = 3
    while i <= sqrt(n):
        if n % i == 0:
            return False
        i += 2
    return n > 1


n = int(input())
while not isPrime(n):
    n += 1
print(n)

Buggy submission (verdict: Runtime Error):
def isPrime(n):
    if (n > 2 and n % 2 == 0) return False
    i = 3
    while (i <= mySqrt(n)):
        if (n % i == 0):
            return False
        i += 2;
    return n > 1
 
 
n = int(input())
while !isPrime(n):
  	n += 1
print(n)

Buggy submission (verdict: Runtime Error):
def isPrime(n):
    if (n > 2 and n % 2 == 0) return False
    i = 3
    while (i <= mySqrt(n)):
        if (n % i == 0):
            return false
        i += 2;
    return n > 1


n = int(input())
while !isPrime(n):
  n += 1
print(n)
Problem p03072 (python)

Fixed submission:
N = int(input())
H = input().split()
H = [int(h) for h in H]
ct = 1
for i in range(N-1):
    maxim = max(H[:i+1])
    if H[i+1] >= maxim:
        ct += 1
print(ct)

Buggy submission (verdict: Runtime Error):
N = int(input())
H = []*100
H[:] = map(int, input().split())
ct = 1
for i in range(N-1):
    max = max(H[:i+1])
    if H[i+1] >= max:
        ct += 1
print(ct)
Problem p03073 (python)

Fixed submission:
s = input()
t = len(s)
a = '01'*int(t/2) + '0'*int(t%2)
b = '10'*int(t/2) + '1'*int(t%2)
cta = 0
ctb = 0
for i in range(t):
    if s[i] == a[i]:
        cta += 1
    elif s[i] == b[i]:
        ctb += 1
if cta <= ctb:
    print(cta)
else:
    print(ctb)

Buggy submission (verdict: Runtime Error):
s = '9' + input()
t = len(s) - 1
A = '9' + '01'*int(t/2) + '0'*int(t%2)
B = '9' + '10'*int(t/2) + '1'*int(t%2)

s = int(s)
A = int(A)
B = int(B)

sa = s^A
sa = sa.count('1')
sb = s^B
sb = sb.count('1')

if sa >= sb:
    print(sa)
else:
    print(sb)

Buggy submission (verdict: Runtime Error):
s = '9' + input()
t = len(s)
A = '9' + '01'*int(t/2) + '0'*int(t%2)
B = '9' + '10'*int(t/2) + '1'*int(t%2)

s = int(s)
A = int(A)
B = int(B)

sa = s^A
sa = sa.count('1')
sb = s^B
sb = sb.count('1')

if sa >= sb:
    print(sa)
else:
    print(sb)
Problem p02757 (python)

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

if P == 2 or P == 5:
    ans = 0
    for i, s in enumerate(S):
        if int(s) % P == 0:
            ans += i+1
    print(ans)
    import sys
    sys.exit(0)

surpluses = [0] * P
s = 0
power = 1
for i in range(N):
    s = (s + int(S[-1-i]) * power) % P
    surpluses[s % P] += 1
    power = (power * 10) % P

ans = surpluses[0]
for count in surpluses:
    ans += count * (count - 1) // 2

print(ans)

Buggy submission (verdict: Runtime Error):
N, P = map(int, input().split())
S = input()

if P == 2 or P == 5:
    import sys
    sys.exit(1)
    ans = 0
    for i, s in enumerate(S):
        if int(s) % P == 0:
            ans += i+1
    print(ans)

val = int(S)
order = 10 ** N
suf_nums = [-1] * N
s = -1
for i in range(N):
    if s != -1:
        val -= s * order
    suf_nums[i] = val
    s = int(S[i])
    order //= 10

surpluses = [0] * P
ans = 0
suf_nums.reverse()
for num in suf_nums:
    surplus = num % P
    surpluses[surplus] += 1
    if surplus == 0:
        ans += surpluses[0]
    else:
        ans += surpluses[surplus] - 1

print(ans)
Problem p02897 (python)

Fixed submission:
N = int(input())

if N%2 == 0:
    print(0.5)
else:
    print((N//2+1)/N)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import sys
input = sys.stdin.readline
A, B = map(int, input().split())

count = 0
tmp = 1

for i in range(1, min(A, B)**0.5+1):
    if A%i == 0 and B%i == 0 and gcd(i, tmp) == 1:
        tmp *= i
        count += 1
print(count)
Problem p02933 (python)

Fixed submission:
a = int(input())
s = input()
if a>=3200:
    print(s)
else:
    print('red')

Buggy submission (verdict: Runtime Error):
3200
pink