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

Fixed submission:
from collections import defaultdict
from collections import deque
import time
import sys

input = sys.stdin.readline

# start = time.time()
n, q = map(int, input().strip().split())
edges = [list(map(int, input().strip().split())) for _ in range(n - 1)]
values = [list(map(int, input().strip().split())) for _ in range(q)]

# elapsed = time.time() - start
# print("elapsed_time:{0}".format(elapsed) + "[sec]")

edge_dict = defaultdict(list)
value_dict = defaultdict(int)
total_value_dict = defaultdict(int)
visited = [False] * n

for a, b in edges:
    edge_dict[a].append(b)
    edge_dict[b].append(a)

for p, x in values:
    value_dict[p] += x


qu = deque([1])
total_value_dict[1] = value_dict[1]
visited[0] = True

while len(qu) > 0:
    node = qu.popleft()
    next_nodes = [m for m in edge_dict[node] if not visited[m - 1]]
    for m in next_nodes:
        total_value_dict[m] = total_value_dict[node] + value_dict[m]
        visited[m - 1] = True
        qu.append(m)

print(' '.join([str(total_value_dict[i]) for i in range(1, n + 1)]))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from collections import deque
import time
import sys

input = sys.stdin.readline

# start = time.time()
n, q = map(int, input().strip().split())
edges = [list(map(int, input().strip().split())) for _ in range(n - 1)]
values = [list(map(int, input().strip().split())) for _ in range(q)]

# elapsed = time.time() - start
# print("elapsed_time:{0}".format(elapsed) + "[sec]")

edge_dict = defaultdict(list)
value_dict = defaultdict(int)
total_value_dict = defaultdict(int)
visited = [False] * n

for a, b in edges:
    edge_dict[a].append(b)
    edge_dict[b].append(a)

for p, x in values:
    value_dict[p] += x


qu = deque([1])
total_value_dict[1] = value_dict[1]
visited[0] = True

while len(qu) > 0:
    node = qu.popleft()
    next_nodes = [m for m in edge_dict[node] if not visited[m]]
    for m in next_nodes:
        total_value_dict[m] = total_value_dict[node] + value_dict[m]
        visited[m - 1] = True
        qu.append(m)

print(' '.join([str(total_value_dict[i]) for i in range(1, n + 1)]))
Problem p02995 (python)

Fixed submission:
# import math
import fractions

a, b, c, d = [int(ch) for ch in input().strip().split()]


# upper 以下で div で割り切れるものの個数
def num_divisor(upper, div):
    return upper // div


# upper 以下で c でも d でも割り切れないものの個数
def num_divisor_c_d(upper, c, d):
    # gcd_cd = c * d // math.gcd(c, d)
    gcd_cd = c * d // fractions.gcd(c, d)

    n1 = num_divisor(upper, c)
    n2 = num_divisor(upper, d)
    n12 = num_divisor(upper, gcd_cd)

    return upper - (n1 + n2 - n12)


ans = num_divisor_c_d(b, c, d) - num_divisor_c_d(a - 1, c, d)

print(ans)

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = [int(ch) for ch in input().strip().split()]


# upper 以下で div で割り切れるものの個数
def num_divisor(upper, div):
    return upper // div


# upper 以下で c でも d でも割り切れないものの個数
def num_divisor_c_d(upper, c, d):
    gcd_cd = c * d // math.gcd(c, d)

    n1 = num_divisor(upper, c)
    n2 = num_divisor(upper, d)
    n12 = num_divisor(upper, gcd_cd)

    return upper - (n1 + n2 - n12)


ans = num_divisor_c_d(b, c, d) - num_divisor_c_d(a - 1, c, d)

print(ans)

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = [int(ch) for ch in input().strip().split()]


# upper 以下で div で割り切れるものの個数
def num_divisor(upper, div):
    return upper // div


# upper 以下で c でも d でも割り切れないものの個数
def num_divisor_c_d(upper, c, d):
    gcd_cd = c * d // math.gcd(c, d)

    n1 = num_divisor(upper, c)
    n2 = num_divisor(upper, d)
    n12 = num_divisor(upper, gcd_cd)

    return upper - (n1 + n2 - n12)


ans = num_divisor_c_d(b, c, d) - num_divisor_c_d(a - 1, c, d)

print(ans)
Problem p02996 (python)

Fixed submission:
n = int(input())
data = [list(map(int, input().strip().split())) for _ in range(n)]

