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

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

N,M=map(int, input().split())
B=[tuple(map(int, input().split())) for _ in range(M)]

P=list(range(N+1))
C=[1 for _ in range(N+1)]
C[0] = 0

def root(x):
    if P[x]==x: return x
    P[x] = root(P[x])
    return P[x]

def unite(a,b):
    ra = root(a)
    rb = root(b)
    C[ra] += C[rb]
    C[rb] = 0
    P[rb] = ra

def same(a,b):
    return root(a) == root(b)

def count(x):
    return C[root(x)]

ans=[0]*(M+1)
ans[M] = N * (N-1)

for i in range(M-1,-1,-1):
    a,b = B[i]
    if same(a,b):
        ans[i] = ans[i+1]
        continue
    ans[i] = ans[i+1] - count(a) * count(b)
    unite(a,b)

for i in range(1,M+1):
    print(ans[i] - ans[0])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N,M=map(int, input().split())
B=[tuple(map(int, input().split())) for _ in range(M)]

P=list(range(N+1))
C=[1 for _ in range(N+1)]
C[0] = 0

def root(x):
    if P[x]==x: return x
    P[x] = root(P[x])
    return P[x]

def unite(a,b):
    ra = root(a)
    rb = root(b)
    C[ra] += C[rb]
    C[rb] = 0
    P[rb] = ra

def same(a,b):
    return root(a) == root(b)

def count(x):
    return C[root(x)]

ans=[0]*(M+1)
ans[M] = N * (N-1)

for i in range(M-1,-1,-1):
    a,b = B[i]
    if same(a,b):
        ans[i] = ans[i+1]
        continue
    ans[i] = ans[i+1] - count(a) * count(b)
    unite(a,b)

for i in range(1,M+1):
    print(ans[i] - ans[0])
Problem p02580 (python)

Fixed submission:
from collections import defaultdict
h, w, m = map(int, input().split())
targets = defaultdict(int)
targets_count_yoko = defaultdict(int)
targets_count_tate = defaultdict(int)
for _ in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    targets_count_yoko[x] += 1
    targets_count_tate[y] += 1
    targets[(y, x)] = -1

max_row = max(targets_count_yoko.values())
max_line = max(targets_count_tate.values())
y_idx = defaultdict(bool)
x_idx = defaultdict(bool)
max_count_x = 0
max_count_y = 0
for i in range(w):
    if targets_count_yoko[i] == max_row:
        x_idx[i] = True
        max_count_x += 1
for i in range(h):
    if targets_count_tate[i] == max_line:
        y_idx[i] = True
        max_count_y += 1


ans = max_line + max_row
kumi = max_count_x*max_count_y
for key_y, key_x in targets.keys():
    if y_idx[key_y] and x_idx[key_x]:
        kumi -= 1
    if kumi == 0:
        break

if kumi == 0:
    print(ans-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
h, w, m = map(int, input().split())
targets_map = [[0]*w for _ in range(h)]
targets_count_tate = [0]*w
targets_count_yoko = [0]*h
for _ in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    targets_count_tate[x] += 1
    targets_count_yoko[y] += 1
    targets_map[y][x] = -1

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, targets_count_tate[x] + targets_count_yoko[y] + targets_map[y][x])

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
h, w, m = map(int, input().split())
targets_map = [[0]*w for _ in range(h)]
targets_count_tate = [0]*w
targets_count_yoko = [0]*h
for _ in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    targets_count_tate[x] += 1
    targets_count_yoko[y] += 1
    targets_map[y][x] = 1


max_line = max(targets_count_yoko)
max_row = max(targets_count_tate)
yoko_idx = []
tate_idx = []
for i in range(h):
    if targets_count_yoko[i] == max_line:
        yoko_idx.append(i)
for i in range(w):
    if targets_count_tate[i] == max_row:
        tate_idx.append(i)

