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

Fixed submission:
n = "0" + input() # 文字列として受け取り
N = len(n)
plus = 1
just = 0
for i in range(1,N):
    #前の桁がplusだった場合の最低枚数を計算する
    plus_plus = plus+10-(int(n[i])+1)#この桁も１枚多く払う
    plus_just = plus+10-int(n[i])#この桁はちょうど払う
    #前の桁はちょうど払っていた場合
    just_plus = just+1+int(n[i])#この桁は１枚多く払う
    just_just = just+int(n[i])#この桁もちょうど払う
    
    plus = min(plus_plus,just_plus)
    just = min(just_just,plus_just)

#最後の桁は1枚余分に払う必要がない
print(just)

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10 **7)
n = "0"+input()
N = len(n)
#num:それまでに何枚使ったか
#keta:何桁目まで確認したか（上の桁から数えて)
def oturi(num,keta):
    one_push = num + 10-int(n[keta])+1#前の桁で一つ多い分
    no_push = num + int(n[keta])
    if keta == N-1:
        return min(one_push,no_push)
    num = min(one_push,no_push)
    return oturi(num,keta+1)
print(oturi(0,0))

Buggy submission (verdict: Runtime Error):
n = "0"+input()
N = len(n)
mi = 10**100
#num:それまでに何枚使ったか
#keta:何桁目まで確認したか（上の桁から数えて)
#mae:前の桁で一つ多めに支払ったか
def oturi(num,keta,mae):
    global mi
    #最後の桁までたどり着いた場合
    if keta == N-1:
        #前の桁で一つ多めに支払ってた場合
        if mae == True:
            num += 10-int(n[keta])
            mi = min(mi,num)
            return
        #前の桁でちょっきり支払ってた場合
        else:
            num += int(n[keta])
            mi = min(mi,num)
            return
    #最後の桁ではない場合
    #前の桁で一つ多めに支払ってた場合
    if mae == True:
        num += 10-int(n[keta])
        return oturi(num+1,keta+1,True),oturi(num,keta+1,False)
    #前の桁でちょっきり支払ってた場合
    else:
        num += int(n[keta])
        return oturi(num+1,keta+1,True),oturi(num,keta+1,False)
oturi(0,0,True);oturi(0,0,False)
print(mi)
Problem p02783 (python)

Fixed submission:
from sys import stdin
import math
a,b = [int(x) for x in stdin.readline().rstrip().split()]
print(math.ceil(a/b))

Buggy submission (verdict: Runtime Error):
from sys import stdin

h,n = [int(x) for x in stdin.readline().rstrip().split()]
a = [0]*n ;b = [0]*n

for i in range(n):
    a[i],b[i] = [int(x) for x in stdin.readline().rstrip().split()]

#最高で削られる可能性がある体力
H = max(a)

inf = 10**10

#体力をちょうどi削るために必要な最低の魔力
dp = [inf for _ in range(h+H+1)];dp[0] = 0

for i in range(n):
    for j in range(h+1):
        if dp[j+a[i]] > dp[j] + b[i]:
            dp[j+a[i]] = dp[j] + b[i]

print(min(dp[h:]))
Problem p02789 (python)

Fixed submission:
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]

if n == m:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from functools import reduce
from fractions import gcd
from collections import defaultdict,Counter
import copy

n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

dic = defaultdict(int)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

for i in a:
    c = Counter(prime_factorize(i))
    for j,k in c.items():
        if dic[j] < k:
            dic[j] = k

point = 0

for i in a:
    dic2 = copy.deepcopy(dic)
    e = Counter(prime_factorize(i))
    for j,k in e.items():
        dic2[j] -= k
    now = 1
    for j,k in dic2.items():
        for l in range(k):
            now *= j
            now %= mod
    point += now%mod

print(point%mod)
Problem p02803 (python)

Fixed submission:
from sys import stdin

inf = 10**10
h,w = [int(x) for x in stdin.readline().rstrip().split()]

li = [["#" for i in range(w)]for j in range(h)]
for i in range(h):
    s = stdin.readline().rstrip()
    for j in range(w):
        li[i][j] = s[j]

