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

Fixed submission:
N, A = map(int, input().split())  # N枚のカード, 平均をAにしたい

X = tuple(map(int, input().split()))  # カードリスト

# [カードの総枚数][選んだカードの枚数][今の総和]
dp = [[[0]*(50*N+1) for _ in range(N+1)] for _ in range(N+1)]

# 0枚の中から0枚選んで総和が0になるパターンは1つ
dp[0][0][0] = 1

for i in range(N):
    for j in range(N+1):
        for k in range(N*50+1):
            if dp[i][j][k]:  # 今の状態を未来へ遷移させる処理
                dp[i+1][j][k] += dp[i][j][k]  # 何も加えず未来へ
                dp[i+1][j+1][k+X[i]] += dp[i][j][k]  # 今見ているカードを加えて未来に遷移

ans = 0
for i in range(1, N+1):
    ans += dp[N][i][i*A]

print(ans)

Buggy submission (verdict: Runtime Error):
N, A = map(int, input().split())  # N枚数のカード, 平均をAにしたい
X = tuple(map(int, input().split()))  # N枚のカードの中身

dp = [[[0]*(50*N+1) for _ in range(N+1)] for _ in range(N+1)]

dp[0][0][0] = 1  # 0枚の中から0枚選んで合計が0になる選び方が1通りある

for i in range(N):
    for j in range(N+1):
        for s in range(50*N+1):
            if s >= X[i]:  # 今見ているのはX[i], これをどうするかで遷移先を変更する
                dp[i+1][j+1][s] += dp[i][j][s-X[i]]  # 追加する余裕がある場合は追加する
            dp[i+1][j][s] += dp[i][j][s]  # 何も追加しない
ans = 0
for i in range(1, N+1):
    ans += dp[N][i][i*A]
print(ans)

Buggy submission (verdict: Runtime Error):
N, A = map(int, input().split())  # N枚数のカード, 平均をAにしたい
X = tuple(map(int, input().split()))  # N枚のカードの中身

dp = [[[0]*(50*N+1) for _ in range(N+1)] for _ in range(N+1)]

dp[0][0][0] = 1  # 0枚の中から0枚選んで合計が0になる選び方が1通りある

for i in range(N):
    now_card = X[i]
    for j in range(N+1):
        for s in range(50*N+1):
            if s >= now_card:  # 今見ているのはX[i], これをどうするかで遷移先を変更する
                dp[i+1][j+1][s] += dp[i][j][s-now_card]  # 追加する余裕がある場合は追加する
            dp[i+1][j][s] += dp[i][j][s]  # 何も追加しない
ans = 0
for i in range(1, N+1):
    ans += dp[N][i][i*A]
print(ans)

Buggy submission (verdict: Runtime Error):
N, A = map(int, input().split())  # N枚数のカード, 平均をAにしたい
X = list(map(int, input().split()))  # N枚のカードの中身

dp = [[[0]*(max(X)*N+2) for _ in range(N+2)] for _ in range(N+2)]

dp[0][0][0] = 1  # 0枚の中から0枚選んで合計が0になる選び方が1通りある

for i in range(N):
    now_card = X[i]
    for j in range(N+1):
        for s in range(max(X)*N+1):
            if s >= now_card:  # 今見ているのはX[i], これをどうするかで遷移先を変更する
                dp[i+1][j+1][s] += dp[i][j][s-now_card]  # 追加する余裕がある場合は追加する
            dp[i+1][j][s] += dp[i][j][s]  # 何も追加しない
ans = 0
for i in range(1, N+1):
    ans += dp[N][i][i*A]
print(ans)

Buggy submission (verdict: Runtime Error):
N, A = map(int, input().split())  # N枚のカード, 平均をAにしたい

X = list(map(int, input().split()))  # カードリスト

# [カードの総枚数][選んだカードの枚数][今の総和]
dp = [[[0]*(max(X)*N+1) for _ in range(N+1)] for _ in range(N+1)]

# 0枚の中から0枚選んで総和が0になるパターンは1つ
dp[0][0][0] = 1

for i in range(len(X)):
    for j in range(1, N+1):
        for k in range(1, N+1):
            for s in range(1, max(X)*N+1):
                if s < X[i]:
                    dp[j][k][s] = dp[j-1][k][s]
                if s >= X[i]:
                    # すでにsになっているものと、今見ているカードを加えることでsになるもの
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-X[i]]