ans = max_line + max_row - 1
flag = True
for y in yoko_idx:
    for x in tate_idx:
        if targets_map[y][x] != 1:
            flag = False
            break
    else:
        continue
    break

if flag:
    print(ans)
else:
    print(ans+1)
Problem p02689 (python)

Fixed submission:
from collections import deque
n, m = map(int, input().split())
h = list(map(int, input().split()))
edges = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
check = [0]*n
q = deque()
for i in range(n):
    q.append(i)
ans = 0
while q:
    node = q.pop()
    if check[node] != 0:
        continue
    else:
        check[node] = 1
        count = 0
        for v in edges[node]:
            q.append(v)
            if h[node] > h[v]:
                check[v] = 1
                count += 1
            elif h[node] == h[v]:
                check[v] = 1
        if count == len(edges[node]):
            ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
h = list(map(int, input().split()))
edges = [[] for i in range(m+1)]
for i in range(m):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
#print(edges)
check = [0]*n
q = deque()
for i in range(n):
    q.append(i)
ans = 0
while q:
    node = q.popleft()
    if check[node] != 0:
        continue
    else:
        check[node] = 1
        count = 0
        for v in edges[node]:
            q.append(v)
            if h[node] >= h[v]:
                check[v] = 1
                count += 1
        if count == len(edges[node]):
            ans += 1


print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
h = list(map(int, input().split()))
edges = [[] for i in range(m+1)]
for i in range(m):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
#print(edges)
check = [0]*n
q = deque()
for i in range(n):
    q.append(i)
ans = 0
while q:
    node = q.popleft()
    if check[node] != 0:
        continue
    else:
        check[node] = 1
        count = 0
        for v in edges[node]:
            q.append(v)
            if h[node] > h[v]:
                check[v] = 1
                count += 1
        if count == len(edges[node]):
            ans += 1


print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
h = list(map(int, input().split()))
edges = [[] for i in range(m+1)]
for i in range(m):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
#print(edges)
check = [[0]*n for _ in range(n)]
count = 0
for i in range(n):
    for node in edges[i]:
        if h[i] > h[node]:
            continue
        else:
            break
    else:
        count += 1
print(count)
Problem p02711 (python)

Fixed submission:
n = str(input())
flag = True
for i in range(3):
    if n[i] == "7":
        print("Yes")
        flag = False
        break
if flag:
    print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
s = str(input())
count = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if i < j < k:
                a = (s[i], s[j], s[k])
                #print(a)
                a_set = set(a)
                #print(a_set)
                if len(a_set) == 3 and (j - i) != (k - j):
                    count += 1
print(count)
Problem p02753 (python)

Fixed submission:
s = input()
if s[0] == s[1] == s[2]:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
s = input()
if s[1] == s[2] == s[3]:
    print("No")
else:
    print("Yes")
Problem p02759 (python)

Fixed submission:
n = int(input())
if n % 2 == 0:
    p = int(n / 2)
else:
    p = int(n/2) + 1
print(p)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]

flag = True

if n == 1 and m == 0:
    print(0)
elif n == 1 and m != 0:
    if len(set(sc)) != 1:
        print(-1)
    else:
        print(sc[0][1])
        
        
elif n > 1 and m == 0:
    print(10**(n-1))
    
elif n > 1 and m != 0:
    for i in range(10**(n-1), 10**n):
        i_str = str(i)
        i_list = list(i_str)
        for item in set(sc):
            if i_list[item[0]-1] != str(item[1]):
                break
        else:
            print(i)
            flag = False
            break
    if flag:
        print(-1)
Problem p02762 (python)

Fixed submission:
import sys
from collections import Counter
input = lambda: sys.stdin.readline().rstrip()
n, m, k = map(int, input().split())

fgraph = [list() for _ in range(n)]  # 隣接行列のリスト版
bgraph = [list() for _ in range(n)]  # brock関係のグラフ
cgraph = [list() for _ in range(n)]  # 友達候補のグラフ
sys.setrecursionlimit(10**9)
rks = [None]*n


