S = list(eval(input()))

K = int(eval(input()))

S2 = S[:]



if len(S) == 1:

    print((K//2))

    exit()

cons = 0

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

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

        cons += 1

        S[i+1] = '_'

if K == 1:

    print(cons)

    exit()

if S[0] != S[-1]:

    print((cons * K))

    exit()

cons3 = 0

if len(set(S2)) == 1:

    S2 = S2 * 2 + ['']

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

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

            cons3 += 1

            S2[i+1] = '_'

    print((cons3 * (K//2) + cons * (K%2)))

    exit()

# 最初から何文字連続するか

# この時最後の連続する文字はすでに奇数でかつ最初の文字と一緒

cons2 = 1

j = 0

while True:

    if S2[j] == S2[j+1]:

        cons2 += 1

        j += 1

    else:

        break

if cons2 % 2 == 0:

    minus = 0

else:

    minus = 1

print((cons * K + minus * (K-1) ))

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



S = list(sr())

K = ir()



def count(s):

    t = s.copy()

    cur = ''

    ret = 0

    for i in range(len(t)):

        if t[i] == cur:

            t[i] = '_'

            ret += 1

        cur = t[i]

    

    return ret



one = count(S)

two = count(S + S)

diff = count(S * 3) - count(S)

if K&1:

    answer = one + (K//2) * diff

else:

    answer = two + ((K//2)-1) * diff



print(answer)

# 24
S = list(eval(input()))
K = int(eval(input()))
S2 = S[:]
if len(S) == 1:
    print((K // 2))
    exit()
cons = 0
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        cons += 1
        S[i + 1] = "_"
if K == 1:
    print(cons)
    exit()
if S[0] != S[-1]:
    print((cons * K))
    exit()
cons3 = 0
if len(set(S2)) == 1:
    S2 = S2 * 2 + [""]
    for i in range(len(S2) - 1):
        if S2[i] == S2[i + 1]:
            cons3 += 1
            S2[i + 1] = "_"
    print((cons3 * (K // 2) + cons * (K % 2)))
    exit()
# 最初から何文字連続するか
# この時最後の連続する文字はすでに奇数でかつ最初の文字と一緒
cons2 = 1
j = 0
while True:
    if S2[j] == S2[j + 1]:
        cons2 += 1
        j += 1
    else:
        break
if cons2 % 2 == 0:
    minus = 0
else:
    minus = 1
print((cons * K + minus * (K - 1)))

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
S = list(sr())
K = ir()


def count(s):
    t = s.copy()
    cur = ""
    ret = 0
    for i in range(len(t)):
        if t[i] == cur:
            t[i] = "_"
            ret += 1
        cur = t[i]
    return ret


one = count(S)
two = count(S + S)
diff = count(S * 3) - count(S)
if K & 1:
    answer = one + (K // 2) * diff
else:
    answer = two + ((K // 2) - 1) * diff
print(answer)
# 24

-S = list(eval(input())) -K = int(eval(input())) -S2 = S[:] -if len(S) == 1: -    print((K // 2)) -    exit() -cons = 0 -for i in range(len(S) - 1): -    if S[i] == S[i + 1]: -        cons += 1 -        S[i + 1] = "_" -if K == 1: -    print(cons) -    exit() -if S[0] != S[-1]: -    print((cons * K)) -    exit() -cons3 = 0 -if len(set(S2)) == 1: -    S2 = S2 * 2 + [""] -    for i in range(len(S2) - 1): -        if S2[i] == S2[i + 1]: -            cons3 += 1 -            S2[i + 1] = "_" -    print((cons3 * (K // 2) + cons * (K % 2))) -    exit() -# 最初から何文字連続するか -# この時最後の連続する文字はすでに奇数でかつ最初の文字と一緒 -cons2 = 1 -j = 0 -while True: -    if S2[j] == S2[j + 1]: -        cons2 += 1 -        j += 1 -    else: -        break -if cons2 % 2 == 0: -    minus = 0 +import sys + +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +S = list(sr()) +K = ir() + + +def count(s): +    t = s.copy() +    cur = "" +    ret = 0 +    for i in range(len(t)): +        if t[i] == cur: +            t[i] = "_" +            ret += 1 +        cur = t[i] +    return ret + + +one = count(S) +two = count(S + S) +diff = count(S * 3) - count(S) +if K & 1: +    answer = one + (K // 2) * diff -    minus = 1 -print((cons * K + minus * (K - 1))) +    answer = two + ((K // 2) - 1) * diff +print(answer) +# 24