def all_pairs_shortest_paths(W):
    # 頂点の数
    n = len(W)
    # 結果を格納する行列を用意する
    res = [[0] * n for i in range(n)]
    # 用意した行列を初期化する
    for i in range(n):
        for j in range(i, n):
            if i == j:
                val = 0
            elif W[i][j]:
                val = W[i][j]
            else:
                val = inf
            res[i][j] = res[j][i] = val
    # 動的計画法ですべての超点間の最短距離を求める
    for k in range(n):
        for u in range(n):
            for v in range(n):
                res[u][v] = min(res[u][v], res[u][k] + res[k][v])
    return res

a = [[0 for i in range(w)]for j in range(h)]
for i in range(h):
    for j in range(w):
        a[i][j] = i*w + j

lin = [[0 for i in range(h*w)]for j in range(h*w)]

for i in range(h):
    for j in range(w-1):
        if li[i][j] == "." and li[i][j+1] == ".":
            lin[a[i][j]][a[i][j+1]] = 1
            lin[a[i][j+1]][a[i][j]] = 1

for i in range(h-1):
    for j in range(w):
        if li[i][j] == "." and li[i+1][j] == ".":
            lin[a[i][j]][a[i+1][j]] = 1
            lin[a[i][j]][a[i+1][j]] = 1

lis = all_pairs_shortest_paths(lin)

ma = 0
for i in range(h*w):
    for j in range(h*w):
        if lis[i][j] != 10**10:
            ma = max(lis[i][j],ma)

print(ma)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import numpy as np
inf = 10**10
h,w = [int(x) for x in stdin.readline().rstrip().split()]

li = [["#" for i in range(w)]for j in range(h)]
for i in range(h):
    s = stdin.readline().rstrip()
    for j in range(w):
        li[i][j] = s[j]

def all_pairs_shortest_paths(W):
    # 頂点の数
    n = len(W)
    # 結果を格納する行列を用意する
    res = [[0] * n for i in range(n)]
    # 用意した行列を初期化する
    for i in range(n):
        for j in range(i, n):
            if i == j:
                val = 0
            elif W[i][j]:
                val = W[i][j]
            else:
                val = inf
            res[i][j] = res[j][i] = val
    # 動的計画法ですべての超点間の最短距離を求める
    for k in range(n):
        for u in range(n):
            for v in range(n):
                res[u][v] = min(res[u][v], res[u][k] + res[k][v])
    return res

a = np.arange(h*w)
a = a.reshape([h,w])
a = a.tolist()

lin = [[0 for i in range(h*w)]for j in range(h*w)]

for i in range(h):
    for j in range(w-1):
        if li[i][j] == "." and li[i][j+1] == ".":
            lin[a[i][j]][a[i][j+1]] = 1
            lin[a[i][j+1]][a[i][j]] = 1

for i in range(h-1):
    for j in range(w):
        if li[i][j] == "." and li[i+1][j] == ".":
            lin[a[i][j]][a[i+1][j]] = 1
            lin[a[i][j]][a[i+1][j]] = 1

lis = all_pairs_shortest_paths(lin)

ma = 0
for i in range(h*w):
    for j in range(h*w):
        if lis[i][j] != 10**10:
            ma = max(lis[i][j],ma)

print(ma)
Problem p02845 (python)

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

xyz = [[0,0,0]for _ in range(n)]
xyz[0] = [0,0,0]

mod = 10**9+7

for i in range(n-1):
    if li[i] not in xyz[i]:
        print(0)
        exit()
    ix = xyz[i].index(li[i])
    for j in range(3):
        if j == ix:
            xyz[i+1][j] = xyz[i][j] + 1
        else:
            xyz[i+1][j] = xyz[i][j]

point = 3

for i in range(1,n):
    point *= xyz[i].count(li[i])
    point %= mod
print(point)

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

xyz = [[0,0,0]for _ in range(n)]
xyz[0] = [0,0,0]

mod = 10**9+7

