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

Fixed submission:
def main():
	num,val = input().split(" ")
	num = int(num)
	val = int(val)

	if num < 10:
		print(val + 100*(10-num))
	else:
		print(val)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
int(num),int(val) = input().split(" ")

if num < 10:
	print val + 100*(10-num)
else:
	print val

Buggy submission (verdict: Runtime Error):
num = raw_input()
val = raw_input()

if int(num) < 10:
	rate = int(val) + 100*(10 - int(num))
	print	rate
else:
	rate = int(val)
	print	rate

Buggy submission (verdict: Runtime Error):
def main():
	num = raw_input()
	val = raw_input()

	if int(num) < 10:
		rate = int(val) + 100*(10 - int(num))
	else:
  		rate = int(val)
	print rate
if __name__ == "__main__":
	main()

Buggy submission (verdict: Runtime Error):
def main():
	num = raw_input()
	val = raw_input()

	if int(num) < 10:
		rate = val + 100*(10-num)
	else:
  		rate = int(val)
	print rate
if __name__ == "__main__":
	main()
Problem p03416 (python)

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

if a < 10000 or b > 99999:
    sys.exit(1)

cnt = 0
for i in range(a,b+1):
    if str(i) == str(i)[::-1]:
        cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
a,b = (int(x) for x in input().split())
cnt = 0
for i in range(a,b+1):
    if str(i) == str(i)[::-1]:
        cnt += 1

print(cnt)
Problem p02898 (python)

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

cnt=0
for n in range(N):
    if h[n]>=K:
        cnt+=1

print(cnt)

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

N=ipt[0]
K=ipt[1]
h=ipt[2:]

cnt=0
for n in range(N):
    if h[n]>=K:
        cnt+=1

print(cnt)
Problem p02900 (python)

Fixed submission:
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

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

a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

al=factorization(a) 
bl=factorization(b)

a_s=set()
b_s=set()
for i in range(len(al)):
    a_s.add(al[i][0])
for j in range(len(bl)):
    b_s.add(bl[j][0])
    

s=a_s&b_s
s.add(1)    

print(len(s))

Buggy submission (verdict: Runtime Error):
a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

al=factorization(a) 
bl=factorization(b)

a_s=set()
b_s=set()
for i in range(len(al)):
    a_s.add(al[i][0])
for j in range(len(bl)):
    b_s.add(bl[j][0])
    

s=a_s&b_s
    
print(len(s)+1)
Problem p02911 (python)

Fixed submission:
N,K,Q=input().split()
N=int(N)
K=int(K)
Q=int(Q)

a=[]
for q in range(Q):
    a.append(int(input()))

cnt=[0]*N
for q in range(Q):
    cnt[int(a[q])-1]+=1

for n in range(N):
    if K - (Q - cnt[n]) > 0:    
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
N,K,Q=input().split()
N=int(N)
K=int(K)
Q=int(Q)

a=[]
for q in range(Q):
    a.append(int(input()))

cnt=[0]*N
for q in range(Q):
    cnt[int(a[q])-1]+=1

'print(cnt)

for n in range(N):
    if K - (Q - cnt[n]) > 0:    
        print('Yes')
    else:
        print('No')
Problem p02917 (python)

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

sum =b[0]

if len(b) >= 2:
    for i in range(1,len(b)):
        if b[i-1]<b[i]:
            sum+=b[i-1]
        else:
            sum+=b[i]
        
sum+=b[-1]
        
print(sum)

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

sum =b[0]

if len(b) >= 2:
    for i in range(1,len(b)):
        if b[i-1]<b[i]:
            sum+=b[i-1]
        else:
            sum+=b[i]
        
sum+=b[i]
        
print(sum)

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

sum =b[0]

print(len(b))
if len(b) >= 2:
    for i in range(1,len(b)):
        if b[i-1]<b[i]:
            sum+=b[i-1]
        else:
            sum+=b[i]
        
sum+=b[i]
        
print(sum)

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

sum =b[0]
for i in range(1,len(b)):
    if b[i-1]<b[i]:
        sum+=b[i-1]
    else:
        sum+=b[i]
        
sum+=b[i]
        
print(sum)

Buggy submission (verdict: Runtime Error):
n = int(input())
b=list(map(int, input().split())) 
  
sum =b[0]
for i in range(1,len(b)):
    if b[i-1]<b[i]:
        sum+=b[i-1]
    else:
        sum+=b[i]
        
sum+=b[i]
        
