S = input()
K = int(input())
N = len(S)
#最初の1回
ans = 0
prev = S[0]
endchange = False
for i in range(1,N):
    if S[i] == prev:
        ans += 1
        prev = 0
        if i == N:
            endchange = True
    else:
        prev = S[i]

if all([s == S[0] for s in S]):
    print((N*K)//2)

elif K==1 or S[0] != S[-1]:
    print(ans * K)
else:
    front = 1
    while 1:
        if S[front] == S[0]:
            front += 1
        else:break
    back = -1
    while 1:
        if S[back] == S[0]:
            back -= 1
        else:break
    back = -1-back
    print(ans*K + ((front+back)//2 - front//2 - back//2) * (K-1)) S = input() S input() input K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S ans = 0 ans 0 prev = S[0] prev S[0] S 0 endchange = False endchange False for i in range(1,N):
    if S[i] == prev:
        ans += 1
        prev = 0
        if i == N:
            endchange = True
    else:
        prev = S[i] i range(1,N) range 1 N if S[i] == prev:
        ans += 1
        prev = 0
        if i == N:
            endchange = True
    else:
        prev = S[i] S[i] == prev S[i] S i prev ans += 1 ans 1 prev = 0 prev 0 if i == N:
            endchange = True
     i == N i N endchange = True endchange True prev = S[i] prev S[i] S i if all([s == S[0] for s in S]):
    print((N*K)//2)

elif K==1 or S[0] != S[-1]:
    print(ans * K)
else:
    front = 1
    while 1:
        if S[front] == S[0]:
            front += 1
        else:break
    back = -1
    while 1:
        if S[back] == S[0]:
            back -= 1
        else:break
    back = -1-back
    print(ans*K + ((front+back)//2 - front//2 - back//2) * (K-1)) all([s == S[0] for s in S]) all [s == S[0] for s in S] print((N*K)//2) print (N*K)//2 N*K N K 2 elif K==1 or S[0] != S[-1]:
    print(ans * K) K==1 or S[0] != S[-1] K==1 K 1 S[0] != S[-1] S[0] S 0 S[-1] S -1 print(ans * K) print ans * K ans K front = 1 front 1 while 1:
        if S[front] == S[0]:
            front += 1
        else:break
     1 if S[front] == S[0]:
            front += 1
        else:break
     S[front] == S[0] S[front] S front S[0] S 0 front += 1 front 1 back = -1 back -1 while 1:
        if S[back] == S[0]:
            back -= 1
        else:break
     1 if S[back] == S[0]:
            back -= 1
        else:break
     S[back] == S[0] S[back] S back S[0] S 0 back -= 1 back 1 back = -1-back back -1-back -1 back print(ans*K + ((front+back)//2 - front//2 - back//2) * (K-1)) print ans*K + ((front+back)//2 - front//2 - back//2) * (K-1) ans*K ans K ((front+back)//2 - front//2 - back//2) * (K-1) (front+back)//2 - front//2 - back//2 (front+back)//2 - front//2 (front+back)//2 front+back front back 2 front//2 front 2 back//2 back 2 K-1 K 1 endchange = False False endchange ans += 1 1 ans endchange = True True endchange K = int(input()) int(input()) K ans = 0 0 ans prev = S[i] S[i] prev front = 1 1 front front += 1 1 front prev = S[0] S[0] prev back = -1 -1 back back -= 1 1 back N = len(S) len(S) N back = -1-back -1-back back S = input() input() S prev = 0 0 prev
S = input()
K = int(input())
N = len(S)
#最初の1回
ans = 0
prev = S[0]
endchange = False
for i in range(1,N):
    if S[i] == prev:
        ans += 1
        prev = 0
        if i == N:
            endchange = True
    else:
        prev = S[i]

if all([s == S[0] for s in S]):
    print((N*K)//2)

elif K==1 or S[0] != S[-1]:
    print(ans * K)
else:
    front = 1
    while 1:
        if S[front] == S[0]:
            front += 1
        else:break
    back = -1
    while 1:
        if S[back] == S[0]:
            back -= 1
        else:break
    back = -1-back
    print(ans*K + ((front+back)//2 - front//2 - back//2) * (K-1))