ans = 0
for j in range(1, N+1):
    for k in range(1, N+1):
        ans += dp[j][k][k*A]

print(ans)
Problem p04026 (python)

Fixed submission:
S = str(input())

left = -2
right = -2

for i in range(max(1, len(S)-2)):
    if S[i] == S[i+1]:
        left = i
        right = i+1
        break
    if len(S) == 2:
        break
    if S[i] == S[i+2]:
        left = i
        right = i+2
        break
    if S[i+1] == S[i+2]:
        left = i+1
        right = i+2
        break

print(left+1, right+1)

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

left = -2
right = -2

for i in range(max(1, len(S)-2)):
    if S[i] == S[i+1]:
        left = i
        right = i+1
        break
    if S[i] == S[i+2]:
        left = i
        right = i+2
        break
    if S[i+1] == S[i+2]:
        left = i+1
        right = i+2
        break

print(left+1, right+1)
Problem p04035 (python)

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

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

ans_index = -1
for i in range(N-1):
    if A[i] + A[i+1] >= L:
        ans_index = i
        break

if ans_index == -1:
    print('Impossible')
    exit()
print('Possible')

ans_index += 1
for i in range(1, ans_index):
    print(i)
for i in range(N-1, ans_index, -1):
    print(i)

print(ans_index)

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

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

ans_index = -1
for i in range(N-1):
    if A[i] + A[i+1] >= L:
        ans_index = i
        break

if ans_index == -1:
    print('Impossible')
    exit()
print('Possible')

ans_index += 1
for i in range(1, ans_index):
    print(i)
for i in range(N-1, n, -1):
    print(i)

print(ans_index)

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

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

ans_index = -1
for i in range(N-1):
    if A[i] + A[i+1] >= L:
        ans_index = i
        break

ans = list(range(1, i)).extend(list(i+1, N-1)).append(ans_index)

if ans_index == -1:
    print('Impossible')
else:
    for i in range(len(ans)):
        print('Possible')
        print(ans[i])
Problem p02573 (python)

Fixed submission:
import sys
from collections import defaultdict
sys.setrecursionlimit(10 + 2 * 10 ** 5)
 
n, m = map(int, input().split())
 
color = [None] * (n + 1)
for i in range(n + 1):
    color[i] = i
 
def root(x):
    global color
 
    if color[x] == x:
        return x
    color[x] = root(color[x])
    return color[x]
 
def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx == ry:
        return
    color[rx] = ry
 
for i in range(m):
    a, b = map(int, input().split())
    unite(a, b)
 
cnt = defaultdict(int)
for i in range(n):
    cnt[root(i + 1)] += 1
print(max(cnt.values()))

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

n, m = map(int, input().split())

color = [None] * (n + 1)
for i in range(n + 1):
    color[i] = i

def root(x):
    global color

    if color[x] == x:
        return x
    return root(color[x])

def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx == ry:
        return
    color[rx] = ry

for i in range(m):
    a, b = map(int, input().split())
    unite(a, b)

cnt = defaultdict(int)
for i in range(n):
    cnt[root(i + 1)] += 1
print(max(cnt.values()))
Problem p02618 (python)

Fixed submission:
d = int(input())
c = tuple(map(int, input().split()))
s = [
    tuple(map(int, input().split()))
    for _ in range(d)
]

for i in range(d):
    m = sorted((ss, j) for j, ss in enumerate(s[i]))[-1]
    print(m[1] + 1)

Buggy submission (verdict: Runtime Error):
d = int(input())
c = tuple(map(int, input().split()))
s = [
    tuple(map(int, input().split()))
    for _ in range(d)
]

m = 0
ans = []
last = [0] * 26
for i in range(d):
    # for all contest
    mdmax = 0
    mdi = 0
    for j, ss in enumerate(s[i]):
        md = 0
        # choose one contest to open
        for k in range(26):
            if j == k:
                md += s[i][j]
            else:
                md -= (i - last[k]) * c[i]
        if md > mdmax:
            mdi = j
            mdmax = md
    ans.append(mdi + 1)
    for j in range(26):
        if j == mdi:
            last[j] = 0
        else:
            last[j] += 1

for a in ans:
    print(a)
Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

c = [None] * 200000
cc = set()
p = 0
st = 0
ed = 0
i = 0
while True:
    c[i] = p
    cc.add(p)
    i += 1
    p = a[p]
    if p in cc:
        st = c.index(p)
        ed = i
        break