for i in range(n-1):
    ix = xyz[i].index(li[i])
    if ix > 2:
        print(0)
        exit()
    for j in range(3):
        if j == ix:
            xyz[i+1][j] = xyz[i][j] + 1
        else:
            xyz[i+1][j] = xyz[i][j]

point = 3

for i in range(1,n):
    point *= xyz[i].count(li[i])
    point %= mod
print(point)

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

xyz = [[0,0,0]for _ in range(n)]
xyz[0] = [0,0,0]

mod = 10**9+7

for i in range(n-1):
    ix = xyz[i].index(li[i])
    for j in range(3):
        if j == ix:
            xyz[i+1][j] = xyz[i][j] + 1
        else:
            xyz[i+1][j] = xyz[i][j]

point = 3
for i in range(1,n):
    point *= xyz[i].count(li[i])
    point %= mod
print(point)

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

pos = [0]*n
pos[0] = 3

mod = 10**9+7

if li[1]-li[0] == 0:
    pos[1] = 6
else:
    pos[1] = 3

for i in range(2,n):
    #連続3つが違う色
    if li[i]-li[i-2] == 0:
        pos[i] = pos[i-2]*2%mod
    #連続3つが同じ色
    elif li[i]-li[i-2] == 2:
        pos[i] = pos[i-2]
    #二つが同じ色
    else:
        pos[i] = pos[i-2]*4%mod

print(pos[-1])
Problem p02865 (python)

Fixed submission:
from sys import stdin
import fractions

n = int(stdin.readline().rstrip())

if n %2 == 1:
    print(n//2)
else:
    print(n//2-1)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

lin.sort()

if lin[0][0] != 0 or lin[0][1] > 1:
    print(0)
    exit()

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0]+1 != lin[i][0]:
        print(0)
        exit()
    
    point *= (lin[i-1][1]**lin[i][1])

print(point%998244353)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

if lin[0][0] != 0 or lin[0][1] > 1:
    print(0)
    exit()

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0] +1 != lin[i][0]:
        print(0)
        exit()
    point *= lin[i-1][1]**lin[i][1]

print(point%998244353)
Problem p02901 (python)

Fixed submission:
n,m = map(int,input().split())
a_list = []
c = []

for i in range(m):
    a,b = map(int,input().split())
    a_list.append(a)
    c.append(sum(1 << j-1 for j in list(map(int,input().split()))))

inf = 10**10
dp = [inf]*(1 << n)
dp[0] = 0

for i in range(1 << n):
    for j in range(m):
        dp[c[j]|i] = min(dp[c[j]|i],dp[i]+a_list[j])

if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])

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

n,m = map(int,input().split())
a_list = []
c = []

for i in range(m):
    a,b = map(int,input().split())
    a_list.append(a)
    c.append(sum(1 << j-1 for j in list(map(int,input().split()))))

inf = 10**10
dp = [inf]*(1 << n)
dp[0] = 0

for i in range(1 << n):
    for j in range(m):
        dp[c[j]|i] = min(dp[c[j]|i],dp[i]+a_list[j])

if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])
Problem p02923 (python)

Fixed submission:
from sys import stdin
n = int(stdin.readline().rstrip())
data = list(map(int,stdin.readline().rstrip().split()))
zantei = 0
k = 0
while k < n-1:
    point = 0
    for i in range(k,n-1):
        if data[i] >= data[i+1]:
            k += 1
            point += 1
        else:
            k += 1
            break
    if point > zantei:
        zantei = point
    point = 0
print(zantei)

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rstrip())
data = list(map(int,stdin.readline().rstrip().split()))
li = []
point = 0
k = 0
while k < n-1:
    for i in range(k,n-1):
        if data[i] >= data[i+1]:
            k += 1
            point += 1
        else:
            li.append(point)
            k += 1
            break
    
    li.append(point)
    point = 0
print(max(li))

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rstrip())
data = list(map(int,stdin.readline().rstrip().split()))
li = []
point = 0
k = 0
while k < n-1:
    for i in range(k,n-1):
        if data[i] >= data[i+1]:
            k += 1
            point += 1
        else:
            li.append(point)
            k += 1
            break
    
    li.append(point)
    point = 0
