import math
S=input()
K=int(input())

ss=S*2

ss=[a for a in ss]
answer=0
N=len(ss)
for n in range(N-1):
    if ss[n]==ss[n+1]:
        answer+=1
        ss[n+1]=0

sss=S*3

sss=[a for a in sss]
suuji=0
N=len(sss)
for n in range(N-1):
    if sss[n]==sss[n+1]:
        suuji+=1
        sss[n+1]=0

number=0
s=[a for a in S]
N=len(s)
for n in range(N-1):
    if s[n]==s[n+1]:
        number+=1
        s[n+1]=0
if K==1:
    print(number)
else:
    if answer - number == suuji - answer:
        print(number + (answer - number) * (K - 1))
    else:
        if K % 2 == 0:
            print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2-1))
        else:
            print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2))
 import math math S=input() S input() input K=int(input()) K int(input()) int input() input ss=S*2 ss S*2 S 2 a for a in ss for a in ss a ss for a in ss a ss=[a for a in ss] ss [a for a in ss] answer=0 answer 0 N=len(ss) N len(ss) len ss for n in range(N-1):
    if ss[n]==ss[n+1]:
        answer+=1
        ss[n+1]=0 n range(N-1) range N-1 N 1 if ss[n]==ss[n+1]:
        answer+=1
        ss[n+1]=0 ss[n]==ss[n+1] ss[n] ss n ss[n+1] ss n+1 n 1 answer+=1 answer 1 ss[n+1]=0 ss[n+1] ss n+1 n 1 0 sss=S*3 sss S*3 S 3 a for a in sss for a in sss a sss for a in sss a sss=[a for a in sss] sss [a for a in sss] suuji=0 suuji 0 N=len(sss) N len(sss) len sss for n in range(N-1):
    if sss[n]==sss[n+1]:
        suuji+=1
        sss[n+1]=0 n range(N-1) range N-1 N 1 if sss[n]==sss[n+1]:
        suuji+=1
        sss[n+1]=0 sss[n]==sss[n+1] sss[n] sss n sss[n+1] sss n+1 n 1 suuji+=1 suuji 1 sss[n+1]=0 sss[n+1] sss n+1 n 1 0 number=0 number 0 a for a in S for a in S a S for a in S a s=[a for a in S] s [a for a in S] N=len(s) N len(s) len s for n in range(N-1):
    if s[n]==s[n+1]:
        number+=1
        s[n+1]=0 n range(N-1) range N-1 N 1 if s[n]==s[n+1]:
        number+=1
        s[n+1]=0 s[n]==s[n+1] s[n] s n s[n+1] s n+1 n 1 number+=1 number 1 s[n+1]=0 s[n+1] s n+1 n 1 0 if K==1:
    print(number)
else:
    if answer - number == suuji - answer:
        print(number + (answer - number) * (K - 1))
    else:
        if K % 2 == 0:
            print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2-1))
        else:
            print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2)) K==1 K 1 print(number) print number if answer - number == suuji - answer:
        print(number + (answer - number) * (K - 1))
    else:
        if K % 2 == 0:
            print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2-1))
        else:
            print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2)) answer - number == suuji - answer answer - number answer number suuji - answer suuji answer print(number + (answer - number) * (K - 1)) print number + (answer - number) * (K - 1) number (answer - number) * (K - 1) answer - number answer number K - 1 K 1 if K % 2 == 0:
            print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2-1))
        else:
            print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2)) K % 2 == 0 K % 2 K 2 0 print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2-1)) print number + (answer - number) * (K//2)+(suuji-answer)*(K//2-1) number + (answer - number) * (K//2) number (answer - number) * (K//2) answer - number answer number K//2 K 2 (suuji-answer)*(K//2-1) suuji-answer suuji answer K//2-1 K//2 K 2 1 print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2)) print number + (answer - number) * (K//2)+(suuji-answer)*(K//2) number + (answer - number) * (K//2) number (answer - number) * (K//2) answer - number answer number K//2 K 2 (suuji-answer)*(K//2) suuji-answer suuji answer K//2 K 2 N=len(ss) len(ss) N S=input() input() S sss=S*3 S*3 sss N=len(sss) len(sss) N answer=0 0 answer number=0 0 number s=[a for a in S] [a for a in S] s number+=1 1 number answer+=1 1 answer N=len(s) len(s) N sss=[a for a in sss] [a for a in sss] sss K=int(input()) int(input()) K ss=S*2 S*2 ss ss=[a for a in ss] [a for a in ss] ss suuji+=1 1 suuji suuji=0 0 suuji
import math
S=input()
K=int(input())

ss=S*2

ss=[a for a in ss]
answer=0
N=len(ss)
for n in range(N-1):
    if ss[n]==ss[n+1]:
        answer+=1
        ss[n+1]=0

sss=S*3

sss=[a for a in sss]
suuji=0
N=len(sss)
for n in range(N-1):
    if sss[n]==sss[n+1]:
        suuji+=1
        sss[n+1]=0

number=0
s=[a for a in S]
N=len(s)
for n in range(N-1):
    if s[n]==s[n+1]:
        number+=1
        s[n+1]=0
if K==1:
    print(number)
else:
    if answer - number == suuji - answer:
        print(number + (answer - number) * (K - 1))
    else:
        if K % 2 == 0:
            print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2-1))
        else:
            print(number + (answer - number) * (K//2)+(suuji-answer)*(K//2))