if k < ed:
    print(c[k] + 1)
else:
    k -= st
    k %= ed - st
    print(c[st + k] + 1)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

c = []
p = 0
na = 0
st = 0
ed = 0
while True:
    c.append(p)
    p = a[p]
    na += 1
    if p in c:
        st = p
        ed = len(c)
        break
if k < len(c):
    print(c[k] + 1)
else:
    k -= st
    k %= ed - st
    print(c[k] + 1)
Problem p02717 (python)

Fixed submission:
a, b, c = map(int, input().split())
print("{} {} {}".format(c, a, b))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(f"{c} {a} {b}")
Problem p02817 (python)

Fixed submission:
s, t = input().rstrip().split()
print(t + s)

Buggy submission (verdict: Runtime Error):
s, t = list(input().split().rstrip())
print(t + s)

Buggy submission (verdict: Runtime Error):
s, t = input().split().rstrip()
print(t + s)
Problem p02900 (python)

Fixed submission:
import math

def divisors(n):
    s = set()
    for x in range(2, math.ceil(n ** 0.5) + 1):
        while n % x == 0:
            s.add(x)
            n /= x
            if n == 1:
                break
    if n > 1:
        s.add(n)
    return s
 
a, b = map(int, input().split())
d = divisors(a) & divisors(b)
print(len(d) + 1)

Buggy submission (verdict: Runtime Error):
import math

def divisors(n):
    s = set()
    for x in range(2, math.ceil(n ** 0.5) + 1):
        while n % x == 0:
            s.add(x)
            n //= x
    return s

a, b = map(int, input().split())
print(len(divisors(math.gcd(a, b))) + 1)
Problem p02981 (python)

Fixed submission:
n, a, b = map(int, input().split())
print(min(a * n, b))

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input())
print(min(a * n, b))

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input())
print(min(a * n, b))
Problem p03244 (python)