data = sorted(data, key=lambda d: d[1])

work_time = 0
impossible = False
for a, b in data:
    deadline = b
    work_time += a
    if work_time > b:
        impossible = True
        break

if impossible:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
n = int(input())
data = [list(map(int, input().strip().split())) for _ in range(n)]

data = sorted(data, key=lambda d: d[1])

work_time = 0
impossible = False
for a, b in data:
    deadline = b
    work_time += a
    if work_time > b:
        impossible = True
        break

if impossible:
    print('No')
else:
    print('Yes')

n = int(input())
data = [list(map(int, input().strip().split())) for _ in range(n)]

data = sorted(data, key=lambda d: d[1])

work_time = 0
impossible = False
for a, b in data:
    deadline = b
    work_time += a
    if work_time > b:
        impossible = True
        break

if impossible:
    print('No')
else:
    print('Yes')
Problem p03160 (python)

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

# 足場 i にたどり着くまでのコストの総和の最小値
dp = [1e14] * n

dp[0] = 0
dp[1] = abs(hs[0] - hs[1])

for i in range(2, n):
    dp[i] = min(abs(hs[i] - hs[i - 1]) + dp[i - 1], abs(hs[i] - hs[i - 2]) + dp[i - 2])

print(dp[n - 1])

Buggy submission (verdict: Runtime Error):
n, w = map(int, input().strip().split())
data = [list(map(int, input().strip().split())) for _ in range(n)]

# i番目に重さがj以下となるように選んだときの価値の総和の最大値
dp = [[0] * (w + 1) for _ in range(n)]

for i in range(0, n):
    for j in range(w + 1):
        # i 番目の品物の重さと価値
        wi, vi = data[i]
        if i == 0:
            take = vi if j - wi >= 0 else 0
            miss = 0
            dp[i][j] = max(take, miss)
        else:
            # i番目の品物を入れる場合
            take = dp[i - 1][j - wi] + vi if j - wi >= 0 else 0
            # 入れない場合
            miss = dp[i - 1][j]
            dp[i][j] = max(take, miss)

print(max(dp[n - 1]))

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

n, w = map(int, input().strip().split())
data = [list(map(int, input().strip().split())) for _ in range(n)]

# i番目に重さがj以下となるように選んだときの価値の総和の最大値
dp = np.zeros((n, w + 1), dtype=np.int64)

for i in range(0, n):
    for j in range(w + 1):
        # i 番目の品物の重さと価値
        wi, vi = data[i]
        if i == 0:
            take = vi if j - wi >= 0 else 0
            miss = 0
            dp[i][j] = max(take, miss)
        else:
            # i番目の品物を入れる場合
            take = dp[i - 1][j - wi] + vi if j - wi >= 0 else 0
            # 入れない場合
            miss = dp[i - 1][j]
            dp[i][j] = max(take, miss)

print(np.max(dp[n - 1]))
Problem p03162 (python)

Fixed submission:
n = int(input())

data = []
for i in range(n):
    row = list(map(int, input().split()))
    data.append(row)

# n日目に act を行うときの最大値
dp = [None] * n

# 初期条件： 0日目にa, b, c (= 0, 1, 2) を行うときの最大値
dp[0] = [0, 0, 0]
dp[0][0] = data[0][0]
dp[0][1] = data[0][1]
dp[0][2] = data[0][2]

for d in range(1, n):
    dp[d] = [0, 0, 0]
    dp[d][0] = data[d][0] + max(dp[d - 1][1], dp[d - 1][2])
    dp[d][1] = data[d][1] + max(dp[d - 1][2], dp[d - 1][0])
    dp[d][2] = data[d][2] + max(dp[d - 1][0], dp[d - 1][1])

mx = max(dp[n - 1])

print(mx)

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

data = []
for i in range(n):
    row = list(map(int, input().split()))
    data.append(row)

# n日目に act を行うときの最大値
def rec(n, act):
    if n == 0:
        return data[n][act]

    if act == 0:
        available = [1, 2]
    elif act == 1:
        available = [0, 2]
    else:
        available = [0, 1]
    return data[n][act] + max(rec(n - 1, available[0]), rec(n - 1, available[1]))

mx = max(rec(n - 1, 0), rec(n - 1, 1), rec(n - 1, 2))

print(mx)
Problem p03665 (python)

Fixed submission:
# from scipy.special import comb
from scipy.misc import comb

