Buggy python submission (verdict: Runtime Error):
import copy

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

def Scount():
    cnt_S = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = "1"
            cnt_S += 1
    return cnt_S

if K == 1:
    ans = Scout()

else:
    T = copy.copy(S)
    T.insert(0, T[len(T)-1])
    cnt_T = 0
    for i in range(len(T)-1):
        if T[i] == T[i+1]:
            T[i+1] = "1"
            cnt_T += 1

    if T[i+1] != "1":
        ans = Scount() + (cnt_T * (K-1))
    else:
        TT = S * 2
        cnt_T = 0
        for i in range(len(TT)-1):
            if TT[i] == TT[i+1]:
                TT[i+1] = "1"
                cnt_T += 1
        if K % 2 == 0:
            ans = cnt_T * K / 2
        else:
            ans = (cnt_T * K // 2) + Scount()

print(ans)

Fixed submission:
import copy

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

def Scount():
    cnt_S = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = "1"
            cnt_S += 1
    return cnt_S

T = copy.copy(S)
T.insert(0, T[len(T)-1])
cnt_T = 0
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "1"
        cnt_T += 1

if T[i+1] != "1":
    ans = Scount() + (cnt_T * (K-1))
else:
    TT = S * 2
    cnt_T = 0
    for i in range(len(TT)-1):
        if TT[i] == TT[i+1]:
            TT[i+1] = "1"
            cnt_T += 1
    if K % 2 == 0:
        ans = cnt_T * (K // 2)
    else:
        ans = (cnt_T * (K // 2)) + Scount()
print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
 
T = list(S * K)
T.append("0")
count = 0
 
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "1"
        count += 1

print(count)


Fixed submission:
import copy

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

def Scount():
    cnt_S = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = "1"
            cnt_S += 1
    return cnt_S

T = copy.copy(S)
T.insert(0, T[len(T)-1])
cnt_T = 0
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "1"
        cnt_T += 1

if T[i+1] != "1":
    ans = Scount() + (cnt_T * (K-1))
else:
    TT = S * 2
    cnt_T = 0
    for i in range(len(TT)-1):
        if TT[i] == TT[i+1]:
            TT[i+1] = "1"
            cnt_T += 1
    if K % 2 == 0:
        ans = cnt_T * (K // 2)
    else:
        ans = (cnt_T * (K // 2)) + Scount()
print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
 
T = list(S * K)
T.append("0")
count = 0
 
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "1"
        count += 1
 
print(count)

Fixed submission:
import copy

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

def Scount():
    cnt_S = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = "1"
            cnt_S += 1
    return cnt_S

T = copy.copy(S)
T.insert(0, T[len(T)-1])
cnt_T = 0
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "1"
        cnt_T += 1

if T[i+1] != "1":
    ans = Scount() + (cnt_T * (K-1))
else:
    TT = S * 2
    cnt_T = 0
    for i in range(len(TT)-1):
        if TT[i] == TT[i+1]:
            TT[i+1] = "1"
            cnt_T += 1
    if K % 2 == 0:
        ans = cnt_T * (K // 2)
    else:
        ans = (cnt_T * (K // 2)) + Scount()
print(ans)

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

T = list(S * K)
T.append("0")
count = 0

for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "p"
        count += 1

print(count)

Fixed submission:
import copy

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

def Scount():
    cnt_S = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = "1"
            cnt_S += 1
    return cnt_S

T = copy.copy(S)
T.insert(0, T[len(T)-1])
cnt_T = 0
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "1"
        cnt_T += 1

if T[i+1] != "1":
    ans = Scount() + (cnt_T * (K-1))
else:
    TT = S * 2
    cnt_T = 0
    for i in range(len(TT)-1):
        if TT[i] == TT[i+1]:
            TT[i+1] = "1"
            cnt_T += 1
    if K % 2 == 0:
        ans = cnt_T * (K // 2)
    else:
        ans = (cnt_T * (K // 2)) + Scount()
print(ans)