Fixed submission:
from collections import Counter
n = int(input())
v = tuple(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
if len(set(v)) == 1:
    print(n // 2)
else:
    c1m = c1.most_common(2)
    c2m = c2.most_common(2)
    if c1m[0][0] == c2m[0][0]:
        print(min(n - c1m[0][1] - c2m[1][1], n - c1m[1][1] - c2m[0][1]))
    else:
        print(n - c1m[0][1] - c2m[0][1])

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
v = tuple(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
if len(set(v)) == 1:
    print(n // 2)
else:
    c1m = c1.most_common(1)
    c2m = c2.most_common(1)
    if c1m[0][0] == c2m[0][0]:
        print(min(n - c1m[0][1] - c2m[1][1], n - c1m[1][1] - c2m[0][1]))
    else:
        print(n - c1m[0][1] - c2m[0][1])
Problem p02664 (python)

Fixed submission:
S = input()
N = len(S)
ans = ""
flag = ""
ans2 = ""

if(N==1):
  if(S == "?"):
    print("D")
  else:
    print(S)
else:
  for i in range(N):
    if(S[i] == "?"):
      flag += "1"
      ans += "D"
    else:
      flag += "0"
      ans += S[i]
  for i in range(N):
    if(i==0):
      if(ans[i+1] == "D" and flag[i] == "1"):
        ans2 += "P"
      else:
        ans2 += ans[i]
    elif(i==N-1):
      ans2 += ans[i]
    else:
      if(ans2[i-1] == "D" and ans[i+1] == "D" and flag[i] == "1"):
        ans2 += "P"
      else:
        ans2 += ans[i]
  print(ans2)

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
ans = ""
flag = ""
ans2 = ""

for i in range(N):
  if(S[i] == "?"):
    flag += "1"
    ans += "D"
  else:
    flag += "0"
    ans += S[i]
for i in range(N):
  if(i==0):
    if(ans[i+1] == "D" and flag[i] == "1"):
      ans2 += "P"
    else:
      ans2 += ans[i]
  elif(i==N-1):
    ans2 += ans[i]
  else:
    if(ans2[i-1] == "D" and ans[i+1] == "D" and flag[i] == "1"):
      ans2 += "P"
    else:
      ans2 += ans[i]
print(ans2)
Problem p03697 (python)

Fixed submission:
A,B = list(map(int, input().split()))
if(A+B>=10):
  print("error")
else:
  print(A+B)

Buggy submission (verdict: Runtime Error):
A,B = list(map()int, input().split())
if(A+B>=10):
  print("error")
else:
  print(A+B)
Problem p02548 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(1,n):
    ans += (n-1)//i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
import sympy
ans = 0
for i in range(1,n):
    ans += sympy.divisor_count(i)
print(ans)

Buggy submission (verdict: Runtime Error):
import sympy
n = int(input())
ans = 0
for i in range(1,n):
    ans += sympy.divisor_count(i)
print(ans)
Problem p02683 (python)

Fixed submission:
n,m,x = map(int,input().split())
c = list(list(map(int,input().split())) for _ in range(n))
ans = 10**7
for i in range(1<<n):
    mokuhyo = [0]*m
    cost = 0
    for j in range(n):
        if i>>j&1:
            for r in range(m):
                mokuhyo[r] += c[j][r+1]
            cost += c[j][0]
    if all(k>=x for k in mokuhyo):
        ans = min(ans, cost)
print("-1" if ans == 10**7 else ans)

Buggy submission (verdict: Runtime Error):
ans = 10**7
for i in range(1<<n):
    mokuhyo = [0]*m
    cost = 0
    for j in range(n):
        if i>>j&1:
            for r in range(m):
                mokuhyo[r] += c[j][r+1]
            cost += c[j][0]
    if all(k>=x for k in mokuhyo):
        ans = min(ans, cost)
print("-1" if ans == 10**7 else ans)

Buggy submission (verdict: Runtime Error):
ans = float("inf")
for i in range(1<<n):
    mokuhyo = [0]*m
    cost = 0
    for j in range(n):
        if i>>j&1:
            for r in range(m):
                mokuhyo[r] += c[j][r+1]
            cost += c[j][0]
    for k in mokuhyo:
        if k < x:
            break
        else:
            ans = min(ans, cost)
print("-1" if ans == 10**7 else ans)
Problem p03290 (python)

Fixed submission:
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

for bit in range(1 << d):
    count = 0
    sum = 0
    nokori = set(range(1, d + 1))

    for i in range(d):
        if bit & (1 << i):
            sum += pc[i][0] * (i + 1) * 100 + pc[i][1]
            count += pc[i][0]
            nokori.discard(i + 1)

    # G 点に満たなければ nokori のうち一番大きいものを解く
    if sum < g:
        use = max(nokori)
        n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
        count += n
        sum += n * use * 100

    if sum >= g:
        ans = min(ans, count)

print(ans)

Buggy submission (verdict: Runtime Error):
ans = float("inf")
for i in range(1<<d):
    count = 0
    sum = 0
    nokori = set(range(1, d+1))
    
    # ボーナスをもらえる解答のみでスコアを計算
    for j in range(d):
        if j & 1<<i:
            sum += pc[i][0]*(i+1)*100+pc[i][1]
            count += pc[i][0]
            nokori.discard(i+1)
            
    # スコアがG点に届かない場合
    if sum < g:
        use = max(nokori)
        n = min(pc[use-1][0], (g-sum)//(use*100))
        count += n
        sum += n*use*100
        
    # スコアがG点に届いた場合
    if sum >= g:
        ans = min(ans, count)
print(ans)
Problem p03339 (python)

Fixed submission:
N = int(input())
S = input()
e = S.count("E")
cnt = e
for i in S:
    if i == "E":
        cnt -= 1
    else:
        cnt += 1
    e = min(e, cnt)
print(e)

Buggy submission (verdict: Runtime Error):
e = S.count("E")
cnt = e
for i in S:
    if i == "E":
        cnt -= 1
    else:
        cnt += 1
    e = min(e, cnt)
print(e)
Problem p03361 (python)

Fixed submission:
H, W = map(int, input().split())
s = list(list(input()) for _ in range(H))
ans = True
d = [(0,1),(0,-1),(1,0),(-1,0)]
for y in range(H):
    for x in range(W):
        if s[y][x] == "#":
            for dy, dx in d:
                ny = y + dy
                nx = x + dx
                if ny<0 or H<=ny or nx<0 or W<=nx:
                    continue
                if s[ny][nx]=="#":
                    break
            else:
                ans = False
print("Yes" if ans else "No")

Buggy submission (verdict: Runtime Error):
ans = True
d = [(0,1),(0,-1),(1,0),(-1,0)]
for y in range(H):
    for x in range(W):
        if s[y][x] == "#":
            for dy, dx in d:
                ny = y + dy
                nx = x + dx
                if ny<0 or H<=ny or nx<0 or W<=nx:
                    continue
                if s[ny][nx]=="#":
                    break
            else:
                ans = False
print("Yes" if ans else "No")
Problem p03457 (python)

Fixed submission:
N = int(input())
txy = list(list(map(int, input().split())) for _ in range(N))
dt = 0
dx = 0
dy = 0
for i in range(N):
    if abs(txy[i][1]-dx)+abs(txy[i][2]-dy) > txy[i][0]-dt or (txy[i][1]+txy[i][2])%2 != txy[i][0]%2:
        print("No")
        break
    dt = txy[i][0]
    dx = txy[i][1]
    dy = txy[i][2]
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
dt = 0
dx = 0
dy = 0
for i in range(N):
    if abs(txy[i][1]-dx)+abs(txy[i][2]-dy) > txy[i][0]-dt or (txy[i][1]+txy[i][2])%2 != txy[i][0]%2:
        print("No")
        break
    dt = txy[i][0]
    dx = txy[i][1]
    dy = txy[i][2]
else:
    print("Yes")
Problem p03470 (python)

Fixed submission:
N = int(input())
d = list(int(input()) for _ in range(N))
print(len(set(sorted(d))))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = list(int(input()) for _ in range(N))
print(len(set(sortd(d))))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = lisat(int(input()) for i in range(N))
print(len(set(sortd(d))))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = lisat(int(input()) for _ in range(N))
print(len(set(sortd(d))))
Problem p03599 (python)

Fixed submission:
A, B, C, D, E, F = map(int, input().split())
dens = 0
ans_water = 100*min(A, B)
ans_sugar = 0
for i in range(31):
    for j in range((F-(100*A*i))//(100*B)+1):
        for k in range((F-(100*A*i)-(100*B*j))//C+1):
            for l in range((F-(100*A*i)-(100*B*j)-(C*k))//D+1):
                water = 100*A*i+100*B*j
                sugar = C*k+D*l
                if water == 0:
                    break
                if sugar <= E*(A*i+B*j):
                    if dens<sugar/(sugar+water):
                        dens = sugar/(sugar+water)
                        ans_water = water
                        ans_sugar = sugar
print(ans_water+ans_sugar, ans_sugar)

Buggy submission (verdict: Runtime Error):
dens = 0
ans_water = 0
ans_sugar = 0
for i in range(31):
    for j in range((F-(100*A*i))//(100*B)+1):
        for k in range((F-(100*A*i)-(100*B*j))//C+1):
            for l in range((F-(100*A*i)-(100*B*j)-(100*C*k))//D+1):
                water = 100*A*i+100*B*j
                sugar = C*k+D*l
                if i==j==0:
                    break
                if water+sugar <= F and sugar <= E*(A*i+B*j):
                    if dens<sugar/(sugar+water):
                        dens = sugar/(sugar+water)
                        ans_water = water
                        ans_sugar = sugar
print(ans_water+ans_sugar, ans_sugar)

Buggy submission (verdict: Runtime Error):
dens = 0
ans_water = 0
ans_sugar = 0
for i in range(31):
    for j in range(31):
        for k in range(101):
            water = 100*A*i+100*B*j
            sugar = C*k+D*(((A*i+B*j)*E-C*k)//D)
            if water == 0:
                continue
            if water+sugar <= F and dens <= sugar/(sugar+water):
                    dens = sugar/(sugar+water)
                    ans_water = water
                    ans_sugar = sugar
print(ans_water+ans_sugar, ans_sugar)

Buggy submission (verdict: Runtime Error):
dens = 0
ans_water = 0
ans_sugar = 0
for i in range(31):
    for j in range(31):
        for k in range(101):
            for l in range(101):
                water = 100*A*i+100*B*j
                sugar = C*k+D*l
                if i==j==0:
                    break
                if water+sugar <= F and sugar <= E*(A*i+B*j):
                    if dens<sugar/(sugar+water):
                        dens = sugar/(sugar+water)
                        ans_water = water
                        ans_sugar = sugar
print(ans_water+ans_sugar, ans_sugar)

Buggy submission (verdict: Runtime Error):
water = 0
sugar = 0
for i in range(F//(100*A)+1):
    for j in range(F//(100*B)+1):
        for k in range(F//C+1):
            for l in range(F//D+1):
                water = 100*i+100*j
                sugar = k+l
                if water+sugar <= F and sugar <= E//100*water:
                    break
print(water+sugar, sugar)
Problem p03611 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
cnt = [0]*(10**7)
for i in a:
    cnt[i-1] += 1
    cnt[i] += 1
    cnt[i+1] += 1
print(max(cnt))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
cnt = [0]*(10**5+1)
for i in a:
    cnt[i] += 1
    cnt[i+1] += 1
    cnt[i+2] += 1
print(max(cnt))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
cnt = [0]*(10**5)
for i in a:
    cnt[i-1] += 1
    cnt[i] += 1
    cnt[i+1] += 1
print(max(cnt))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
cnt = [0]*(10**5)
for i in a:
    cnt[i-1] += 1
    cnt[i] += 1
    cnt[i+1] += 1
print(max(cnt))
Problem p03680 (python)

Fixed submission:
N = int(input())
a = list(int(input()) for _ in range(N))
cnt = 0
l = 1
for _ in range(N):
        l = a[l-1]
        cnt += 1
        if l == 2:
            print(cnt)
            break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
cnt = 1
l = a[0]
for _ in range(N):
    if l in a:
        l = a[l-1]
        cnt += 1
        if l == 2:
            print(cnt)
            break
else:
    print(-1)
Problem p03739 (python)

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

def chk(a,t):     # t=True(奇数項が正), t=False(偶数項が正) 
    cnt=0   # 操作回数
    x=0     # 塁積和        
    for i in a:
        x+=i      
        if t==True and x<=0:       # 正項予定なのに累積が負か0
            cnt+=1-x                              
            x=x+(1-x)               # 今回のcntで符号変更
        elif t==False and x>=0:   # 負項予定なのに累積が正か0
            cnt+=1+x              
            x=x-(1+x)              # 今回のcntで符号変換
        t = not t                  # 次の項は符号が逆
    return cnt

print(min(chk(a,True),chk(a,False)))

Buggy submission (verdict: Runtime Error):
def chk(a,t):     # t=True(奇数項が正), t=False(偶数項が正) 
    cnt=0   # 操作回数
    x=0     # 塁積和        
    for i in a:
        x+=i      
        if t==True and x<=0:       # 正項予定なのに累積が負か0
            cnt+=1-x                              
            x=x+(1-x)               # 今回のcntで符号変更
        elif t==False and x>=0:   # 負項予定なのに累積が正か0
            cnt+=1+x              
            x=x-(1+x)              # 今回のcntで符号変換
        t = not t                  # 次の項は符号が逆
    return cnt
print(min(chk(a,True),chk(a,False)))
Problem p03963 (python)

Fixed submission:
N, K = map(int,input().split())
ans = 1
for i in range(N):
    if i == 0:
        ans *= K
    else:
        ans *= K-1
print(ans)

Buggy submission (verdict: Runtime Error):
ans = 1
for i in range(N):
    if i == 0:
        ans *= K
    else:
        ans *= K-1
print(ans)
Problem p02584 (python)

Fixed submission:
v = input().split(" ")
x = int(v[0])
k = int(v[1])
d = int(v[2])

if (x == 0):
    if (k % 2 == 0):
        ans = 0
    else:
        ans = d
else:
    if ((k * d) > abs(x)):
        y = abs(x) // d
        ans = abs(abs(x) - y * d)
        if ((k - y) % 2 == 1):
            ans = abs(d - ans)
    else:
        ans = abs(x) - k * d


print(ans)

Buggy submission (verdict: Runtime Error):
v = input().split(" ")
x = int(v[0])
k = int(v[1])
d = int(v[2])

if ((k * d) > abs(x)):
    y = x // d
    if ((k - y) % 2 == 0):
        ans = abs(x) - y * d
    else:
        ans = abs(x - (x // abs(x)) * (y + 1) * d)
else:
    ans = abs(x) - k * d


print(ans)

Buggy submission (verdict: Runtime Error):
x = int(input())
k = int(input())
d = int(input())

if ((k * d) > abs(x)):
    y = x // d
    if ((k - y) % 2 == 0):
        ans = abs(x) - y * d
    else:
        ans = abs(x - (x // abs(x)) * (y + 1) * d)
else:
    ans = abs(x) - k * d


print(ans)