n, p = map(int, input().strip().split())
as_ = list(map(int, input().strip().split()))

num_evens = len([a for a in as_ if a % 2 == 0])
num_odds = len([a for a in as_ if a % 2 == 1])

counts = 0
if p == 0:
    # 全部で偶数枚食べる = 偶数枚の袋 a 個 + 奇数枚の袋 b = 2k 個
    # 0袋食べる場合も OK.
    counts += 1
    # 1袋以上食べる場合
    for i in range(1, n + 1):
        # 全部で i 袋食べるとする i = 1 〜 n
        for a in range(i + 1):
            # そのうち偶数枚の袋を a 個食べる方法
            even_ways = comb(num_evens, a, exact=True)
            # 奇数枚の袋は (i - a) 個食べるが、それは偶数でなければならない
            b = (i - a)
            if b % 2 == 1 or b < 0:
                continue
            else:
                odd_ways = comb(num_odds, b, exact=True)

            counts += even_ways * odd_ways

else:
    # 全部で奇数枚食べる = 偶数枚の袋 a 個 + 奇数枚の袋 b = 2k + 1個 (k >= 0)
    # 奇数の袋は0ではいけない (k >= 0)
    # 0袋食べるのはダメ
    # 1袋以上食べる場合
    for i in range(1, n + 1):
        # 全部で i 袋食べるとする
        for b in range(0, i + 1):
            # 奇数枚の袋を b = 2k + 1 個食べる
            if b % 2 == 0:
                continue
            # すると偶数枚の袋は a = i - b 個食べる
            a = i - b
            if a < 0:
                continue

            odd_ways = comb(num_odds, b, exact=True)
            even_ways = comb(num_evens, a, exact=True)
            counts += even_ways * odd_ways

print(counts)

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

n, p = map(int, input().strip().split())
as_ = list(map(int, input().strip().split()))

num_evens = len([a for a in as_ if a % 2 == 0])
num_odds = len([a for a in as_ if a % 2 == 1])

counts = 0
if p == 0:
    # 全部で偶数枚食べる = 偶数枚の袋 a 個 + 奇数枚の袋 b = 2k 個
    # 0袋食べる場合も OK.
    counts += 1
    # 1袋以上食べる場合
    for i in range(1, n + 1):
        # 全部で i 袋食べるとする i = 1 〜 n
        for a in range(i + 1):
            # そのうち偶数枚の袋を a 個食べる方法
            even_ways = comb(num_evens, a, exact=True)
            # 奇数枚の袋は (i - a) 個食べるが、それは偶数でなければならない
            b = (i - a)
            if b % 2 == 1 or b < 0:
                continue
            else:
                odd_ways = comb(num_odds, b, exact=True)

            counts += even_ways * odd_ways

else:
    # 全部で奇数枚食べる = 偶数枚の袋 a 個 + 奇数枚の袋 b = 2k + 1個 (k > 0)
    # 奇数の袋は0ではいけない (k > 0)
    # 0袋食べるのはダメ
    # 1袋以上食べる場合
    for i in range(1, n + 1):
        # 全部で i 袋食べるとする
        for b in range(1, i + 1):
            # 奇数枚の袋を b = 2k + 1 個食べる
            if b % 2 == 0:
                continue
            # すると偶数枚の袋は a = i - b 個食べる
            a = i - b
            if a < 0:
                continue

            odd_ways = comb(num_odds, b, exact=True)
            even_ways = comb(num_evens, a, exact=True)
            counts += even_ways * num_odds

print(counts)
Problem p02555 (python)

Fixed submission:
from scipy.special import comb


s = int(input())

if s < 3:
    print(0)
else:

    count = 0
    total = 0

    while True:
        s = s-3
        count += 1

        if s >= 0:
           total += comb(s+count-1, count-1 ,exact=True)
           total = total% (10**9+7)
        else:
            break

    print(int(total ))

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


s = int(input())

if s < 3:
    print(0)
else:

    count = 0
    total = 0

    while True:
        s = s-3
        count += 1

        if s >= 0:
           total += comb(s+count-1, count-1)
        else:
            break

    print(int(total % (10**9+7)))
Problem p02690 (python)

Fixed submission:
X=int(input())
J=1000
N=[0]*J
for i in range(0,J):
    N[i]=i**5