print(max(li))
Problem p02924 (python)

Fixed submission:
from sys import stdin

n = int(stdin.readline().rstrip())
point = n*(n-1)//2
print(point)

Buggy submission (verdict: Runtime Error):
from sys import stdin
from itertools import accumulate
n = int(stdin.readline().rstrip())
if n == 1:
    print(0)
else:
    a = list(range(1, n))
    b = list(accumulate(a))
    print(max(b))

Buggy submission (verdict: Runtime Error):
from sys import stdin
from itertools import accumulate
n = int(stdin.readline().rstrip())
if n == 1:
    print(0)
else:
    a = list(range(1, n))
    b = list(accumulate(a))
    print(b[-1])

Buggy submission (verdict: Runtime Error):
from sys import stdin
from itertools import accumulate#累積和

n = int(stdin.readline().rstrip())
if n == 1:
    print(0)
else:
    a = list(range(1, n))
    b = list(accumulate(a))
    print(b[-1])
Problem p02928 (python)

Fixed submission:
from sys import stdin
n,k = map(int,stdin.readline().rstrip().split())
li = list(map(int,stdin.readline().rstrip().split()))
nai = 0
ato = 0
point = 0
for i in range(n):
    for s in range(i+1,n):
        if li[i] > li[s]:
            nai += 1
    for v in range(n):
        if li[i] > li[v]:
            ato += 1
point += (nai*k)+(ato*k*(k-1)//2)
print(point%(10**9+7))

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

n = int(input())
a = list(map(int,input().split()))
a = np.array(a,dtype=np.int64)
point = 0
mod = 10**9+7

b = [((a>>i)&1).sum() for i in range(61)]
c = [n-b[i] for i in range(61)]
d = [c[i]*b[i]%mod for i in range(61)]

point = 0
for i in range(61):
    point += (2**i)*d[i]%mod

point %= mod

print(point)

Buggy submission (verdict: Runtime Error):
from sys import stdin
from math import factorial
n,k = map(int,stdin.readline().rstrip().split())
li = list(map(int,stdin.readline().rstrip().split()))
nai = 0
ato = 0
point = 0
for i in range(n):
    for s in range(i+1,n):
        if li[i] > li[s]:
            nai += 1
    for v in range(n):
        if li[i] > li[v]:
            ato += 1
def combinations_count(j,r):
    return factorial(j) // (factorial(j - r) * factorial(r))
point += (nai*k)+(ato*combinations_count(k,2))
print(point%(10**9+7))

Buggy submission (verdict: Runtime Error):
from sys import stdin
from math import factorial
n,k = map(int,stdin.readline().rstrip().split())
li = list(map(int,stdin.readline().rstrip().split()))
li_to = li*2
nai = 0
ato = 0
for i in range(len(li)):
    for s in range(i+1,len(li)):
        if li[i] > li[s]:
            nai += 1
    for p in range(len(li),len(li_to)):
        if li[i] > li_to[p]:
            ato += 1
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))
point = 0
point += (nai*k)+(ato*combinations_count(k,2))
print(point%(10**9+7))
Problem p02934 (python)

Fixed submission:
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
s = 0
for i in range(n):
    s += 1/li[i]
print(1/s)

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rsprit())
li = list(map(int,stdin.readline().rstrip().split()))
s = 0
for i in range(n):
    s += 1/li[i]
print(1/s)
Problem p02936 (python)

Fixed submission:
from sys import stdin
import sys
from itertools import groupby
sys.setrecursionlimit(10**6) 
n,q = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n-1)]
lin = [list(map(int,stdin.readline().rstrip().split())) for _ in range(q)]

kazu = [[]for _ in range(n)]
point = [0]*n

for i in range(len(li)):
    kazu[li[i][0]-1].append(li[i][1]-1)
    kazu[li[i][1]-1].append(li[i][0]-1)
for i in range(q):
    point[lin[i][0]-1] += lin[i][1]

def dfs(li,li2,now,before):
    for i in (li[now]):
        if i == before:
            continue
        li2[i] += li2[now]
        dfs(kazu,point,i,now)
