S = input()
K = int(input())



def func(S):
    inner = 0
    S = list(S)
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S[i + 1] = '#'
            inner += 1
    return inner

if len(set(list(S))) == 1:
    print(len(S) * K // 2)
else:
    inner = func(S)
    inter = func(S * 2) - func(S) * 2
    print(inner * K + inter * (K - 1)) S = input() S input() input K = int(input()) K int(input()) int input() input def func(S):
    inner = 0
    S = list(S)
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S[i + 1] = '#'
            inner += 1
    return inner func inner = 0 inner 0 S = list(S) S list(S) list S for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S[i + 1] = '#'
            inner += 1
     i range(len(S) - 1) range len(S) - 1 len(S) len S 1 if S[i] == S[i + 1]:
            S[i + 1] = '#'
            inner += 1
     S[i] == S[i + 1] S[i] S i S[i + 1] S i + 1 i 1 S[i + 1] = '#' S[i + 1] S i + 1 i 1 '#' inner += 1 inner 1 return inner inner S S if len(set(list(S))) == 1:
    print(len(S) * K // 2)
else:
    inner = func(S)
    inter = func(S * 2) - func(S) * 2
    print(inner * K + inter * (K - 1)) len(set(list(S))) == 1 len(set(list(S))) len set(list(S)) set list(S) list S 1 print(len(S) * K // 2) print len(S) * K // 2 len(S) * K len(S) len S K 2 inner = func(S) inner func(S) func S inter = func(S * 2) - func(S) * 2 inter func(S * 2) - func(S) * 2 func(S * 2) func S * 2 S 2 func(S) * 2 func(S) func S 2 print(inner * K + inter * (K - 1)) print inner * K + inter * (K - 1) inner * K inner K inter * (K - 1) inter K - 1 K 1 def func(S):
    inner = 0
    S = list(S)
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S[i + 1] = '#'
            inner += 1
    return inner def func(S):
    inner = 0
    S = list(S)
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S[i + 1] = '#'
            inner += 1
    return inner func S = input() input() S inner = func(S) func(S) inner K = int(input()) int(input()) K inter = func(S * 2) - func(S) * 2 func(S * 2) - func(S) * 2 inter
S = input()
K = int(input())



def func(S):
    inner = 0
    S = list(S)
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S[i + 1] = '#'
            inner += 1
    return inner

if len(set(list(S))) == 1:
    print(len(S) * K // 2)
else:
    inner = func(S)
    inter = func(S * 2) - func(S) * 2
    print(inner * K + inter * (K - 1))