for i in range(0,J):
    for j in range(0,J):
        if abs(N[i]-N[j])==X:
            print(int(max(N[i],N[j])**(1/5)),int(min(N[i],N[j])**(1/5)))
            exit()
        elif N[i]+N[j]==X:
            print(int(N[i]**(1/5)),int(-1*N[j]**(1/5)))
            exit()

Buggy submission (verdict: Runtime Error):
X=int(input())
i=0
while True:
    x1=(X+i**5)**(1/5)
    x2=(X-i**5)**(1/5)
    if x1==int(x1):
        print(int(x1),i)
        exit()
    elif x2==int(x2):
        print(int(x2),-i)
        exit()
    i+=1
Problem p02981 (python)

Fixed submission:
N,A,B= list(map(int, input().split()))
if N*A>=B:
    print(B)
else:
    print(N*A)

Buggy submission (verdict: Runtime Error):
N,A,B= list(map(int, input().split()))
if N*A>=B:
    print(B)
else
    print(N*A)
Problem p03637 (python)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
b4=[x for x in a if x%4==0]
a4=[x for x in a if x%4!=0]
b2=[x for x in a4 if x%2==0]
c=[x for x in a4 if x%2!=0]
if len(b4)==0 and (len(c)==0 and len(b2)>1):
    print('Yes')
elif len(b4)==0 and len(c)!=0:
    print('No')
elif len(b4)+1<len(c):
    print('No')
elif len(b4)<len(c) and len(b2)>0:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
b4=[x for x in a if x%4==0]
a4=[x for x in a if x%4!=0]
b2=[x for x in a4 if x%2==0]
c=[x for x in a4 if x%2!=0]
if len(b4)==0 and (len(c)==0 and len(b2)>1):
    print('Yes')
elif len(b4)==0 and len(c)!=0
    print('No')
elif len(b4)+1<len(c):
    print('No')
elif len(b4)<len(c) and len(b2)>0:
    print('No')
else:
    print('Yes')
Problem p02681 (python)

Fixed submission:
#ABC167-A

id_1 = input()
id_2 = input()

length_1 = len(id_1)
length_2 = len(id_2)

if length_2 == length_1 + 1 and id_2.startswith(id_1):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
#ABC168

n = int(input())

unit = {0:'pon', 1:'pon', 2:'hon', 3:'bon', 4:'hon', 5:'hon', 6:'pon', 7:'hon', 8:'pon', 9:'hon'}

x = n % 10
print(unit[x])
Problem p02675 (python)

Fixed submission:
d = {n: 'hon' for n in "24579"}
d.update({n: 'pon' for n in "0168"})
d.update({"3": 'bon'})
 
print(d[input()[-1]])

Buggy submission (verdict: Runtime Error):
d = {n: 'hon' for n in "24579"}
d.update({n: 'pon' for n in "0168"})
d.update({3: 'bon'})

print(d[input()[-1]])
Problem p02727 (python)

Fixed submission:
x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()))
v = 0
c = sorted(p[0:x] + q[0:y])
for i in range(x + y):
    if len(r):
        if c[i] < r[-1]:
            c[i] = r.pop()
    else:
        break
print(sum(c))

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()))
q = sorted(map(int, input().split()))
r = sorted(map(int, input().split()))
v = 0

for _ in range(x):
    if len(r):
        if p[-1] > r[-1]:
            v += p.pop()
        else:
            v += r.pop()
    else:
        v += p.pop()

for _ in range(y):
    if len(r):
        if q[-1] > r[-1]:
            v += q.pop()
        else:
            v += r.pop()
    else:
        v += r.pop()

print(v)
Problem p02888 (python)

Fixed submission:
from bisect import bisect_left, bisect_right

n = int(input())
l = sorted(map(int, input().split()))
ans = 0
for i1 in range(n - 2):
    for i2 in range(i1 + 1, n - 1):
        a = l[i1]
        b = l[i2]
        i3s = max(bisect_right(l, b - a), i2 + 1)
        i3e = bisect_left(l, a + b)
        ans += i3e - i3s
print(ans)

Buggy submission (verdict: Runtime Error):
rom bisect import bisect_left
from itertools import combinations

n = int(input())
l = sorted(map(int, input().split()))
ans = 0

for (i1, a), (i2, b) in combinations(enumerate(l[:-1]), 2):
    i3s = i2 + 1
    i3e = bisect_left(l, a + b, i3s)
    ans += i3e - i3s

print(ans)
Problem p03001 (python)

Fixed submission:
w, h, x, y = map(int, input().split())

