s=list(input())
a=int(input())

w = ""
c = 0
cnt = 0
for i in s:
    if w != i:
        #print(w)
        cnt += c//2
        c = 1
        w = i
    else:
        c +=1
cnt += c//2
#print(cnt)

start = 0
start_w = s[0]
for i in s:
    if start_w != i:
        break
    else:
        start +=1

s.reverse()

end = 0
end_w = s[0]
for i in s:
    if end_w != i:
        break
    else:
        end +=1

same = len(list(set(s)))
#print(same)

if s[0] != s[-1]:
    print(cnt*a)
elif same ==1:
    print(len(s)*a//2)
else:
    print(cnt*a-(a-1)*(start//2+end//2-(start+end)//2)) s=list(input()) s list(input()) list input() input a=int(input()) a int(input()) int input() input w = "" w "" c = 0 c 0 cnt = 0 cnt 0 for i in s:
    if w != i:
        #print(w)
        cnt += c//2
        c = 1
        w = i
    else:
        c +=1 i s if w != i:
        #print(w)
        cnt += c//2
        c = 1
        w = i
    else:
        c +=1 w != i w i cnt += c//2 cnt c//2 c 2 c = 1 c 1 w = i w i c +=1 c 1 cnt += c//2 cnt c//2 c 2 start = 0 start 0 start_w = s[0] start_w s[0] s 0 for i in s:
    if start_w != i:
        break
    else:
        start +=1 i s if start_w != i:
        break
    else:
        start +=1 start_w != i start_w i break start +=1 start 1 s.reverse() s.reverse s reverse end = 0 end 0 end_w = s[0] end_w s[0] s 0 for i in s:
    if end_w != i:
        break
    else:
        end +=1 i s if end_w != i:
        break
    else:
        end +=1 end_w != i end_w i break end +=1 end 1 same = len(list(set(s))) same len(list(set(s))) len list(set(s)) list set(s) set s if s[0] != s[-1]:
    print(cnt*a)
elif same ==1:
    print(len(s)*a//2)
else:
    print(cnt*a-(a-1)*(start//2+end//2-(start+end)//2)) s[0] != s[-1] s[0] s 0 s[-1] s -1 print(cnt*a) print cnt*a cnt a elif same ==1:
    print(len(s)*a//2) same ==1 same 1 print(len(s)*a//2) print len(s)*a//2 len(s)*a len(s) len s a 2 print(cnt*a-(a-1)*(start//2+end//2-(start+end)//2)) print cnt*a-(a-1)*(start//2+end//2-(start+end)//2) cnt*a cnt a (a-1)*(start//2+end//2-(start+end)//2) a-1 a 1 start//2+end//2-(start+end)//2 start//2+end//2 start//2 start 2 end//2 end 2 (start+end)//2 start+end start end 2 c = 1 1 c w = "" "" w cnt += c//2 c//2 cnt start_w = s[0] s[0] start_w c = 0 0 c a=int(input()) int(input()) a start = 0 0 start same = len(list(set(s))) len(list(set(s))) same start +=1 1 start s=list(input()) list(input()) s end +=1 1 end cnt = 0 0 cnt w = i i w c +=1 1 c cnt += c//2 c//2 cnt end = 0 0 end end_w = s[0] s[0] end_w
s=list(input())
a=int(input())

w = ""
c = 0
cnt = 0
for i in s:
    if w != i:
        #print(w)
        cnt += c//2
        c = 1
        w = i
    else:
        c +=1
cnt += c//2
#print(cnt)

start = 0
start_w = s[0]
for i in s:
    if start_w != i:
        break
    else:
        start +=1

s.reverse()

end = 0
end_w = s[0]
for i in s:
    if end_w != i:
        break
    else:
        end +=1

same = len(list(set(s)))
#print(same)

if s[0] != s[-1]:
    print(cnt*a)
elif same ==1:
    print(len(s)*a//2)
else:
    print(cnt*a-(a-1)*(start//2+end//2-(start+end)//2))