dfs(kazu,point,0,-1)
print(*point)

Buggy submission (verdict: Runtime Error):
from sys import stdin
from itertools import groupby

n,q = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n-1)]
lin = [list(map(int,stdin.readline().rstrip().split())) for _ in range(q)]

kazu = [[]for _ in range(n)]
point = [0]*n

for i in range(len(li)):
    kazu[li[i][0]-1].append(li[i][1]-1)
    kazu[li[i][1]-1].append(li[i][0]-1)
for i in range(q):
    point[lin[i][0]-1] += lin[i][1]

def dfs(li,li2,now,before):
    for i in (li[now]):
        if i == before:
            continue
        li2[i] += li2[now]
        dfs(kazu,point,i,now)
dfs(kazu,point,0,-1)
print(*point)

Buggy submission (verdict: Runtime Error):
from sys import stdin
from itertools import groupby

n,q = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n-1)]
lin = [list(map(int,stdin.readline().rstrip().split())) for _ in range(q)]

kazu = [[]for _ in range(n)]
point = [0]*n

for i in range(len(li)):
    kazu[li[i][0]-1].append(li[i][1]-1)
    kazu[li[i][1]-1].append(li[i][0]-1)
for i in range(q):
    point[lin[i][0]-1] += lin[i][1]

#深さ優先探索を実装したい(liが各ノードを入れたリスト、li2が)

def dfs(li,li2,now,before):
    for i in (li[now]):
        if i == before:
            continue
        li2[i] += li2[now]
        dfs(kazu,point,i,now)
dfs(kazu,point,0,-1)
print(*point)
Problem p02969 (python)

Fixed submission:
from sys import stdin

n = int(stdin.readline().rstrip())
print(3*n**2)

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(int(stdin.readline().rstrip()) for _ in range(n))
li_to = sorted(li)
one = li_to[-1]
two = li_to[-2]
for i in range(n):
    if max(li) == li[i]:
        print(two)
    else:
        print(one)
Problem p02971 (python)

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
a_m = max(a)
a_i = a.index(a_m)
a.sort()
for i in range(len(a)):
  if i == a_i:
    print(a[-2])
  else:
    print(a_m)

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(int(stdin.readline().rstrip()) for _ in range(n))
one = max(li)
two = sorted(li)[-2]
for i in range(n):
    if max(li) == li[i]:
        print(two)
    else:
        print(max(one))

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rstrip())
li = list(int(stdin.readline().rstrip()) for _ in range(n))
one = max(li)
two = sorted(li)[-2]
for i in range(n):
    if max(li) == li[i]:
        print(two)
    else:
        print(max(one)
Problem p02981 (python)

Fixed submission:
from sys import stdin
li = list(map(int,stdin.readline().rstrip().split()))
if li[1]*li[0] > li[2]:
    print(li[2])
else:
    print(li[0]*li[1])

Buggy submission (verdict: Runtime Error):
from sys import stdin
li = list(map(int,stdin.readline().rstrip.split()))
if li[1] > li[2]:
    print(li[0]*li[1])
else:
    print(li[0]*li[2])

Buggy submission (verdict: Runtime Error):
from sys import stdin

li = list(map(int,stdin.readline().rstrip.split()))

if li[1] > li[2]:
    print(li[0]*li[1])
else:
    print(li[0]*li[2])
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n,k = map(int,input().split())
li = [[] for _ in range(n+1)]
mod = 10**9+7
ans = k
perm = [1]*(n)# 組み合わせ(k-2)P(要素)

for i in range(n-1):
    a,b = map(int,input().split())
    li[a].append(b)
    li[b].append(a)
    perm[i+1] = (perm[i]*(k-2-i))%mod

def dfs(now,before):
    point = 1
    if now == 1:
        ret = 1
        ko = len(li[1])
        for i in range(ko):
            ret *= k-1-i
            ret %= mod
    else:
        ko = len(li[now])-1
        ret= perm[ko]%mod
    
    for i in li[now]:
        if i==before:
            continue
        ret = ret*dfs(i,now)%mod
    return ret

ans *= dfs(1,0)

print(ans%mod)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)
n,k = map(int,input().split())
li = [[] for _ in range(n+1)]
mod = 10**9+7
ans = k
perm = [1]*(n)# 組み合わせ(k-2)P(要素)

