def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

def l_s(L):
    return "".join(map(str, L))

import sys
from itertools import groupby as gb

S = input()
K = INT()
g1 = []

if len(set(S)) == 1:
    print(len(S) * K // 2)
    sys.exit()

for _, s in gb(S):
    g1.append(list(s))

tmp = l_s(g1[0]) + l_s(g1[len(g1) - 1])
g2 = []

for _, s in gb(tmp):
    g2.append(list(s))
    
ans = len(g1[0]) // 2 + len(g1[len(g1) - 1]) // 2

for i in range(1, len(g1) - 1):
    ans += (len(g1[i]) // 2) * K

for i in range(len(g2)):
    ans += (len(g2[i]) // 2) * (K - 1)
    
print(ans) def INT():
    return int(input()) INT return int(input()) int(input()) int input() input def MI():
    return map(int, input().split()) MI return map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split def LI():
    return list(map(int, input().split())) LI return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def l_s(L):
    return "".join(map(str, L)) l_s return "".join(map(str, L)) "".join(map(str, L)) "".join "" join map(str, L) map str L L L import sys sys from itertools import groupby as gb S = input() S input() input K = INT() K INT() INT g1 = [] g1 [] if len(set(S)) == 1:
    print(len(S) * K // 2)
    sys.exit() len(set(S)) == 1 len(set(S)) len set(S) set S 1 print(len(S) * K // 2) print len(S) * K // 2 len(S) * K len(S) len S K 2 sys.exit() sys.exit sys exit for _, s in gb(S):
    g1.append(list(s)) _ s gb(S) gb S g1.append(list(s)) g1.append g1 append list(s) list s tmp = l_s(g1[0]) + l_s(g1[len(g1) - 1]) tmp l_s(g1[0]) + l_s(g1[len(g1) - 1]) l_s(g1[0]) l_s g1[0] g1 0 l_s(g1[len(g1) - 1]) l_s g1[len(g1) - 1] g1 len(g1) - 1 len(g1) len g1 1 g2 = [] g2 [] for _, s in gb(tmp):
    g2.append(list(s))
     _ s gb(tmp) gb tmp g2.append(list(s)) g2.append g2 append list(s) list s ans = len(g1[0]) // 2 + len(g1[len(g1) - 1]) // 2 ans len(g1[0]) // 2 + len(g1[len(g1) - 1]) // 2 len(g1[0]) // 2 len(g1[0]) len g1[0] g1 0 2 len(g1[len(g1) - 1]) // 2 len(g1[len(g1) - 1]) len g1[len(g1) - 1] g1 len(g1) - 1 len(g1) len g1 1 2 for i in range(1, len(g1) - 1):
    ans += (len(g1[i]) // 2) * K i range(1, len(g1) - 1) range 1 len(g1) - 1 len(g1) len g1 1 ans += (len(g1[i]) // 2) * K ans (len(g1[i]) // 2) * K len(g1[i]) // 2 len(g1[i]) len g1[i] g1 i 2 K for i in range(len(g2)):
    ans += (len(g2[i]) // 2) * (K - 1)
     i range(len(g2)) range len(g2) len g2 ans += (len(g2[i]) // 2) * (K - 1) ans (len(g2[i]) // 2) * (K - 1) len(g2[i]) // 2 len(g2[i]) len g2[i] g2 i 2 K - 1 K 1 print(ans) print ans def l_s(L):
    return "".join(map(str, L)) def l_s(L):
    return "".join(map(str, L)) l_s def INT():
    return int(input()) def INT():
    return int(input()) INT S = input() input() S ans += (len(g2[i]) // 2) * (K - 1) (len(g2[i]) // 2) * (K - 1) ans g1 = [] [] g1 tmp = l_s(g1[0]) + l_s(g1[len(g1) - 1]) l_s(g1[0]) + l_s(g1[len(g1) - 1]) tmp def MI():
    return map(int, input().split()) def MI():
    return map(int, input().split()) MI def LI():
    return list(map(int, input().split())) def LI():
    return list(map(int, input().split())) LI K = INT() INT() K g2 = [] [] g2 ans += (len(g1[i]) // 2) * K (len(g1[i]) // 2) * K ans ans = len(g1[0]) // 2 + len(g1[len(g1) - 1]) // 2 len(g1[0]) // 2 + len(g1[len(g1) - 1]) // 2 ans
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

def l_s(L):
    return "".join(map(str, L))

import sys
from itertools import groupby as gb

S = input()
K = INT()
g1 = []

if len(set(S)) == 1:
    print(len(S) * K // 2)
    sys.exit()

for _, s in gb(S):
    g1.append(list(s))

tmp = l_s(g1[0]) + l_s(g1[len(g1) - 1])
g2 = []

for _, s in gb(tmp):
    g2.append(list(s))
    
ans = len(g1[0]) // 2 + len(g1[len(g1) - 1]) // 2

for i in range(1, len(g1) - 1):
    ans += (len(g1[i]) // 2) * K

for i in range(len(g2)):
    ans += (len(g2[i]) // 2) * (K - 1)
    
print(ans)