Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())
A,B,C=0,0,0
test=s*3
for i in range(len(s)*3-1):
    if test[i]==test[i+1]:
        test[i+1]="A"
A=test[:len(s)].count("A")
B=test[len(s):len(s)*2].count("A")
C=test[len(s)*2:len(s)*3].count("A")

flag=0
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        flag=1
        break
if flag==0:print((s*k+1)//2)
if k==1:print(A)
elif k==2:print(A+B)
else:
    print(A+B*(k-2)+C)


Fixed submission:
s=list(input())
k=int(input())
A,B,C=0,0,0
test=s*3
for i in range(len(s)*3-1):
    if test[i]==test[i+1]:
        test[i+1]="A"
A=test[:len(s)].count("A")
B=test[len(s):len(s)*2].count("A")
C=test[len(s)*2:len(s)*3].count("A")

if s.count(s[0])==len(s):
    print((len(s)*k)//2)
else:
    if k==1:print(A)
    elif k==2:print(A+B)
    else:print(A+B*(k-2)+C)

Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())
count=0
word=""
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        if i==len(s)-1:
            word=s[i]
        s[i]="A"
        count +=1

if s[0]==s[-1]:
    word=s[-1]
    s[-1]="A"
    count +=1

print((count*k)-1 if (s[-1]=="A")and(s[-2]!=word) else count*k)

Fixed submission:
s=list(input())
k=int(input())
A,B,C=0,0,0
test=s*3
for i in range(len(s)*3-1):
    if test[i]==test[i+1]:
        test[i+1]="A"
A=test[:len(s)].count("A")
B=test[len(s):len(s)*2].count("A")
C=test[len(s)*2:len(s)*3].count("A")

if s.count(s[0])==len(s):
    print((len(s)*k)//2)
else:
    if k==1:print(A)
    elif k==2:print(A+B)
    else:print(A+B*(k-2)+C)

Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())
count=0
re=""
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        if i==len(s)-1:
            re=s[-1]
        s[i]="A"
        count +=1

if s[0]==s[-1]:
    count +=1
    re=s[-1]
    s[-1]="A"

if (s[-1]=="A") and (s[-2]!=re):
    print((count*k)-1)
    exit()
print(count*k)

Fixed submission:
s=list(input())
k=int(input())
A,B,C=0,0,0
test=s*3
for i in range(len(s)*3-1):
    if test[i]==test[i+1]:
        test[i+1]="A"
A=test[:len(s)].count("A")
B=test[len(s):len(s)*2].count("A")
C=test[len(s)*2:len(s)*3].count("A")

if s.count(s[0])==len(s):
    print((len(s)*k)//2)
else:
    if k==1:print(A)
    elif k==2:print(A+B)
    else:print(A+B*(k-2)+C)

Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())
count=0
re=""
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        if i==len(s)-1:
            re=s[-1]
        s[i]="A"
        count +=1

if s[0]==s[-1] and s[-1]!="A":
    count +=1
    re=s[-1]
    s[-1]="A"

if s[-1]=="A" and s[-2]!=re:print((count*k)-1)
else:print(count*k)

Fixed submission:
s=list(input())
k=int(input())
A,B,C=0,0,0
test=s*3
for i in range(len(s)*3-1):
    if test[i]==test[i+1]:
        test[i+1]="A"
A=test[:len(s)].count("A")
B=test[len(s):len(s)*2].count("A")
C=test[len(s)*2:len(s)*3].count("A")

if s.count(s[0])==len(s):
    print((len(s)*k)//2)
else:
    if k==1:print(A)
    elif k==2:print(A+B)
    else:print(A+B*(k-2)+C)

Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())
count=0
re=""
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        if i == len(s) - 1: re += s[-1]
        s[i]="A"
        count +=1

if s[0]==s[-1] and s[-1]!="A":
    count +=1
    re +=s[-1]
    s[-1]="A"

if s[-1]=="A" and s[-2]!=re:print((count*k)-1)
else:print(count*k)

Fixed submission:
s=list(input())
k=int(input())
A,B,C=0,0,0
test=s*3
for i in range(len(s)*3-1):
    if test[i]==test[i+1]:
        test[i+1]="A"
A=test[:len(s)].count("A")
B=test[len(s):len(s)*2].count("A")
C=test[len(s)*2:len(s)*3].count("A")

if s.count(s[0])==len(s):
    print((len(s)*k)//2)
else:
    if k==1:print(A)
    elif k==2:print(A+B)
    else:print(A+B*(k-2)+C)