print("{:.10f} {}".format(w * h / 2, 1 if x * 2 == w and y * 2 == h else 0))

Buggy submission (verdict: Runtime Error):
w, h, x, y = map(int, input().split())


if x == 0 and y == 0:
    s1 = h * w / 2
    s1 = s2
else:
    ym = min(y, h - y)
    xm = min(x, w - x)

    s1 = ym * w
    s2 = xm * h
    s = max(s1, s2)

o = 0
if s1 == s2:
    o = 1
print("{:.6f} {}".format(s, o))
Problem p03006 (python)

Fixed submission:
from itertools import permutations
from collections import Counter


n = int(input())
balls = []

for _ in range(n):
    x, y = map(int, input().split())
    balls.append((x, y))

if n == 1:
    print(1)
else:
    counter = Counter()
    for b1, b2 in permutations(balls, 2):
        p, q = b1[0] - b2[0], b1[1] - b2[1]
        counter[(p, q)] += 1

    (p, q), val = counter.most_common(1)[0]
    print(n - val)

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


n = int(input())
balls = []

for _ in range(n):
    x, y = map(int, input().split())
    balls.append((x, y))

counter = Counter()
for b1, b2 in permutations(balls, 2):
    p, q = b1[0] - b2[0], b1[1] - b2[1]
    counter[(p, q)] += 1

(p, q), val = counter.most_common(1)[0]
print(n - val)

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


n = int(input())
balls = []
cost = n
for _ in range(n):
    x, y = map(int, input().split())
    balls.append((x, y))

counter = Counter()
for b1, b2 in permutations(balls, 2):
    p, q = b1[0] - b2[0], b1[1] - b2[1]
    counter[(p, q)] += 1

(p, q), val = counter.most_common(1)[0]
print(n - val)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
diffs = []
xi, yi = map(int, input().split())
for _ in range(n - 1):
    xn, yn = map(int, input().split())
    diffs.append((xi - xn, yi - yn))
    xi, yi = xn, yn

c = Counter(diffs)
cv = c.most_common(1)
(p, q), val = c.most_common(1)[0]
print(n - val)
Problem p03059 (python)