def dfs(graph, s, r):  # 深さ優先探索
    if rks[s] is None:
        rks[s] = r
    for j in range(len(graph[s])):
        if rks[graph[s][j] - 1] is not None:
            continue
        dfs(graph, graph[s][j]-1, r)


for i in range(m):
    a, b = map(int, input().split())
    fgraph[a-1].append(b)
    fgraph[b-1].append(a)

 # fgraphの連結成分を調べる
c = -1
for i in range(n):
    if rks[i] is None:
        c += 1
        dfs(fgraph, i, c)  # iから始めるDFS。ｃが同じなら同じ連結成分にいる

for i in range(k):
    c, d = map(int, input().split())
    if rks[c-1] == rks[d-1]:  # 同一連結成分の中でのブロック関係のみ注目
        bgraph[c-1].append(d)
        bgraph[d-1].append(c)

counter = Counter(rks)
for i in range(n):
    print(counter[rks[i]] - len(fgraph[i]) - len(bgraph[i]) - 1)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n, m, k = map(int, input().split())

fgraph = [list() for _ in range(n)]  # 隣接行列のリスト版
bgraph = [list() for _ in range(n)]  # brock関係のグラフ
cgraph = [list() for _ in range(n)]  # 友達候補のグラフ
rks = [None]*n


def dfs(graph, s, r):  # 深さ優先探索
    if rks[s] is None:
        rks[s] = r
    for j in range(len(graph[s])):
        if rks[graph[s][j] - 1] is not None:
            continue
        dfs(graph, graph[s][j]-1, r)


for i in range(m):
    a, b = map(int, input().split())
    fgraph[a-1].append(b)
    fgraph[b-1].append(a)

 # fgraphの連結成分を調べる
c = -1
for i in range(n):
    if rks[i] is None:
        c += 1
        dfs(fgraph, i, c)  # iから始めるDFS。ｃが同じなら同じ連結成分にいる

for i in range(k):
    c, d = map(int, input().split())
    if rks[c-1] == rks[d-1]:  # 同一連結成分の中でのブロック関係のみ注目
        bgraph[c-1].append(d)
        bgraph[d-1].append(c)

counter = Counter(rks)
for i in range(n):
    print(counter[rks[i]] - len(fgraph[i]) - len(bgraph[i]) - 1)
Problem p02785 (python)

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

h = sorted(h)

h.reverse()

print(sum(h[k:]))

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

h.sort()
h.reverse()

print(sum(h[k:]))
Problem p02829 (python)

Fixed submission:
a = int(input())
b = int(input())
for i in range(1, 4):
    if i != a and i != b:
        print(i)

Buggy submission (verdict: Runtime Error):
import fractions
a, b = map(int, input().split())
ans = (a * b) // fractions.gcd(a, b)
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
a, b = map(int, input().split())
ans = (a * b) // fractions.gcd(a, b)
print(ans)
Problem p02831 (python)

Fixed submission:
import fractions
a, b = map(int, input().split())
ans = (a * b) // fractions.gcd(a, b)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
ans = (a * b) // math.gcd(a, b)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
ans = (a * b) // math.gcd(a, b)
print(ans)

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

Fixed submission:
a, b, c = map(int, input().split())
if a + b + c >= 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 p02951 (python)

Fixed submission:
a, b, c = map(int, input().split())
d = a-b
if c <= d:
    print(0)
else:
    print(c-d)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
d = a-b
if c <= d:
    print(0)
elif:
    print(c-d)
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
a = [0]*m
for i in range(m):
    a[i] = int(input())
mod = 10**9 + 7

dp = [-1]*(n+1)
dp[0] = 1
dp[1] = 1
for i in range(m):
    dp[a[i]] = 0
#print(dp)
for i in range(n-1):
    if dp[i+2] == -1:
        dp[i+2] = (dp[i+1] + dp[i]) % mod
    elif dp[i+2] == 0:
        dp[i+2] = 0