print(sum)
Problem p02975 (python)

Fixed submission:
from collections import Counter

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

flag="No"

count_by_kw = Counter()
for i in range(n):
    count_by_kw[a[i]]+=1

if count_by_kw.get(0) == n:
    flag="Yes"

if count_by_kw.get(0) == n/3 and len(count_by_kw.keys())==2:
    flag="Yes"

cl=list(count_by_kw.values())
ck=list(count_by_kw.keys())

if len(cl)==3:
    if cl[0] == cl[1] and cl[1] == cl[2]:
        xor = ck[0]^ck[1]^ck[2]
        if xor == 0:
            flag="Yes"
        
print(flag)

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

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

flag="No"

count_by_kw = Counter()
for i in range(n):
    count_by_kw[a[i]]+=1

if count_by_kw.get(0) == n:
    flag="Yes"

if count_by_kw.get(0) == n/3 and len(count_by_kw.keys())==2:
    flag="Yes"

cl=list(count_by_kw.values())
ck=list(count_by_kw.values())

if len(cl)==3:
    if cl[0] == cl[1] and cl[1] == cl[2]:
        if ck[0]^ck[1]^ck[2]^ == 0
            flag="Yes"
        
print(flag)
Problem p02993 (python)

Fixed submission:
S=input()

hantei="Good"

for i in range(3):
    if S[i] == S[i+1]:
        hantei="Bad"
        
print(hantei)

Buggy submission (verdict: Runtime Error):
N,L=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

aji=0
eat=99999

for i in range(1,N+1):
    aji=aji+i+L-1
    if abs(aji) < abs(eat):
        eat = aji
        
print(aji)
Problem p02994 (python)

Fixed submission:
N,L=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

aji_sum=0
eat=99999

for i in range(1,N+1):
    
    aji_sum=aji_sum+i+L-1
    if abs(i+L-1) < abs(eat):
        eat = i+L-1

print(aji_sum-eat)

Buggy submission (verdict: Runtime Error):
aji=0
eat=99999

for i in range(1,N+1):
    aji=aji+i+L-1
    if abs(aji) < abs(eat):
        eat = aji
        
print(aji)
Problem p02995 (python)

Fixed submission:
import fractions

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

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
ee=b//(c * d // fractions.gcd(c, d))-(a-1)//(c * d // fractions.gcd(c, d))
    
print((b-a+1)-(cc+dd-ee))

Buggy submission (verdict: Runtime Error):
import math

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

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
ee=b//(c * d // math.gcd(c, d))-(a-1)//(c * d // math.gcd(c, d))
    
print(cc,dd,ee)
print((b-a+1)-(cc+dd-ee))
Problem p03000 (python)

Fixed submission:
#
import sys

n,x=map(int, input().split())
L=list(map(int, input().split()))  

d=0
b=0
for i in range(n):
    d=d+L[i]
    b+=1
    if d > x:
        print(b)
        sys.exit()    
    
print(b+1)

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

n,x=map(int, input().split())
L=list(map(int, input().split()))  

d=0
b=0
for i in range(n+1):
    d=d+L[i]
    b+=1
    
    if d > x:
        print(b)
        sys.exit()
Problem p03043 (python)

Fixed submission:
import math
import heapq
import sys
from collections import Counter
import numpy as np
import datetime

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#s = [input() for i in range(3)]

N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

sum=0
for n in range(1,N+1):
    if n<K:
        sum+=1/N*((1/2)**math.ceil(math.log2(K/n)))
    else:
        sum+=1/N
print(sum)

Buggy submission (verdict: Runtime Error):
import math
import heapq
import sys
from collections import Counter
import numpy as np
import datetime

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#s = [input() for i in range(3)]

N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

a=1/N*((1/2)**math.ceil(math.log2(K)))
sum=0
for n in range(1,N+1):
    if n<K:
        sum+=a*(2**(n-1))
    else:
        sum+=1/N
print(sum)
Problem p03254 (python)