Fixed submission:
def main():
    a, b, t = map(int, input().split())
    c = int((t + 0.5) // a * b)
    print(c)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from fractions import gcd
 
def main():
    n = int(input())
    a = list(map(int, input().split()))
    left = [0]
    right = [0]
    for l in a[:-1]:
        g = gcd(left[-1], l)
        left.append(g)
    for r in a[n:0:-1]:
        g = gcd(right[-1], r)
        right.append(g)
    right.reverse()
    m = 0
    for i in range(n):
        m = max(m, gcd(left[i], right[i]))
    print(m)
    
if __name__ == '__main__':
    main()
Problem p03061 (python)

Fixed submission:
from fractions import gcd

def main():
    n = int(input())
    a = list(map(int, input().split()))
    left = [0]
    right = [0]
    for i in range(1, n):
        g = gcd(left[-1], a[i - 1])
        left.append(g)
    for i in range(n - 2, -1, -1):
        g = gcd(right[-1], a[i + 1])
        right.append(g)
    right.reverse()
    m = 0
    for i in range(0, n):
        m = max(m, gcd(left[i], right[i]))
    print(m)
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def main():
    n = int(input())
    a = list(map(int, input().split()))
    left = [0 for _ in range(n)]
    right = [0 for _ in range(n)]
    for i in range(1, n):
        l = math.gcd(a[i - 1], a[i])
        r = math.gcd(a[n - i - 1], a[n - i - 2])
        left[i] = l
        right[n - i - 2] = r

    m = max(left[0], right[n - 1])
    for i in range(n - 1):
        m = max(m, left[i - 1], right[i + 1])
    print(m)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from fractions import gcd


def main():
    n = int(input())
    a = list(map(int, input().split()))
    left = [0 for _ in range(n)]
    right = [0 for _ in range(n)]
    for i in range(1, n):
        l = math.gcd(a[i - 1], a[i])
        r = math.gcd(a[n - i - 1], a[n - i - 2])
        left[i] = l
        right[n - i - 2] = r

    m = max(left[0], right[n - 1])
    for i in range(n - 1):
        m = max(m, left[i - 1], right[i + 1])
    print(m)


if __name__ == '__main__':
    main()
Problem p03067 (python)

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

if a > b:
    a, b = b, a
if a < c and c < b:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input().rstrip()
s = s.rstrip('#')
if len(s) == 0:
    print(0)
    exit()

start = s.find('#.')
if start == -1:
    print(0)
    exit()
print(s.count('.', start))
Problem p03074 (python)

Fixed submission:
n, k = map(int, input().split())
s = input().rstrip()
ans = 1
i = 0
left = 0
right = 1
while i < n:
    if k > 0:
        pos = s.find('01', i)
        if pos == -1:
            i = n
            right = n - 1
        else:
            pos = s.find('10', pos + 1)
            if pos == -1:
                i = n
                right = n - 1
            else:
                right = pos
                i = pos + 1
        k = k - 1
        ans = max(ans, right - left + 1)
    else:
        pos = s.find('01', left)
        left = pos + 1
        k = k + 1

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input().rstrip()
ans = 1
i = 0
left = 0
right = 1
while i < n:
    if k > 0:
        pos = s.find('01', i)
        if pos == -1:
            i = n
            right = n - 1
        else:
            pos = s.find('10', pos + 1)
            if pos == -1:
                i = n
                right = n - 1
            else:
                right = pos
                i = pos + 1
        k = k - 1
        print(s[left:right+1])
        ans = max(ans, right - left + 1)
    else:
        pos = s.find('01', left)
        left = pos + 1
        k = k + 1

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools


def count_maxone(binstr):
    return max([len(l) for l in binstr.split('0') if len(l)])


n, k = map(int, input().split())
s = input().rstrip()
ones = count_maxone(s)

pos = []
pre = '1'

for i in range(n):
    if s[i] == '0' and pre == '1':
        pos.append(i)
    pre = s[i]

for i in range(1, k + 1):
    combs = itertools.combinations(pos, i)
    for cmb in combs:
        slist = list(s)
        for c in cmb:
            zc = s.find('1', c)
            if zc == -1:
                zc = c + 1
            for t in range(c, zc):
                slist[t] = '1'
        ones = max(ones, count_maxone(''.join(slist)))

print(ones)
Problem p03106 (python)

Fixed submission:
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a


def divisor(a):
    res = set()
    for i in range(1, int(a * 0.5 + 1) + 1):
        if a % i == 0:
            res.add(i)
            res.add(a // i)
    return sorted(res)


a, b, k = map(int, input().split())
ans = divisor(gcd(a, b))[-k]
print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a


def divisor(a):
    res = set()
    for i in range(1, int(a * 0.5 + 1)):
        if a % i == 0:
            res.add(i)
            res.add(a // i)
    return sorted(res)


a, b, k = map(int, input().split())
ans = divisor(gcd(a, b))[-k]
print(ans)
Problem p03110 (python)

Fixed submission:
n = int(input())
ans = 0.0
for _ in range(n):
    x, u = input().split()
    if u == 'JPY':
        ans += int(x)
    else:
        ans += float(x) * 380000.0

print("{:.11f}".format(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0.0
for _ in range(n):
  x, u = input.split()
  if u == 'JPN':
    ans += int(x)
  else:
    ans += float(x) * 38000.0

print("{:.8f}".format(ans))
Problem p03136 (python)

Fixed submission:
n = int(input())
e = list(map(int, input().split()))
if max(e) < sum(e) - max(e):
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
e = list(map(int, input().split))
if max(e) < sum(e) - max(e):
  print('Yes')
else:
  print('No')
Problem p03262 (python)

Fixed submission:
from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        a, b = b, a % b
    return a

def gcd_from_list(vals):
    return reduce(gcd, vals)

n, x = map(int, input().split())
c = [abs(x - xn) for xn in map(int, input().split())]
print(gcd_from_list(c))

Buggy submission (verdict: Runtime Error):
def gcd(*args):
    a, *args = args
    if len(args) == 0:
        return a
    elif len(args) > 1:
        return gcd(a, gcd(*args))
    else:
        b = args[0]
        if a < b:
            a, b = b, a
        while b != 0:
            a, b = b, a % b
        return a


n, x = map(int, input().split())
c = [abs(x - xn) for xn in map(int, input().split())]
print(gcd(*c))
Problem p03264 (python)

Fixed submission:
k = int(input())
a, b = k // 2 + k % 2, k // 2
print(a * b)

Buggy submission (verdict: Runtime Error):
k = int(input())
a, b = a // 2 + a % 2, a // 2
print(a * b)