Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = list(input().strip())
K = int(input())

L = [i for i in S]


if len(S) == 1:
    if K == 1:
        print(0)
    else:
        print(S[2])
    sys.exit()

count = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        count += 1
        S[i] = "A"
        tmp = S[i]
    else:
        tmp = S[i]

count2 = 0
if S[0] == S[-1]:
    L[0] = "A"
    count2 += 1
    tmp = L[0]
    for i in range(1, len(L)):
        if L[i] == tmp:
            count2 += 1
            L[i] = "A"
            tmp = L[i]
        else:
            tmp = L[i]
    print((K//2)*count2 + (K//2+K%2)*count)
else:
    print(count * K)

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

S = list(input().strip())
K = int(input())

L = [i for i in S]


if len(S) == 1:
    if K == 1:
        print(0)
    else:
        print(K//2)
    sys.exit()

count = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        count += 1
        S[i] = "A"
        tmp = S[i]
    else:
        tmp = S[i]

count2 = 0
if S[0] == S[-1]:
    L[0] = "A"
    count2 += 1
    tmp = L[0]
    for i in range(1, len(L)):
        if L[i] == tmp:
            count2 += 1
            L[i] = "A"
            tmp = L[i]
        else:
            tmp = L[i]
    if L[-1] == "A":
        print((K//2)*count2 + (K//2+K%2)*count)
    else:
        print(count + (K-1)*count2)
else:
    print(count * K)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = list(input().strip())
K = int(input())

L = [i for i in S]


if len(S) == 1:
    if K == 1:
        print(0)
    else:
        print(K//2)
        print(S[2])
    sys.exit()

count = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        count += 1
        S[i] = "A"
        tmp = S[i]
    else:
        tmp = S[i]

count2 = 0
if S[0] == S[-1]:
    L[0] = "A"
    count2 += 1
    tmp = L[0]
    for i in range(1, len(L)):
        if L[i] == tmp:
            count2 += 1
            L[i] = "A"
            tmp = L[i]
        else:
            tmp = L[i]
    print((K//2)*count2 + (K//2+K%2)*count)
else:
    print(count * K)

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

S = list(input().strip())
K = int(input())

L = [i for i in S]


if len(S) == 1:
    if K == 1:
        print(0)
    else:
        print(K//2)
    sys.exit()

count = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        count += 1
        S[i] = "A"
        tmp = S[i]
    else:
        tmp = S[i]

count2 = 0
if S[0] == S[-1]:
    L[0] = "A"
    count2 += 1
    tmp = L[0]
    for i in range(1, len(L)):
        if L[i] == tmp:
            count2 += 1
            L[i] = "A"
            tmp = L[i]
        else:
            tmp = L[i]
    if L[-1] == "A":
        print((K//2)*count2 + (K//2+K%2)*count)
    else:
        print(count + (K-1)*count2)
else:
    print(count * K)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = list(input().strip())
K = int(input())


count = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        count += 1
        tmp = ""
    else:
        tmp = S[i]

if S[0] == S[-1] and S[-2] != S[-1]:
    count += 1
print(count * K)

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

S = list(input().strip())
K = int(input())

L = [i for i in S]


if len(S) == 1:
    if K == 1:
        print(0)
    else:
        print(K//2)
    sys.exit()

count = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        count += 1
        S[i] = "A"
        tmp = S[i]
    else:
        tmp = S[i]

count2 = 0
if S[0] == S[-1]:
    L[0] = "A"
    count2 += 1
    tmp = L[0]
    for i in range(1, len(L)):
        if L[i] == tmp:
            count2 += 1
            L[i] = "A"
            tmp = L[i]
        else:
            tmp = L[i]
    if L[-1] == "A":
        print((K//2)*count2 + (K//2+K%2)*count)
    else:
        print(count + (K-1)*count2)
else:
    print(count * K)