Fixed submission:
import math
import heapq
import sys
from collections import Counter

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N,x=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
a=list(map(int,input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

heapq.heapify(a)  # リストを優先度付きキューへ

for i in range(N):
    x-=heapq.heappop(a)  # 最小値の取り出し
    #print(x,a)
    if x<=0 or i==N-1:
        if x==0:
            print(i+1)
        else:
            print(i)
        break

Buggy submission (verdict: Runtime Error):
import math
import heapq
import sys
from collections import Counter

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N,x=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
a=list(map(int,input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

heapq.heapify(a)  # リストを優先度付きキューへ

for i in range(N):
    x-=heapq.heappop(a)  # 最小値の取り出し
    #print(x,a)
    if x<=0 or i==N-1:
        print(i+1)
        break
Problem p03285 (python)

Fixed submission:
import math
import heapq
import sys
from collections import Counter
import datetime
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

#N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N=int(input())

for i in range(0,N//4+1):
    if (N-4*i)%7==0:
        print('Yes')
        sys.exit()
        
print('No')

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

for i in range(0,N//4):
    if (N-4*i)%7==0:
        print('Yes')
        sys.exit()
        
print('No')

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

for i in range(0,N//4):
    if (N-4*i)%7==0:
        print('Yes')
        sys.exit()
        
print('No')
Problem p03293 (python)

Fixed submission:
import math
import heapq
import sys
import re
from collections import Counter
import datetime
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

#N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

S=input()
T=input()
for i in range(len(S)):
    if S!=T:
        S=S[-1]+S[:-1]
    else:
        print('Yes')
        sys.exit()
        
print('No')

Buggy submission (verdict: Runtime Error):
S=input()
T=input()
for i in range(len(S)):
    if S!=T:
        S=S[-1]+S[:-1]
        print(S)
    else:
        print('Yes')
        sys.exit()
        
print('No')
Problem p03296 (python)

Fixed submission:
import math
import heapq
import sys
from collections import Counter

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N=int(input())
a=list(map(int,input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

cnt=0
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        a[i+1]=-1
        cnt+=1
        #print(a)


print(cnt)

Buggy submission (verdict: Runtime Error):
import math
import heapq
import sys
from collections import Counter

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N=int(input[0])
a=list(map(int,input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

cnt=0
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        a[i+1]=-1
        cnt+=1
        #print(a)


print(cnt)
Problem p03319 (python)

Fixed submission:
import math

N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
A=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき


if N==K:
    print(1)
else:
    print(math.ceil((N-1)/(K-1)))

Buggy submission (verdict: Runtime Error):
import math

N,K=map(int, inp[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
A=list(map(int, inp[0].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき


if N==K:
    print(1)
else:
    print(math.ceil((N-1)/(K-1)))
Problem p03399 (python)

Fixed submission:
A=int(input())
B=int(input())
C=int(input())
D=int(input())

print(min(A,B)+min(C,D))

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

print(min(A,B)+min(C+D))
Problem p03497 (python)

Fixed submission:
import math
import heapq
from collections import Counter

#N,K=map(int, input[].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
A=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

S=Counter(A)
s= S.most_common(K)

print(N-[sum(x) for x in zip(*s)][1])

Buggy submission (verdict: Runtime Error):
import math
import heapq
from collections import Counter

#N,K=map(int, input[].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
A=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

S=Counter(A)
s= S.most_common(K)

print(N-[sum(x) for x in zip(*s)][1])
Problem p02802 (python)

Fixed submission:
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(input().split())
    except:
        break;
        
N = int(listA[0][0])
M = int(listA[0][1])

ans = [0] * N
pena = [0] * N

for i in range(1, M+1):
    num=int(listA[i][0]) -1
    res=listA[i][1]
    if res=="WA" and ans[num] == 0:
        pena[num] =  pena[num]+1
    if res=="AC" and ans[num] == 0:
        ans[num] = 1
        
print('%d %d' % (sum(ans), sum(x*y for x,y in zip(ans,pena)  ) ))

Buggy submission (verdict: Runtime Error):
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]
ans = [0] * N
pena = [0] * N
        
        
for i in range(1, M):
    num=listA[i][0] -1
    res=listA[i][1]
    if res=="WA" and ans[num] == 0:
        pena[num] =  pena[num]+1
    if res=="AC":
        ans[num] = ans[num] + 1
        
print('%d %d' % (sum(ans), sum(pena) ))

Buggy submission (verdict: Runtime Error):
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]
ans = [0] * N
pena = [0] * N
        
        
for i in range(1, M-1):
    num=listA[i][0] -1
    res=listA[i][1]
    if(res=="WA" and ans[num] == 0):
        pena[num] =  pena[num]+1
    if(res=="AC"):
        ans[num] = ans[num] + 1                      
        
print('%d %d' % (sum(ans), sum(pena) ))

Buggy submission (verdict: Runtime Error):
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]

ans = [0] * N
pena = [0] * N

for i in range(1, M):
    num=listA[i][0] -1
    res=listA[i][1]
    if(res=="WA" and ans[num] == 0):
        pena[num] =  pena[num]+1
    if(res=="AC"):
        ans[num] = ans[num] + 1                      
        
print('%d %d' % (sum(ans), sum(pena) ))

Buggy submission (verdict: Runtime Error):
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]

ans = [0] * N
pena = [0] * N

for i in range(M):
    num=listA[i+1][0] -1
    res=listA[i+1][1]
    if(res=="WA" and ans[num] == 0):
        pena[num] =  pena[num]+1
    if(res=="AC"):
        ans[num] = ans[num] + 1            
        
print('%d %d' % (sum(ans), sum(pena) ))

Buggy submission (verdict: Runtime Error):
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]

ans = []
pena = []
for i in range(N): 
    ans.insert(0,0)
    pena.insert(0,0)
for i in range(M):
    num=listA[i+1][0] -1
    res=listA[i+1][1]
    if(res=="WA" and ans[num] == 0):
        pena[num] =  pena[num]+1
    if(res=="AC"):
        ans[num] = ans[num] + 1   
print(sum(ans),sum(pena))
Problem p03125 (python)

Fixed submission:
a = int()
b = int()

1 <= a <= b <=20

a,b=(int(x) for x in input().split())


if b % a == 0:
    print(a + b)
else :
    print(b - a)

Buggy submission (verdict: Runtime Error):
1 <= a <= b <=20

a,b=(int(x) for x in input().split())


if b % a == 0:
    print(a + b)
else :
    print(a - b)
Problem p03152 (python)

Fixed submission:
H,W=map(int,input().split())
hlen = list(map(int,input().split()))
wlen =	list(map(int,input().split()))
hlen.sort(reverse=True)
wlen.sort(reverse=True)
hlen.append(0)
wlen.append(0)

m = H*W
count = 1
h=0
w=0
for num in range(1,H*W+1)[::-1]:
	if hlen[h] == num and wlen[w] == num:
		count *= 1
		h += 1
		w += 1
	elif hlen[h] == num:
		count *= w
		h += 1
	elif wlen[w] == num:
		count *= h
		w += 1
	else:
		count *= h*w - (m-num)
	#print(num,flagh,flagw,count)
	count %= (10**9+7)
print(count)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
hlen= list(map(int,input().split()))
wlen =	list(map(int,input().split()))
def is_unique(l):
    return len(l) == len(set(l))
if not is_unique(hlen) or not is_unique(wlen):
	print(0)
	exit()
def Count(x,l):
	ret = 0
	while l[ret] > x :
		ret += 1
		if ret == len(l):
			break
	return ret	
hlen.sort(reverse=True)
wlen.sort(reverse=True)

m = max(hlen[0],wlen[0])
count = 1
for num in range(1,H*W+1)[::-1]:
	flagh = 0
	flagw = 0
	if num in hlen:
		flagh = 1
	if num in wlen:
		flagw = 1
	if flagh and flagw:
		count *= 1
	elif flagh:
		count *= Count(num,wlen)
	elif flagw:
		count *= Count(num,hlen)
	else:
		count *= Count(num,hlen)*Count(num,wlen) - (m-num)
    count %= (10**9+7)
	#print(num,flagh,flagw,count)
print(count % (10**9+7))

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
hlen = list(map(int,input().split()))
wlen =	list(map(int,input().split()))
hlen.sort(reverse=True)
wlen.sort(reverse=True)
hhlen =[0 for _ in range(H*W+1)]
wwlen =[0 for _ in range(H*W+1)]
for x,xx in zip([hlen,wlen],[hhlen,wwlen]):
	c = 1
	for y in x:
		if xx[y] != 0:
			print(0)
			exit()
		else:
			xx[y] = c
			c += 1

def Count(x,l):
	ret = 0
	for ll in l[x:]:
		if ll > 0:
			return ll

m = max(hlen[0],wlen[0])
count = 1
for num in range(1,H*W+1)[::-1]:
	flagh = 0
	flagw = 0
	if hhlen[num]:
		flagh = 1
	if wwlen[num]:
		flagw = 1
	if flagh and flagw:
		count *= 1
	elif flagh:
		count *= Count(num,wwlen)
	elif flagw:
		count *= Count(num,hhlen)
	else:
		count *= Count(num,hhlen)*Count(num,wwlen) - (m-num)
	#print(num,flagh,flagw,count)
	count %= (10**9+7)
print(count % (10**9+7))
Problem p03200 (python)

Fixed submission:
S=input()
count=0
def sigma(i):
    a=[b for b in range(0,i+1)]
    return sum(a)
place=0
flag=0
start=0
for i in range(len(S)):
    if S[i]=="B":
        flag=1
    elif S[i]=="W":
        if flag == 1:
            count += 1
            place += i - start
        else:
            start+=1
ans=place-sigma(count-1)
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
N=int(input())
x=list(map(int,input().split()))
c=collections.Counter(x)
t=[2**i for i in range(len(str(bin(max(x)*2))[2:])+1)[::-1]]
count=0
start=0
x.sort()
for i in range(len(x))[::-1]:
    for j in range(len(t)):
        if t[j] < x[i]:
            break
        if t[j]-x[i] in c.keys():
            if t[j]-x[i] == x[i] and c[x[i]] >= 2:
                c[x[i]] -= 2
                count +=1
            elif c[t[j]-x[i]]>0 and c[x[i]]>0:
                c[t[j]-x[i]] -= 1
                c[x[i]] -= 1
                count+=1
print(count)

Buggy submission (verdict: Runtime Error):
import collections
N=int(input())
x=list(map(int,input().split()))
c=collections.Counter(x)
t=[2**i for i in range(len(str(bin(max(x)*2))[2:])+1)[::-1]]
count=0
start=0
x.sort()
for i in range(len(x))[::-1]:
    for j in range(start,len(t)):
        if t[j] > 2*x[i]:
            start = j
        if t[j] < x[i]:
            break
        if t[j]-x[i] in c.keys():
            if t[j]-x[i] == x[i]:
                if c[x[i]] >= 2:
                    c[x[i]] -= 2
                    count +=1
            else:
                if c[t[j]-x[i]]>0 and c[x[i]]>0:
                    c[t[j]-x[i]] -= 1
                    c[x[i]] -= 1
                    count+=1
print(count)

Buggy submission (verdict: Runtime Error):
import collections
N=int(input())
x=list(map(int,input().split()))
c=collections.Counter(x)
t=[2**i for i in range(len(str(bin(max(x)*2))[2:])+1)[::-1]]
count=0
#print(c)
#print("x=",x)
#print("t=",t)
for i in range(len(x))[::-1]:
    if x[i] != 0:
        for j in range(0,len(t)):
            if t[j] <= x[i]:
                break
            if t[j]-x[i] in c:
                if t[j]-x[i] == x[i]:
                    if c.get(x[i],-1) >= 2:
                        c[x[i]] -= 2
                        count +=1
                        break
                else:
                    if c.get(t[j]-x[i],-1)>0 and c.get(x[i],-1)>0:
                        c[t[j]-x[i]] -= 1
                        c[x[i]] -= 1
                        count+=1
                        break
#print(c)    
print(count)

Buggy submission (verdict: Runtime Error):
S=input()
count=S.count("BW")
end=0
def sigma(i):
    a=[b for b in range(i+1)]
    return sum(a)
place=[]
i=0
while "BW" in S:
    i=S[i:].find("BW") + 1 + i
    place.append(i)
    S=S[:i-1]+S[i-1:].replace("BW","BB",1)
    print(S)

count=sum(place)-sigma(count-1)
print(count)
Problem p03211 (python)

Fixed submission:
Sstr = list(input())
S = [int(i) for i in Sstr]

bit=[]
for i in range(0,len(S)-2):
    bit.append([abs(7-S[i]),i])


bit.sort(key=lambda x : x[0])

j=0
start=[]

for j in range(len(bit)):
    if bit[0][0] == bit[j][0]:
        start.append(bit[j][1])
        j+=1
    else:
        break

test=0
ans=1000
for st in start:
    if len(S)-st >= 3:
        test=abs(753-(S[st]*100+S[st+1]*10+S[st+2]))
        if ans > test:
            ans=test
print(ans)

Buggy submission (verdict: Runtime Error):
Sstr = list(input())
S = [int(i) for i in Sstr]

bit=[]
for i in range(0,len(S)-1):
    bit.append([abs(7-S[i]),i])


bit.sort(key=lambda x : x[0])

j=0
start=[]
while bit[0][0] == bit[j][0]:
    start.append(bit[j][1])
    j+=1

test=0
ans=1000
for st in start:
    if len(S)-st >= 3:
        test=abs(753-(S[st]*100+S[st+1]*10+S[st+2]))
        if ans > test:
            ans=test
print(ans)