for i in range(n-1):
    a,b = map(int,input().split())
    li[a].append(b)
    li[b].append(a)
    perm[i+1] = (perm[i]*(k-2-i))%mod

def dfs(now,before):
    point = 1
    ret = 1
    if now == 1:
        ko = len(li[1])
        for i in range(ko):
            ret *= k-1-i
            ret %= mod
    else:
        ko = len(li[now])-1
        ret= perm[ko]%mod
    
    for i in li[now]:
        if i==before:
            continue
        ret = ret*dfs(i,a)%mod
    return ret

ans *= dfs(1,0)
print(ans)
Problem p02995 (python)

Fixed submission:
from sys import stdin
import fractions
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
kouyaku = fractions.gcd(c, d)
koubai = c * d // fractions.gcd(c, d)
b_s = b - b//c - b//d + b//koubai
a_s = a-1 - (a-1)//c - (a-1)//d + (a-1)//koubai
print(b_s - a_s)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
kouyaku = math.gcd(c, d)
koubai = c * d // math.gcd(c, d)
b_s = b - b//c - b//d + b//koubai
a_s = a-1 - (a-1)//c - (a-1)//d + (a-1)//koubai
print(b_s - a_s)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
kouyaku = math.gcd(c, d)
koubai = (c * d // kouyaku)
b_s = (b - b//c - b//d + b//koubai)
a_s = (a-1 - (a-1)//c - (a-1)//d + (a-1)//koubai)
print(b_s - a_s)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
kouyaku = math.gcd(c, d)
koubai = c * d // kouyaku
b_s = b - b//c - b//d + b//koubai
a_s = a-1 - (a-1)//c - (a-1)//d + (a-1)//koubai
print(b_s - a_s)
Problem p03061 (python)

Fixed submission:
from fractions import gcd

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

M = [0]*N

#漸化式を作る
L = [0]*N
R = [0]*N

for i in range(1,N):
    L[i] = gcd(L[i-1],A[i-1])
    R[N-1-i] = gcd(R[N-i],A[N-i])

for j in range(N):
    M[j] = gcd(L[j],R[j])

print(max(M))

Buggy submission (verdict: Runtime Error):
from sys import stdin
from fractions import gcd
#from math import gcd

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

def gcd_all(list):
    return gcd_all([gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]

ma = -50
for i in range(n):
    lin = [li[s] for s in range(n) if s != i]
    ma = max(ma,gcd_all(lin))

print(ma)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import fractions

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

def gcd_all(list):
    return gcd_all([fractions.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]

ma = 0
for i in range(n):
    lin = [li[s] for s in range(n) if s != i]
    ma = max(ma,gcd_all(lin))

print(ma)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

def gcd_all(list):
    return gcd_all([math.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]

ma = 0
for i in range(n):
    lin = [li[s] for s in range(n) if s != i]
    ma = max(ma,gcd_all(lin))

print(ma)
Problem p03069 (python)

Fixed submission:
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
kuro = s.count("#")
shiro = n-kuro
mi = shiro
k = 0
sh = shiro
for i in range(n):
    if s[i] == "#":
        k += 1
    else:
        sh -= 1
    mi = min(mi,k+sh)
print(mi)

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rstrip())
s = "."+stdin.readline().rstrip()
kuro = s.count("#")
shiro = n-kuro
mi = shiro
k = 0
sh = shiro
for i in range(n):
    if s[i] == "#":
        k += 1
    else:
        sh -= 1
    mi = min(mi,k+s)
print(mi)
Problem p03080 (python)

Fixed submission:
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

if s.count("R") > s.count("B"):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

if s.cound("R") > s.count("B"):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

if s.cound("R") > s.count("B"):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
from sys import stdin

s = stdin.readline().rstrip()

if s.cound("R") > s.count("B"):
    print("Yes")
else:
    print("No")