#print(dp)
print(dp[n] % mod)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [0]*m
for i in range(m):
    a[i] = int(input())
mod = 10**9 + 7

dp = [0]*(n+1)
dp[0] = 1
if a[0] != 1:
    dp[1] = 1
else:
    dp[1] = 0
for i in range(1, m):
    dp[a[i]] = -1
for i in range(n-1):
    if dp[i+2] == -1:
        dp[i+2] = 0
    elif dp[i+2] == 0:
        dp[i+2] = (dp[i+1] + dp[i]) % mod
print(dp[n] % mod)
Problem p03127 (python)

Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
flag = True
b = gcd(a[0], a[1])
for i in range(2, n):
    b = gcd(a[i], b)
print(b)

Buggy submission (verdict: Runtime Error):
from fractions import math
n = int(input())
a = list(map(int, input().split()))
min_mod = min(a)
flag = True
b = math.gcd(a[0], a[1])
for i in range(2, n):
    b = math.gcd(a[i], b)
print(b)
Problem p03307 (python)

Fixed submission:
n = int(input())
if n % 2 == 0:
    print(n)
else:
    print(2*n)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
na = [0]*n
for i in range(n):
    na[i] = a[i]-(i+1)
mid = sum(na)//n
mid1 = mid+1
ans = 0
ans1 = 0
for i in range(n):
    ans += abs(na[i]-mid)
    ans1 += abs(na[i]+mid1)
print(min(ans, ans1))
Problem p02570 (python)

Fixed submission:
d,t,s= list(map(int, input().strip().split()))
x=t*s
if x>=d:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a= list(map(int, input().strip().split()))
a.sort()
b=1
for i in range(n):
    b*=a[i]
f=0#pairwise coprime
for i in range(n):
    if b%(a[i])**2==0:
        f=1
        break
b=np.gcd(a[0],a[1])
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
if f==0:
    print("pairwise coprime")
Problem p02571 (python)

Fixed submission:
s=input()
t=input()
L=len(s)
l=len(t)
X=[]
for i in range(L-l+1):
    x=0
    for j in range(l):
        if s[i+j]!=t[j]:
            x+=1
    X.append(x)
print(min(X))

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
L=len(s)
l=len(t)
X=[]
for i in range(L-l):
    x=0
    for j in range(l):
        if s[i+j]!=t[j]:
            x+=1
    X.append(x)
print(min(X))
Problem p02624 (python)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, N + 1):
    n = N // i  # 項数n
    cnt = (n * (2 * i + (n - 1) * i)) // 2  # 初項i, 項数n の等差数列の和の公式
    ans += cnt
print(ans)

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

Fixed submission:
a,b,c = list(map(int, input().strip().split()))
f=0
if a%2==1 or b%2==1 or c%2==1:
    print(f)
elif a==b and b==c:
    f=-1
    print(f)
else:
    while a%2==0 and b%2==0 and c%2==0:
        A=a
        B=b
        C=c
        a=B//2+C//2
        b=A//2+C//2
        c=A//2+B//2
        f=f+1
    else:
        print(f)

Buggy submission (verdict: Runtime Error):
if a%2==1 or b%2==1 or c%2==1:
    print(f)
elif a==b and b==c:
    f=-1
    print(f)
else:
    while a%2==0 and b%2==0 and c%2==0:
        A=a
        B=b
        C=c
        a=B//2+C//2
        b=A//2+C//2
        c=A//2+B//2
        f=f+1
    else:
        print(f)
Problem p02580 (python)

Fixed submission:
h,w,m=map(int,input().split())
bomb=[]
x=[0]*(h+1)
y=[0]*(w+1)
for i in range(m):
    h1,w1=map(int,input().split())
    x[h1]+=1
    y[w1]+=1
    bomb.append((h1,w1))
maxx=max(x)
maxy=max(y)
r=[]
c=[]
bomb=set(bomb)
for i in range(1,h+1):
    if x[i]==maxx:
        r.append(i)
