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

Fixed submission:
import heapq
n,m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)
 
for i in range(m):
	target = heapq.heappop(a)
	heapq.heappush(a, (-1)*(-target//2))
	
print(-sum(a))

Buggy submission (verdict: Runtime Error):
import math

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

def waribiki(s,maisu):
    return math.floor(s/(2**maisu))

for _ in range(m):
    a.append(waribiki(max(A)),1))
    a.remove(max(a))

print(sum(a))
Problem p02990 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def solve(N: int, K: int):
    for i in range(1,K+1):
        split_pattern = combinations_count(K-1,i-1)
        if N-K >= i-1:
            print((split_pattern*combinations_count(N-K+1,i))%MOD)
        else:
            print(0)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def solve(N: int, K: int):
    for i in range(1,K+1):
        split_pattern = combinations_count(K-1,i-1)
        print((split_pattern*combinations_count(N-K+1,i))%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def solve(N: int, K: int):
    re = N-K

    for i in range(1,K+1):
        split_pattern = combinations_count(K-1,i-1)
        print(split_pattern*combinations_count(re+1,i)%MOD)
        
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def solve(N: int, K: int):
    re = N-K

    for i in range(1,K+1):
        split_pattern = combinations_count(K-1,i-1)
        print(math.factorial(split_pattern)*combinations_count(re+1,i)%MOD)
        
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

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

Fixed submission:
import sys
n, m = map(int,input().split())

if n >= m:
  print(0)
  sys.exit()
  
x = list(map(int,input().split()))
x.sort()
between = [x[i+1]-x[i] for i in range(len(x)-1)]
between.sort(reverse = True)
print(sum(between[n-1:]))

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

if n >= m:
  print(0)
  sys.exit()
  
x = sorted(list(map(int,input().split())))
print(sum([x[i+1]-x[i] for i in range(len(x)-1)].sort(reverse = True)[n-1:]))
Problem p03252 (python)

Fixed submission:
from collections import Counter
s=sorted(Counter(input()).values())
t=sorted(Counter(input()).values())
print("Yes" if t==s else "No")

Buggy submission (verdict: Runtime Error):
s = input()
target = input()
for index in xrange(len(s)):
    ss = s[index]
    tt = target[index]
	
    if s[:index] != target[:index]:
        break
    if ss == tt:
        continue
    else: #ssとttを相互変換する
        s = s.replace(ss,"0").replace(tt,ss).replace("0",tt)

if s == target:
    print("Yes")
else:
    print("No")
Problem p03329 (python)

Fixed submission:
N=int(input())
ans=N
for i in range(N+1): 
    cnt=0
    t=i
    while t>0:
        cnt+=t%6
        t//=6
    s=N-i
    while s>0:
        cnt+=s%9
        s//=9
    ans=min(ans,cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
n= int(input())
ninesix = [9**i for i in range(1,6)]+[6**i for i in range(1,7)]
ninesix.sort(reverse=True)

def coin(ns,max_res):
  if max_res < 6:
    return max_res
  count = 0
  remainder = max_res//ns[0]
  c = 1000000000
  if remainder > 0:
    for i in range(1,remainder+1):
      nnss = ns[1:]
      c = min(coin(nnss,max_res-ns[0]*i),c)+i
    count += c
    return count
  else:
    return coin(ns[1:],max_res)
  return count
   
print(coin(ninesix,n))
Problem p03317 (python)

Fixed submission:
n , k = map(int, input().split())
if k == 2:
    print(n-1)
elif k == n-1:
    print(2)
elif (n-k)%(k-1) == 0:
    print((n-k)//(k-1) +1)
else:
    print((n-k)//(k-1) + 2)

Buggy submission (verdict: Runtime Error):
n , k = map(int, input().split())
if k == 2:
    print(n-1)
elif k == n-1:
    print(2)
elif n%2 != 0 k%2 == 0 and (n-k)%(k-1) != 0:
  	print(n//(k-1) + 1)
else:
    print(n//(k-1))
Problem p03295 (python)

Fixed submission:
n, m = map(int, input().split())
p = []
for i in range(m):
  r, l = map(int, input().split())
  p.append((r, l))

p.sort()
mr = 0
c = 0
for l, r in p:
  if l >= mr:
    mr = r
    c += 1
    continue
  mr = min(mr, r)

print(c)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
p = []
for i in range(n):
  r, l = map(int, input().split())
  p.append((r, l))

p.sort()
mr = 0
c = 0
for l, r in p:
  if l >= mr:
    mr = r
    continue
  c += 1
  mr = min(mr, r)

print(c)
Problem p03805 (python)

Fixed submission:
def search(node, searched, goal):
  if searched == goal:
    return 1
  v = 0
  for nei in edges[node]:
    if searched & (1 << nei):
      continue
    v += search(nei, searched | (1<<nei), goal)
    
  return v

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(m):
  a, b = map(lambda x: int(x) - 1, input().split())
  edges[a].append(b)
  edges[b].append(a)
print(search(0, 1, (1<<n) - 1))

Buggy submission (verdict: Runtime Error):
def search(node, searched, goal):
  if searched == goal:
    return 1
  v = 0
  for nei in edges[node]:
    if searched & (1 << nei):
      continue
    v += search(nei, searched | (1<<nei), goal)
    
  return v
n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(n):
  a, b = map(lambda x: int(x) - 1, input().split())
  edges[a].append(b)
  edges[b].append(a)
print(search(0, 1, (1<<n) - 1))
Problem p02831 (python)

Fixed submission:
from fractions import gcd
import sys
sys.setrecursionlimit(100000)

a, b = map(int, input().split())
gcd = gcd(a, b)
if gcd <= 0:
    print(0)
else:
    result = int(a*b / gcd)
    print(result)

Buggy submission (verdict: Runtime Error):
import math
import sys
sys.setrecursionlimit(100000)

a, b = map(int, input().split())
gcd = math.gcd(a, b)
if gcd <= 0:
    print(0)
else:
    result = int(a*b / gcd)
    print(result)

Buggy submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())
gcd = math.gcd(a, b)
if gcd == 0:
    print(0)
else:
    result = int(a*b / gcd)
    print(result)

Buggy submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())
result = int(a*b / math.gcd(a, b))
print(result)
Problem p02862 (python)

Fixed submission:
mod = 1000000007
import sys
sys.setrecursionlimit(1000000)
x, y = map(int, input().split())
a = ((2*x-y)//3)
b = ((2*y-x)//3)
if (x+y) % 3 != 0 or a < 0 or b < 0:
    print(0)
else:
    n = (a + b)%mod
    kaijo = [1, 1]
    for i in range(2, n+1):
        kaijo.append(i*kaijo[i-1]%mod)
    def mul(a, b):
        return ((a % mod) * (b % mod)) % mod
    def power(x, y):
        if y == 0:
            return 1
        elif y == 1:
            return x % mod
        elif y % 2 == 0:
            return power(x, y // 2) ** 2 % mod
        else:
            return power(x, y // 2) ** 2 * x % mod
    def div(a, b):
        return mul(a, power(b, mod - 2))
    n_a = div(kaijo[n], kaijo[a])
    ans = div(n_a, kaijo[n-a])
    print(ans)

Buggy submission (verdict: Runtime Error):
mod = 1000000007
import sys
sys.setrecursionlimit(1000000)
x, y = map(int, input().split())
if (x+y) % 3 != 0:
    print(0)
else:
    a = ((2*x-y)//3)%mod
    b = ((2*y-x)//3)%mod
    n = (a + b)%mod
    kaijo = [1, 1]
    for i in range(2, n+1):
        kaijo.append(i*kaijo[i-1]%mod)
    def mul(a, b):
        return ((a % mod) * (b % mod)) % mod
    def power(x, y):
        if y == 0:
            return 1
        elif y == 1:
            return x % mod
        elif y % 2 == 0:
            return power(x, y // 2) ** 2 % mod
        else:
            return power(x, y // 2) ** 2 * x % mod
    def div(a, b):
        return mul(a, power(b, mod - 2))
    n_a = div(kaijo[n], kaijo[a])
    ans = div(n_a, kaijo[n-a])
    print(ans)
Problem p03011 (python)

Fixed submission:
p,q,r = map(int, input().split())
print(min(p+q,q+r,r+p))

Buggy submission (verdict: Runtime Error):
import sys
n,m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))
fib = [1,1]
for i in range(n):
    fib.append((fib[i]+fib[i+1])%1000000007)
if m == 0:
	print(fib[n])
    sys.exit()
answer = fib[a[0]-1]
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        answer = 0
    else:
        answer = answer * fib[a[i+1]-a[i]-2] % 1000000007
answer = answer * fib[n-a[m-1]-1] % 1000000007
print(answer)
Problem p03013 (python)

Fixed submission:
import sys
n,m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))
fib = [1,1]
for i in range(n):
    fib.append((fib[i]+fib[i+1])%1000000007)
if m == 0:
    print(fib[n]%1000000007)
    sys.exit()
answer = fib[a[0]-1]
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        answer = 0
    else:
        answer = answer * fib[a[i+1]-a[i]-2] % 1000000007
answer = answer * fib[n-a[m-1]-1] % 1000000007
print(answer)

Buggy submission (verdict: Runtime Error):
import sys
n,m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))
fib = [1,1]
for i in range(n):
    fib.append((fib[i]+fib[i+1])%1000000007)
if m == 0:
	print(fib[n])
    sys.exit()
answer = fib[a[0]-1]
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        answer = 0
    else:
        answer = answer * fib[a[i+1]-a[i]-2] % 1000000007
answer = answer * fib[n-a[m-1]-1] % 1000000007
print(answer)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))
fib = [1,1]
for i in range(n):
    fib.append((fib[i]+fib[i+1])%1000000007)
answer = fib[a[0]-1]
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        answer = 0
    else:
        answer = answer * fib[a[i+1]-a[i]-2] % 1000000007
answer = answer * fib[n-a[m-1]-1] % 1000000007
print(answer)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))
fib = [1,1]
#n段登る場合の数がfib[n]になるようにする
for i in range(n):
    fib.append((fib[i]+fib[i+1])%1000000007)
answer = 1
answer *= fib[a[0]-1]
if m > 1:
    if a[0]+1 == a[1]:
        answer = 0
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        answer = 0
    answer = answer * fib[a[i+1]-a[i]-2] % 1000000007
answer = answer * fib[n - a[m-1] -1] % 1000000007
print(answer)

Buggy submission (verdict: Runtime Error):
import sys
n,m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))
fib = [1,1]
#n段登る場合の数がfib[n]になるようにする
for i in range(n):
    fib.append((fib[i]+fib[i+1])%1000000007)
answer = 1
answer *= fib[a[0]-1]
if m > 1:
    if a[0]+1 == a[1]:
        print(0)
        sys.exit()
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        print(0)
        sys.exit()
    answer = answer * fib[a[i+1]-a[i]-2] % 1000000007
answer = answer * fib[n - a[m-1] -1] % 1000000007
print(answer)
Problem p03038 (python)

Fixed submission:
n, m = map(int,input().split())
a = list(map(int,input().split()))
rewrite = []
for i in range(m):
    rewrite.append(list(map(int,input().split())))
rewrite.sort(key= lambda x : x[1], reverse=True)
a.sort()
k = 0
flag = 0
for i in range(m):
    for j in range(rewrite[i][0]):
        if rewrite[i][1] > a[k]:
            a[k] = rewrite[i][1]
            k += 1
            if k == n:
                flag = 1
                break
        else:
            flag = 1
            break
    if flag == 1:
        break
print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = list(map(int,input().split()))
rewrite = []
for i in range(m):
    rewrite.append(list(map(int,input().split())))
rewrite.sort(key= lambda x : x[1], reverse=True)
a.sort()
k = 0
flag = 0
for i in range(min(n,sum(rewrite[0]))):
    for j in range(rewrite[i][0]):
        if rewrite[i][1] > a[k]:
            a[k] = rewrite[i][1]
            k += 1
        else:
            flag = 1
            break
    if flag == 1:
        break
print(sum(a))
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
from sys import stdin
input = stdin.readline

n = int(input())
adjacency = [[] for i in range(n+1)] #adjacency[i]は頂点iと隣接する頂点のリスト
distance = {} # distance[(i,j)](i,jは隣接した頂点)は頂点i,jを結ぶ辺の長さ
for i in range(n-1):
    line = list(map(int, input().split()))
    adjacency[line[0]].append(line[1])
    adjacency[line[1]].append(line[0])
    distance[(line[0], line[1])] = line[2]
    distance[(line[1], line[0])] = line[2]
q, k = map(int, input().split())
x = []
y = []
for i in range(q):
    line = list(map(int, input().split()))
    x.append(line[0])
    y.append(line[1])

k_distance = [-1 for i in range(n+1)] # k_distance[i]は頂点i,kの距離
k_distance[k] = 0
reached = {k}
def dfs(v, d): # 現在いる頂点vと頂点v,k間の距離dを入力すると頂点vと隣接する未到達の頂点のk_distanceを計算してappendする
    for neighbor in adjacency[v]:
        if not neighbor in reached:
            reached.add(neighbor)
            k_distance[neighbor] = d + distance[(v, neighbor)]
            dfs(neighbor, k_distance[neighbor])
    return
dfs(k, 0)
for i in range(q):
    print(k_distance[x[i]] + k_distance[y[i]])

Buggy submission (verdict: Runtime Error):
n = int(input())
adjacency = [[] for i in range(n+1)] #adjacency[i]は頂点iと隣接する頂点のリスト
distance = {} # distance[(i,j)](i,jは隣接した頂点)は頂点i,jを結ぶ辺の長さ
for i in range(n-1):
    line = list(map(int, input().split()))
    adjacency[line[0]].append(line[1])
    adjacency[line[1]].append(line[0])
    distance[(line[0], line[1])] = line[2]
    distance[(line[1], line[0])] = line[2]
q, k = map(int, input().split())
x = []
y = []
for i in range(q):
    line = list(map(int, input().split()))
    x.append(line[0])
    y.append(line[1])

k_distance = [-1 for i in range(n+1)] # k_distance[i]は頂点i,kの距離
k_distance[k] = 0
reached = {k}
def dfs(v, d): # 現在いる頂点vと頂点v,k間の距離dを入力すると頂点vと隣接する未到達の頂点のk_distanceを計算してappendする
    for neighbor in adjacency[v]:
        if not neighbor in reached:
            reached.add(neighbor)
            k_distance[neighbor] = d + distance[(v, neighbor)]
            dfs(neighbor, k_distance[neighbor])
    return
dfs(k, 0)
for i in range(q):
    print(k_distance[x[i]] + k_distance[y[i]])
Problem p02989 (python)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
 
c_idx = n // 2 - 1
l.sort()
print(l[c_idx + 1] - l[c_idx])

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

c_idx = n / 2 - 1
l.sort()
print(l[c_idx + 1] - l[c_idx])
Problem p02990 (python)

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


from functools import reduce
from operator import mul

def cmb(n, r):
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    # なんでn + 1じゃないのか？
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

TEISU = 10 ** 9 + 7

for i in range(k):
    print(int(cmb(n - k + 1, i + 1) * cmb(k - 1, i)) % TEISU)

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


from functools import reduce
from operator import mul

def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    # なんでn + 1じゃないのか？
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

TEISU = 10 ** 9 + 7

for i in range(k):
    print(int(cmb(n - k + 1, i + 1) * cmb(k - 1, i)) % TEISU)

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


from functools import reduce
from operator import mul

def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    # なんでn + 1じゃないのか？
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

TEISU = 10 ** 9 + 7

for i in range(k):
    print(int(cmb(n - k + 1, i + 1) * cmb(k - 1, i)) % TEISU)

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

def kaijou(a):
    ret = 1
    for i in range(a):
        ret *= i + 1
    return ret


def comb(n, k):
    if k == 0:
        return 1

    return kaijou(n) / (kaijou(k) * kaijou(n - k))

TEISU = 10 ** 9 + 7

for i in range(k):
    print(int(comb(n - k + 1, i + 1) * comb(k - 1, i)) % TEISU)
Problem p02688 (python)

Fixed submission:
N, K = map(int, input().split())
snuke = [0] * N
for n in range(K):
    snack = int(input())
    d_snuke = map(int, input().split())
    for d in d_snuke:
        snuke[d-1] = snack
c = 0
for n in range(N):
    if snuke[n] == 0:
        c += 1
print(c)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
snuke = [0] * N
for n in range(N-1):
    snack = int(input())
    d_snuke = map(int, input().split())
    for d in d_snuke:
        snuke[d-1] = snack
c = 0
for n in range(N-1):
    if snuke[n] == 0:
        c += 1
print(c)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
snuke = [0] * N
for n in range(N-1):
    snack = int(input())
    d_snuke = map(int, input().split())
    for d in d_snuke:
        snuke[d-1] = snack
c = 0
for n in range(N):
    if snuke[n] == 0:
        c += 1
print(c)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
snuke = [0] * N
for n in range(N-1):
    snack = int(input())
    A = str(input())
    snuke[snack-1] = 1
c = 0
for n in range(N):
    if snuke[n] == 0:
        c += 1
print(c)
Problem p02831 (python)

Fixed submission:
import fractions
A, B = map(int, input().split(' '))
gcd = fractions.gcd(A, B)
print((A * B) // gcd)

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().split(' '))
print(int((A * B) / math.gcd(A, B)))

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().split(' '))
print((A * B) // math.gcd(A, B))
Problem p02835 (python)

Fixed submission:
 
A, B, C = map(int, input().split())
val = A + B + C
if val >= 22:
    print('bust')
else:
    print('win')

Buggy submission (verdict: Runtime Error):
 A, B, C = map(int, input().split())

if A + B + C >= 22:
    print('bust')
else:
    print('win')
Problem p02891 (python)

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

flag = False

itr = 0
cnt = 1
len_cnt = []
for x in S :
  if itr == 0 :
    pre = x
    itr += 1
    continue
  now = x
  if pre == now :
    cnt += 1
    itr += 1
    if itr == len(S) :
      len_cnt.append(cnt)
    continue
  if pre != now :
    len_cnt.append(cnt)
    itr+=1
    if itr == len(S) and cnt == 1 :
      len_cnt.append(cnt)
    cnt = 1
    pre = x
    continue

if sum(len_cnt) != len(S) :
  len_cnt.append(1)

if len(len_cnt) == 1 :
  print(int(len_cnt[0] * K / 2))
  exit()

ans = 0
for x in len_cnt :
  if x == 1 :
    continue
  else :
    ans += int(x / 2)

# if S[0] == S[-1] and len_cnt[-1] > 1 and len_cnt[-1] % 2 == 1 and K > 1:
#   ans += 1
if S[0] == S[-1] and len_cnt[-1] % 2 == 1 and len_cnt[0] % 2 == 1 :
  ans += 1
  flag = True

ANS = K * ans
# print (ANS, len_cnt)
if flag :
  ANS -= 1

# if S[0] ==S[-1] and len_cnt[-1] % 2 == 1 and len_cnt[-1] != 1 :
#   ANS -= 1
print(ANS)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

itr = 0
cnt = 1
len_cnt = []
for x in S :
  if itr == 0 :
    pre = x
    itr += 1
    continue
  now = x
  if pre == now :
    cnt += 1
    itr += 1
    if itr == len(S) :
      len_cnt.append(cnt)
    continue
  if pre != now :
    len_cnt.append(cnt)
    itr+=1
    if itr == len(S) and cnt == 1 :
      len_cnt.append(cnt)
    cnt = 1
    pre = x
    continue

ans = 0
for x in len_cnt :
  if x == 1 :
    continue
  else :
    ans += int(x / 2)

if S[0] == S[-1] and len_cnt[-1] > 1 and len_cnt[-1] % 2 == 1 and K > 1:
  ans += 1

ANS = K * ans
if len_cnt[-1] % 2 == 1 and len_cnt[-1] != 1 :
  ANS -= 1
print(ANS)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

itr = 0
cnt = 1
len_cnt = []
for x in S :
  if itr == 0 :
    pre = x
    itr += 1
    continue
  now = x
  if pre == now :
    cnt += 1
    itr += 1
    if itr == len(S) :
      len_cnt.append(cnt)
    continue
  if pre != now :
    len_cnt.append(cnt)
    itr+=1
    if itr == len(S) and cnt == 1 :
      len_cnt.append(cnt)
    cnt = 1
    pre = x
    continue

ans = 0
for x in len_cnt :
  if x == 1 :
    continue
  else :
    ans += int(x / 2)

if S[0] == S[-1] and len_cnt[-1] > 1 and len_cnt[-1] % 2 == 1 and K > 1:
  ans += 1

ANS = K * ans
if len_cnt[-1] % 2 == 1 :
  ANS -= 1
print(ANS)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

itr = 0
cnt = 1
len_cnt = []
for x in S :
  if itr == 0 :
    pre = x
    itr += 1
    continue
  now = x
  if pre == now :
    cnt += 1
    itr += 1
    if itr == len(S) :
      len_cnt.append(cnt)
    continue
  if pre != now :
    len_cnt.append(cnt)
    itr+=1
    if itr == len(S) and cnt == 1 :
      len_cnt.append(cnt)
    cnt = 1
    pre = x
    continue

ans = 0
for x in len_cnt :
  if x == 1 :
    continue
  else :
    ans += int(x / 2)

if S[0] == S[-1] and len_cnt[-1] > 1 and len_cnt[-1] % 2 == 1 :
  ans += 1

print(K * ans)
Problem p02695 (python)

Fixed submission:
#提出用
n,m,q = list(map(int, input().split()))

a=[]
b=[]
c=[]
d=[]

for i in range(q):
    aa,bb,cc,dd = list(map(int, input().split()))
    a.append(aa)
    b.append(bb)
    c.append(cc)
    d.append(dd)

ans = 0

def dfs(la):
    global ans
    if len(la)==n+1:
        sum_d=0
        #print(la)
        #print(ans)
        for i in range(q):
            if la[b[i]] - la[a[i]] == c[i]:
                sum_d += d[i]
        if sum_d > ans:
            ans = sum_d
        return
    
    la.append(la[-1])
    while(la[-1]<=m):
        dfs(la.copy())
        la[-1] += 1
        

dfs([1])
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,q,*abcd=list(map(int, Input.split()))
a=[]
b=[]
c=[]
d=[]

ans = 0

for i in range(q):
    a.append(abcd.pop(0))
    b.append(abcd.pop(0))
    c.append(abcd.pop(0))
    d.append(abcd.pop(0))
    
def dfs(la):
    global ans
    if len(la)==n+1:
        sum_d=0
        #print(la)
        #print(ans)
        for i in range(q):
            if la[b[i]] - la[a[i]] == c[i]:
                sum_d += d[i]
        if sum_d > ans:
            ans = sum_d
        return
    
    la.append(la[-1])
    while(la[-1]<=m):
        dfs(la.copy())
        la[-1] += 1
        

dfs([1])
print(ans)