import copy



S = list(eval(input()))

K = int(eval(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)
import copy



S = list(eval(input()))

K = int(eval(input()))



def count(L):

    cnt = 0

    for i in range(len(L)-1):

        if L[i] == L[i+1]:

            L[i+1] = "1"

            cnt += 1

    return cnt



T = copy.copy(S)

T.insert(0, T[len(T)-1])

cnt_T = count(T)



if T[-1] != "1":

    ans = count(S) + (cnt_T * (K-1))

else:

    TT = S * 2

    cnt_TT = count(TT)

    if K % 2 == 0:

        ans = cnt_TT * (K // 2)

    else:

        ans = (cnt_TT * (K // 2)) + count(S)



print(ans)
import copy

S = list(eval(input()))
K = int(eval(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)

import copy

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


def count(L):
    cnt = 0
    for i in range(len(L) - 1):
        if L[i] == L[i + 1]:
            L[i + 1] = "1"
            cnt += 1
    return cnt


T = copy.copy(S)
T.insert(0, T[len(T) - 1])
cnt_T = count(T)
if T[-1] != "1":
    ans = count(S) + (cnt_T * (K - 1))
else:
    TT = S * 2
    cnt_TT = count(TT)
    if K % 2 == 0:
        ans = cnt_TT * (K // 2)
    else:
        ans = (cnt_TT * (K // 2)) + count(S)
print(ans)

-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 +def count(L): +    cnt = 0 +    for i in range(len(L) - 1): +        if L[i] == L[i + 1]: +            L[i + 1] = "1" +            cnt += 1 +    return cnt -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)) +cnt_T = count(T) +if T[-1] != "1": +    ans = count(S) + (cnt_T * (K - 1)) -    cnt_T = 0 -    for i in range(len(TT) - 1): -        if TT[i] == TT[i + 1]: -            TT[i + 1] = "1" -            cnt_T += 1 +    cnt_TT = count(TT) -        ans = cnt_T * (K // 2) +        ans = cnt_TT * (K // 2) -        ans = (cnt_T * (K // 2)) + Scount() +        ans = (cnt_TT * (K // 2)) + count(S)