for j in range(1,w+1):
    if y[j]==maxy:
        c.append(j)
for j in r:
    for k in c:
        if (j,k) not in bomb:
            print(maxx+maxy)
            exit()
print(maxx+maxy-1)

Buggy submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
bomb=[]
x=[0]*(h+1)
y=[0]*(w+1)
for i in range(m):
    h1,w1=map(int,input().split())
    x[h1]+=1
    y[w1]+=1
    bomb.append((h1,w1))
maxx=max(x)
maxy=max(y)
r=[]
c=[]
for i in range(1,h+1):
    if x[i]==maxx:
        r.append(i)
for j in range(1,w+1):
    if y[i]==maxy:
        c.append(i)
for j in r:
    for k in c:
        if (j,k) not in bomb:
            print(maxx+maxy)
            exit()
print(maxx+maxy-1)

Buggy submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
bomb=[]
x=[0]*(h+1)
y=[0]*(w+1)
for i in range(m):
    h1,w1=map(int,input().split())
    x[h1]+=1
    y[w1]+=1
    bomb.append((h1,w1))
maxx=max(x)
maxy=max(y)
r=[]
c=[]
for i in range(1,h+1):
    if x[i]==maxx:
        r.append(i)
for j in range(1,w+1):
    if y[i]==maxy:
        c.append(i)
for j in r:
    for k in c:
        if not (j,k) in bomb:
            print(maxx+maxy)
            exit()
print(maxx+maxy-1)

Buggy submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
bomb=[]
x=[0]*(h+1)
y=[0]*(w+1)
for i in range(m):
    h1,w1=map(int,input().split())
    x[h1]+=1
    y[w1]+=1
    bomb.append((h1,w1))
maxx=max(x)
maxy=max(y)
r=[]
c=[]
for i in range(1,h+1):
    if x[i]==maxx:
        r.append(i)
for j in range(1,w+1):
    if y[i]==maxy:
        c.append(i)
for j in r:
    for k in c:
        if not (j,k) in bomb:
            print(maxx+maxy)
            exit()
print(maxx+maxy-1)

Buggy submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
h=[]
w=[]
for i in range(m):
    h1,w1=map(int,input().split())
    h.append(h1)
    w.append(w1)
h_counter=Counter(h)
w_counter=Counter(w)
for i in range(m):
    if h[i]==h_counter.most_common()[0][0] and w[i]==w_counter.most_common()[0][0]:
        print(h_counter.most_common()[0][1]+w_counter.most_common()[0][1]-1)
        exit()
else:
    print(h_counter.most_common()[0][1]+w_counter.most_common()[0][1])
