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

Fixed submission:
def f(n):
    if n == 0: return ""
    n -= 1
    return (f(n // 26) + chr(ord("a") + n % 26))

def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    n = input_number()
    ans = f(n)
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    from builtins import int, map, list, print, len
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    dog_no = input_number()
    base = 26
    alphabet = "abcdefghijklmnopqlstuvwxyz"
    n = 1
    n_ls = [n]
    t_ls = [0]
    while n <= 10 ** 15 + 1:
        n *= base
        n_ls.append(n + n_ls[-1])
        t_ls.append(n)
    n_ls.sort(reverse=True)
    t_ls.sort(reverse=True)

    ans = ""
    for i in range(len(n_ls)):
        d = dog_no // (n_ls[i])
        if d >= 1:
            if i == len(n_ls) - 1:
                ans += alphabet[dog_no - 1]
            else:
                a = dog_no // t_ls[i]
                dog_no %= t_ls[i]
                ans += alphabet[a - 1]
    print(ans)


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

Fixed submission:
N = int(input())
max = int(N**0.5)
a = max-1
for i in range(max,0,-1):
    v = N % i
    if v == 0:
        mult = N / i
        a = mult + i
        break
print(int(a-2))

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
tmp = []
for i in range(1, int(math.sqrt(N))):
    v = N % i
    if v == 0:
        mult = N / i
        tmp.append(int(i + mult - 2))
print(min(tmp))
Problem p03013 (python)

Fixed submission:
import sys
N, W = input().split()
aArr = list()
ans = 0
tmp = int(N)
MOD = 10 ** 9 + 7
aArr = set(map(int, sys.stdin))

tmp = 0
tmpB = 0
ans = 1
for i in range(int(N)):
    if (i in aArr):
        tmp = 0
    elif i < 2:
        tmp = 1
    else:
        tmp = ans
    ans = (tmp + tmpB) % MOD
    tmpB = tmp
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin
N, W = input().split()
aArr = list()
ans = 0
tmp = int(N)
MOD = 10 ** 9 + 7
aArr = set(map(int, input()))

tmp = 0
tmpB = 0
ans = 1
for i in range(int(N)):
    if (i in aArr):
        tmp = 0
    elif i < 2:
        tmp = 1
    else:
        tmp = ans
    ans = (tmp + tmpB) % MOD
    tmpB = tmp
print(ans)
Problem p02762 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N, M, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]

par = [n+1 for n in range(N)]
rank = [0 for _ in range(N)]
size = [1 for _ in range(N)]

# 木の根を求める
def find(x):
  if par[x-1] != x:
    par[x-1] = find(par[x-1])
  return par[x-1]
# x, y の属する集合を併合
def unite(x, y):
  rx = find(x)
  ry = find(y)
  if rx == ry:
    return
  if rank[rx-1] < rank[ry-1]:
    rx, ry = ry, rx
  par[ry-1] = rx
  size[rx-1] += size[ry-1]
  if rank[rx-1] == rank[ry-1]:
    rank[rx-1] += 1
# x, y が同じ集合に属するか否か
def same(x, y):
  return find(x) == find(y)
def getsize(x):
  return size[find(x)-1]

friends = [0 for _ in range(N)]
for A, B in AB:
  unite(A, B)
  friends[A-1] += 1
  friends[B-1] += 1

ans = [0 for _ in range(N)]

for n in range(N):
  ans[n] = getsize(n+1) - friends[n] -1

for C, D in CD:
  if same(C, D):
    ans[C-1] -= 1
    ans[D-1] -= 1
print(' '.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]

A = [0 for _ in range(N)]
friend = [[] for _ in range(N)]
block = [[] for _ in range(N)]
answer = [[] for _ in range(N)]

for a, b in AB:
  friend[a-1].append(b)
  friend[b-1].append(a)

for c, d in CD:
  block[c-1].append(d)
  block[d-1].append(c)

def search(root, fs, check):
  for f in fs:
    if check[f-1] != 0 or f == root:
      continue
    else:
      check[f-1] = 1
    search(root, friend[f-1], check)
    if f not in block[root-1] and f not in friend[root-1] and f != root:
      if f not in answer[root-1]:
        answer[root-1].append(f)

for i in range(N):
  search(i+1, friend[i], [0 for _ in range(N)])

for i in range(N):
  A[i] = len(answer[i])

print(' '.join(map(str, A)))
Problem p02881 (python)

Fixed submission:
import math

N = int(input())

n = int(math.sqrt(N)) + 1
lens = [N-1]
for a in range(2, n):
  if N % a == 0:
    lens.append(a+N//a-2)

print(min(lens))

Buggy submission (verdict: Runtime Error):
import math

N = int(input())

n = int(math.sqrt(N))
lens = []
for a in range(1, n):
  if N % a == 0:
    lens.append(a+N//a-2)

print(min(lens))
Problem p02862 (python)

Fixed submission:
import itertools
X, Y=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
MOD = 10**9 + 7
if (X+Y)%3 != 0:
    print(0)
else:

    n = int((2*Y-X)/3)
    m = int((2*X-Y)/3)

    # print(f"n:{n}, m:{m}")

    if n<0 or m<0:
        print(0)
    else:
        ret = 1
        for i in range(m):
            ret = ret * ((X+Y)//3 - i) % MOD * pow(i + 1, MOD-2, MOD) % MOD
        print(ret)

Buggy submission (verdict: Runtime Error):
import itertools
X, Y=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
MOD = 10**9 + 7
from math import factorial
# a = factorial(n+m) / factorial(n) / factorial(m)

if (X+Y)%3 != 0:
    print(0)
else:

    n = int((2*Y-X)/3)
    m = int((2*X-Y)/3)

    # print(f"n:{n}, m:{m}")

    if n<0 or m<0:
        print(0)
    else:
        # ret = 1
        # for i in range(m):
        #     ret = ret * ((X+Y)//3 - i) % MOD * pow(i + 1, MOD-2, MOD) % MOD
        a = factorial(n+m) / factorial(n) / factorial(m)
        print(a%MOD)

Buggy submission (verdict: Runtime Error):
import itertools
X, Y=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
MOD = 10**9 + 7
if (X+Y)%3 != 0:
    print(0)
else:

    n = int((2*Y-X)/3)
    m = int((2*X-Y)/3)

    # print(f"n:{n}, m:{m}")

    if n<0 or m<0:
        print(0)
    else:
        for i in range(m):
            ret = ret * (n - i) % MOD * pow(i + 1, MOD-2, MOD) % MOD
        print(ret)
Problem p03329 (python)

Fixed submission:
N = int(input())
dp = dict()

dp[0] = 0
for n in range(1, N+1):
  ans = dp[n-1] + 1
  
  # メモ化
  x = 6
  while x <= n:
    ans = min(ans, dp[n-x]+1)
    x *= 6
  
  x = 9
  while x <= n:
    ans = min(ans, dp[n-x]+1)
    x *= 9
    
  dp[n] = ans
  
print(dp[N])

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

max_N = 1000000
memo = [False]*max_N

# 貰う DPではなく、再帰を使ったメモ化再帰
def f(n):
	if n < 6:
		return n
	if memo[n]:
		return memo[n]
	
	ans = n
	# メモ化
	x = 6
	while x <= n:
		ans = min(ans, f(n-x)+1)
		x *= 6
	
	x = 9
	while x <= n:
		ans = min(ans, f(n-x)+1)
		x *= 9
	
	return ans
		
	
print(f(n))
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
a, b = [0], [0]
for i in range(N):
  # a[i+1]: i番目のものまで読むのにかかる総時間
  a.append(a[i]+As[i]) # 累積和の考え方
for i in range(M):
  # aのBバージョン
  b.append(b[i] + Bs[i])

ans = 0
j = M # Bから読める冊数の最大値を入れておく
for i in range(N+1):
  if a[i] > K: # 読めない
    break
  while b[j] > K-a[i]: #すべてのiに対して、a[i]+b[j]<=K になるjを求めたい
    j -= 1
  ans = max(ans, i+j) # i+jが最大値を更新したら記録

print(ans)

Buggy submission (verdict: Runtime Error):
def see_next(N, M, As, Bs, a, b):
  if a == N and b == M:
    return 1
  elif As[a] < Bs[b]:
    return 1
  elif As[a] > Bs[b]:
    return 0
  elif As[a] == Bs[b]:
    return see_next(N, M, As, Bs, a+1, b+1)

N, M, K = map(int,input().split())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
As.append(K+1)
Bs.append(K+1)
a = 0
b = 0
time = 0
ans = -1
while time <= K:
  ans += 1
  if a == N and b == M:
    break
  elif As[a] < Bs[b]:
    time += As[a]
    # print(As[a])
    a += 1
  elif As[a] > Bs[b]:
    time += Bs[b]
    # print(Bs[b])
    b += 1
  elif As[a] == Bs[b]:
    if see_next(N, M, As, Bs, a+1, b+1):
      time += As[a]
      a += 1
    else:
      time += Bs[b]
      b += 1
  
print(ans)
Problem p02624 (python)

Fixed submission:
# 正整数Xの正約数個数をf(X)とするときの \sum_(K=1)^N {K*f(K)}
# 正整数jの倍数でありN以下のものの総和をg(j)とするときの \sum_(j=1)^N g(j)

N = int(input())
ans = 0
for j in range(1, N+1):
  # Y = N/j とすると g(j) = j+2j+...+Yj = (1+2+...+Y)j = Y(Y+1)/2 *j
  g = (N//j)*(N//j+1)*j//2
  ans += g
print(ans)

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

Fixed submission:
import itertools
n,m,q=map(int,input().split())
qs = [list(map(int,input().split())) for i in range(q)]

max_ans = 0
for mid in itertools.combinations_with_replacement(range(1,m+1), n):
    sum_ans=0
    for q in qs:
        if mid[q[1]-1]-mid[q[0]-1] == q[2]:
            sum_ans += q[3]
    if sum_ans > max_ans:
        max_ans = sum_ans
        
print(max_ans)

Buggy submission (verdict: Runtime Error):
import itertools
n,m,q=map(int,input().split())
qs = [list(map(int,input().split())) for i in range(q)]
mids = [i for i in range(m)]
# print(nums)
max_ans= 0
for mid in itertools.combinations_with_replacement(nums, n-1):
    if sum(mid)>m-1:
        continue
    sum_ans=0
    for i in qs:
        sum_mid = 0
        for j in range(i[0]-1,i[1]-1):
            sum_mid += mid[j]
        if sum_mid == i[2]:
            sum_ans += i[3]
    if sum_ans > max_ans:
        max_ans = sum_ans
        
print(max_ans)

Buggy submission (verdict: Runtime Error):
import itertools
n,m,q=map(int,input().split())
qs = [list(map(int,input().split())) for i in range(q)]
mids = [i for i in range(m)]
# print(nums)
max_ans= 0
for mid in itertools.combinations_with_replacement(nums, n-1):
    if sum(mid)>m-1:
        continue
    sum_ans=0
    for i in qs:
        sum_mid = 0
        for j in range(i[0]-1,i[1]-1):
            sum_mid += mid[j]
        if sum_mid == i[2]:
            sum_ans += i[3]
    if sum_ans > max_ans:
        max_ans = sum_ans
        
print(max_ans)
Problem p02723 (python)

Fixed submission:
s=input()
print("Yes" if s[2]==s[3] and s[4]==s[5] else "No")

Buggy submission (verdict: Runtime Error):
x=int(input())
print(x//500*1000+x%500//5*5)
Problem p02699 (python)

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

Buggy submission (verdict: Runtime Error):
s = input()
num = len(s)

dp = [0]*num
temp = [0]*2019
for i in range(num):
    temp[int(s[i:]) % 2019] += 1

ans = temp[0]
for t in temp:
    if t > 1:
        ans += t*(t-1)/2

print(int(ans))
Problem p02753 (python)

Fixed submission:
S = input()

if S == "AAA" : print("No")
elif S == "BBB":print("No")
else : print("Yes")

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

d = deque()
S = input()
d.append(S)
Q = int(input())
Flag = True
 
for i in range(Q):
    Query = input()
    if Query[0] == "1":
        Flag = not Flag
    else:
        QueryList = Query.split()
        if Flag:
            if QueryList[1] =="1":
                d.appendleft(QueryList[2])
            else:
                d.append(QueryList[2])
        else:
            if QueryList[1] =="2":
                d.appendleft(QueryList[2])
            else:
                d.append(QueryList[2])

d_string = "".join(list(d))

if not Flag:
    d_string = d_string[::-1]    
print(d_string)
Problem p02833 (python)

Fixed submission:
N = int(input())

ans = 0

if N % 2 == 0:
    num = 5
    temp_N = N//2
    while num <= temp_N:
        ans += temp_N//num
        num *= 5

print(int(ans))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
 
def calcmore2(num,result,ans):
    while result%10 == 0 and result >= 10:
        result = result / 10
        ans += 1
    if num >= 2:return calcmore2(num-2, num-2, ans)
    else:return ans
 
A = int(input())
ans = 0
ans = calcmore2(A, 1,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
 sys.setrecursionlimit(10**7)

def calcmore2(num,result,ans):
    while result%10 == 0 and result >= 10:
        result = result / 10
        ans += 1
    if num >= 2:return calcmore2(num-2, num-2, ans)
    else:return ans
 
A = int(input())
ans = 0
ans = calcmore2(A, 1,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
def calcmore2(num,result,ans):
    while result%10 == 0 and result >= 10:
        result = result / 10
        ans += 1
    if num >= 2:return calcmore2(num-2, num-2, ans)
    else:return ans

A = int(input())
ans = 0
ans = calcmore2(A, 1,ans)
print(ans)
Problem p02726 (python)

Fixed submission:
n,x,y=map(int,input().split())
x-=1
y-=1
d=[10000 for i in range(n)]
ans=[0 for i in range(n)]
for i in range(n):
    for j in range(i,n):
        m=min(abs(i-j),abs(x-i)+abs(y-j)+1,abs(y-i)+abs(x-j)+1)
        ans[m]+=1

for i in range(1,n):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n,x,y=map(int,input().split())
x-=1
y-=1
ans=[0 for i in range(n)]
for ni in range(n):
    d=[100000 for i in range(n)]
    q=[]
    q.append(ni)
    d[ni]=0
    while q:
        p=q.pop()
        if(p>0 and d[p-1]>d[p]+1):
            q.append(p-1)
            d[p-1]=d[p]+1
        if(p<n-1 and d[p+1]>d[p]+1):
            q.append(p+1)
            d[p+1]=d[p]+1

        if(p==x and d[y]>d[x]+1):
            q.append(y)
            d[y]=d[x]+1
        if(p==y and d[x]>d[y]+1):
            q.append(x)
            d[x]=d[y]+1
        break

    for i in range(n):ans[d[i]]+=1
for i in range(1,n):print(ans[i]//2)
Problem p02726 (python)

Fixed submission:
n, x, y = map(int, input().split())
result = [0] * n
for i in range(1,n):
    for j in range(i+1, n+1):
        result[min([(j - i), (abs(i - x) + 1 + abs(j - y))])] += 1

for i in range(1,n):
    print(result[i])

Buggy submission (verdict: Runtime Error):
n, x, y = map(int, input().split())
x = x-1
y = y-1

result = [0] * n
for i in range(n):
    for j in range(i, n, 1):
        if i == j:
            continue
        minij = min([(j - i - 1), ((x - i + 1) + (y - j) - 1)])
        result[minij] += 1
for i in range(n-1):
    print(result[i])
Problem p02759 (python)

Fixed submission:
n = int(input())
print(int((n+1)/2))

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

fail = False
result = {}
for i in range(0, m):
    s, c = map(int, input().split())
    key = n-s
    if key in result and result[key] != c:
        fail = True
        break
    result[key] = c

if not(n-1 in result) or result[n-1] == 0:
   fail = True

if fail:
    print(-1)
else:
    res = 0
    for i in range(0, n):
        if i in result:
            res += 10 ** i * result[i]
    print(res)
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)
Problem p02629 (python)

Fixed submission:
n = int(input())
ans = ''
check = 'abcdefghijklmnopqrstuvwxyz'

while n != 0:
    n -= 1
    ans += check[n%26]
    n = n//26

print(ans[::-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = ['']

quo = n
rem = 0

while True:
    rem = quo%26
    quo = quo//26
    if rem == 0:
        ans.insert(0, 'z')
        if quo < 2:
            break
    else:
    
    if quo == 0:
        break

print(*ans, sep="")
Problem p02689 (python)

Fixed submission:
n, m = map(int, input().split())
h = [int(i) for i in input().split()]
obs = [True]*n
ab = []

for i in range(m):
    ab.append(input().split())

for j in range(len(ab)):
    if h[int(ab[j][0]) - 1] > h[int(ab[j][1]) - 1]:
        obs[int(ab[j][1]) - 1] = False

    elif h[int(ab[j][1]) - 1] > h[int(ab[j][0]) - 1]:
        obs[int(ab[j][0]) - 1] = False

    elif h[int(ab[j][0]) - 1] == h[int(ab[j][1]) - 1]:
        obs[int(ab[j][0]) - 1] = False
        obs[int(ab[j][1]) - 1] = False

print(obs.count(True))

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

tmp = [1] * n

ab = [map(int, input().split()) for _ in range(M)]
a, b = [list(i) for i in zip(*ab)]

for i in range(m):
    if h[a[i] - 1] > h[b[i] - 1]:
        tmp[b[i] - 1] = 0
    elif h[a[i] - 1] < h[b[i] - 1]:
        tmp[a[i] - 1] = 0
    else:
        tmp[a[i] - 1] = 0
        tmp[b[i] - 1] = 0

print(sum(tmp))
Problem p02711 (python)

Fixed submission:
n = input()

if '7' in n:
  print('Yes')
else:
  print('No')

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

if n.index('7'):
  print('Yes')
else:
  print('No')
Problem p02831 (python)

Fixed submission:
from fractions import gcd

def lcm(a, b):
    res = a*b / gcd(a, b)
    return res

a, b = map(int, input().split())
ans = int(lcm(a, b))
print(ans)

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

def lcm(a, b):
    res = a*b / gcd(a, b)
    return res

a, b = map(int, input().split())
ans = int(lcm(a, b))
print(ans)

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

def lcm(a, b):
    return a*b / gcd(a, b)

a, b = map(int, input().split())
ans = int(lcm(a, b))
print(ans)
Problem p02699 (python)

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

Buggy submission (verdict: Runtime Error):
s,w=map(int.input().split())
print("unsafe" if w>=s else "safe")
Problem p02627 (python)

Fixed submission:
s = input()
if s.isupper():
    print("A")
else:
    print("a")

Buggy submission (verdict: Runtime Error):
s = input()
if s.isuper():
    print("A")
else:
    print("a")
Problem p02676 (python)

Fixed submission:
K = input()
S = input()
K = int(K)
if len(S) <= K:
    print(S)
else:
    a = S[:K] + "..."
    print(a)

Buggy submission (verdict: Runtime Error):
K = input()
S = input()
if len(S) < K:
    print(S)
else:
    print("S[:K]" + "...")
Problem p02897 (python)

Fixed submission:
N = int(input())
K = int(N / 2) + N % 2
print(K / N)

Buggy submission (verdict: Runtime Error):
import numpy as np
def so(n):
    for i in range(3, int(np.sqrt(n)) + 1, 2):
        if n % i == 0:
            return False
    return True
A, B = map(int, input().split())
M = np.min([A, B])
n = 1
if (A % 2 == 0) and (B % 2 == 0):
    n = 2
for i in range(3, M, 2):
    if so(i):
        if (A % i == 0) and (B % i == 0):
            n = n + 1
print(n)
Problem p03041 (python)

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

S[K-1] = S[K-1].lower()

print("".join(S))

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

S[K-1] = S[K-1].lower()

print("".join(S)
Problem p02831 (python)

Fixed submission:
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

a, b = map(int, input().split())
print(lcm(a,b))

Buggy submission (verdict: Runtime Error):
from math import gcd
a, b = map(int, input().split())
print(gcd(a,b))
Problem p02891 (python)

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

if len(set(S)) == 1:
    print(n * K // 2)
    exit()

SS = S[:] + S[:]
S = list(S)
SS = list(SS)
ans0 = 0
ans1 = 0

c = 0
cnt = 1
for i in range(1, n):
    if S[i - 1] == S[i]:
        cnt += 1
        if i == n-1:
            c += cnt // 2
    else:
        if cnt >= 2:
            c += cnt // 2
        cnt = 1
ans0 = c
c = 0
cnt = 1
m = len(SS)
for i in range(1, m):
    if SS[i - 1] == SS[i]:
        cnt += 1
        if i == m - 1:
            c += cnt // 2
    else:
        if cnt >= 2:
            c += cnt // 2
        cnt = 1

ans1 = c


num = ans1 - ans0
print(ans0 + (K-1) * num)

Buggy submission (verdict: Runtime Error):
print(a)
Problem p03107 (python)

Fixed submission:
S=list(input())
ans=0

print(len(S)-abs(S.count('0')-S.count('1')))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s = input()
S = [int(s[i]) for i in range(len(s))]
# print(S)
count = 0
before = 0
while 1:
    #print("S:", S)
    is_continue = False
    # print(len(S))
    #deleted = False
    for i in range(max([before, 0]), len(S) - 1):
        #print(before, i)
        #print(S[i], S[i + 1])
        # print(S)
        if S[i] != S[i + 1]:
            # print(count)
            del S[i]
            del S[i]
            count += 2
            is_continue = True
            before = i - 2
            #deleted = True
            break
    if not is_continue:
        break
print(count)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s = input()
n = len(s)
a = []
i = 0
ct = 0
for i in range(n):
    a.append(int(s[i]))
i = -1

while ct < 100000000000:
    n = len(a)
    i += 1
    if i >= n - 1: break
    if a[i] == 0 and a[i + 1] == 1:
        a.pop(i)
        a.pop(i)
        ct += 1
        i -= 2
        if i <= 1: i = -1
        continue
    elif a[i] == 1 and a[i + 1] == 0:
        a.pop(i)
        a.pop(i)
        ct += 1
        i -= 2
        if i <= 1: i = -1

print(ct * 2)
Problem p03108 (python)

Fixed submission:
n, m = map(int, input().split())
par = [-1] * n  # 親だった場合は-(その集合のサイズ)


# xがどのグループに属しているか調べる
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return find(par[x])


# 自分のいるグループの数
def size(x):
    return -par[find(x)]


# xとyの属する集合を併合
def unite(x, y):
    # 根を探す
    x, y = find(x), find(y)

    # 根が一緒
    if x == y:
        return

    # 大きい方に小さい方をくっつける
    if size(x) < size(y):
        x, y = y, x

    # xのサイズを更新
    par[x] += par[y]
    # yの親をxにする
    par[y] = x


# 同じ集合に属するか判定
def same(x, y):
    return find(x) == find(y)


bridges = [list(map(int, input().split())) for _ in range(m)]
bridges.reverse()
huben = n * (n - 1) // 2
ans = []
for i in range(m):
    ans.append(huben)
    a, b = bridges[i]
    a, b = a - 1, b - 1
    if same(a, b):
        continue
    else:
        huben -= size(a) * size(b)
        unite(a, b)
ans = ans[::-1]
for i in range(m):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
par = [-1] * n  # 親だった場合は-(その集合のサイズ)


# xがどのグループに属しているか調べる
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return find(par[x])


# 自分のいるグループの数
def size(x):
    return -par[find(x)]


# xとyの属する集合を併合
def unite(x, y):
    # 根を探す
    x, y = find(x), find(y)

    # 根が一緒
    if x == y:
        return

    # 大きい方に小さい方をくっつける
    if size(x) < size(y):
        x, y = y, x

    # xのサイズを更新
    par[x] += par[y]
    # yの親をxにする
    par[y] = x


# 同じ集合に属するか判定
def same(x, y):
    return find(x) == find(y)


bridges = [list(map(int, input().split())) for _ in range(m)]
bridges.reverse()
huben = n * (n - 1) // 2
ans = []

for i in range(m):
    ans.append(huben)
    a, b = bridges[i]
    a, b = a - 1, b - 1
    if same(a, b):
        continue
    else:
        huben -= size(a) * size(b)
        unite(a, b)
ans = ans.reverse()
for i in range(m):
    print(ans[i])