Problem p02598 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ng=0
ok=max(a)+1
while ok-ng>1:
    mid=(ng+ok)//2
    count=0
    for i in range(n):
        if a[i]%mid==0:
            count+=((a[i]//mid)-1)
        else:
            count+=(a[i]//mid)
    if count>k:
        ng=mid
    else:
        ok=mid
print(ok)

Buggy submission (verdict: Runtime Error):
h,w,m=map(int,input().split())
bomb=[]
x=[0]*(h+1)
y=[0]*(w+1)
for i in range(m):
    h1,w1=map(int,input().split())
    x[h1]+=1
    y[w1]+=1
    bomb.append((h1,w1))
maxx=max(x)
maxy=max(y)
r=[]
c=[]
for i in range(1,h+1):
    if x[i]==maxx:
        r.append(i)
for j in range(1,w+1):
    if y[i]==maxy:
        c.append(i)
for j in r:
    for k in c:
        if (j,k) not in bomb:
            print(maxx+maxy)
            exit()
print(maxx+maxy-1)
Problem p02726 (python)

Fixed submission:
from collections import deque

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

ans=[0]*n

for j in range(1,n+1):
    dict=[-1]*(n+1)
    que=deque()
    que.append(j)
    dict[j]=0
    while que:
        t=que.popleft()
        for k in map[t]:
            if dict[k]==-1:
                dict[k]=dict[t]+1
                que.append(k)
    for l in range(1,n+1):
        ans[dict[l]]+=1
for m in range(1,n):
    print(ans[m]//2)

Buggy submission (verdict: Runtime Error):
ans=[0]*n

for j in range(1,n+1):
    dict=[-1]*(n+1)
    que=deque()
    que.append(j)
    dict[j]=0
    while que:
        t=que.popleft()
        for k in map[t]:
            if dict[k]==-1:
                dict[k]=dict[t]+1
                que.append(k)
    for l in range(1,n+1):
        ans[dict[l]]+=1
for m in range(1,n):
    print(ans[m]//2)
Problem p02831 (python)

Fixed submission:
from math import gcd
a,b=map(int,input().split())
print((a*b)//gcd(a,b))

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

Fixed submission:
s=list(input())
n=len(s)
k=int(input())
count=[]
i=0
while i<=n-1:
    j=0
    while i+j+1<=n-1 and s[i+j]==s[i+j+1]:
        j+=1
    count.append(j+1)
    i+=(j+1)

length=len(count)
if length==1:
    print((n*k)//2)
   
else:
    if s[0]==s[-1]:
        ans=0
        for l in range(length):
            if l!=0 and l!=length-1:
                ans+=(count[l]//2)*k
        ans+=(count[0]//2+count[-1]//2)
        ans+=((count[0]+count[-1])//2)*(k-1)
        print(ans)
    else:
        ans=0
        for m in count:
            ans+=(m//2)*k
        print(ans)

Buggy submission (verdict: Runtime Error):
s = list(input())
k = int(input())
if not s[0]==s[-1]:
  count1=0
  for i in range(len(s)-1):
    if s[i]==s[i+1]:
      s[i+1]=1
      count1+=1
  print(k*count1)
else:
  s[-1]=0
  count2=0
  for i in range(len(s)-1):
    if s[i]==s[i+1]:
      s[i+12]=1
      count2+=1
  print(k*count2+k)
Problem p03013 (python)

Fixed submission:
n,m=map(int,input().split())
dp=[1]*n 
for i in range(m):
    dp[int(input())-1]=0
if n==1:
  if m==1:
    print(0)
  else:
    print(1)
else:
  if dp[1]==1:
    dp[1]=1+dp[0]
  for j in range(n-2):
    if dp[j+2]==1:
      dp[j+2]+=(dp[j]+dp[j+1]-1)
  print(dp[-1]%1000000007)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
dp=[1]*n 
for i in range(m):
    dp[int(input())-1]=0
if dp[1]==1:
    dp[1]=1+dp[0]
for j in range(n-2):
    if dp[j+2]==1:
      dp[j+2]+=(dp[j]+dp[j+1]-1)
print(dp[-1]%1000000007)
Problem p03017 (python)

Fixed submission:
n,a,b,c,d=map(int,input().split())
s=[0]+list(input())
if c<d:
    for i in range(a,d):
        if s[i]==s[i+1]=="#":
            print("No")
            break
    else:
        print("Yes")
else:
    for j in range(a,c):
        if s[j]==s[j+1]=="#":
            print("No")
            break
    else:
        for k in range(b-1,d):
            if s[k]==s[k+1]==s[k+2]==".":
                    print("Yes")
                    break
        else:
            print("No")

Buggy submission (verdict: Runtime Error):
s=[0]+list(input())
if c<d:
    for i in range(a,d):
        if s[i]==s[i+1]=="#":
            print("No")
            break
    else:
        print("Yes")
else:
    for j in range(a,c):
        if s[j]==s[j+1]=="#":
            print("No")
            break
    else:
        for k in range(b-1,d-2):
            if s[k]==s[k+1]==s[k+2]==".":
                    print("Yes")
                    break
        else:
            print("No")