s = input()
k = int(input())
s_len = len(s)
if s_len == 1:
    print(k//2)
    exit()
if s.count(s[0]) == s_len:
    print((k*s_len)//2)
    exit()
cnt = 0
ans = 0
flag = "off"
while cnt <= s_len-2:
    if s[cnt] == s[cnt+1]:
        if cnt == s_len-2:
            flag = "on"
        ans += 1
        cnt += 1
    cnt += 1
dum = s[0]
check1 = 0
for i in s:
    if dum == i:
        check1 += 1
    else:
        break
dum = s[-1]
check2 = 0
for i in s[::-1]:
    if dum == i:
        check2 += 1
    else:
        break
if (check1+check2)%2 == 0 and s[0] == s[-1]:
    print(ans*k+(k-1))
else:
    print(ans*k) s = input() s input() input k = int(input()) k int(input()) int input() input s_len = len(s) s_len len(s) len s if s_len == 1:
    print(k//2)
    exit() s_len == 1 s_len 1 print(k//2) print k//2 k 2 exit() exit if s.count(s[0]) == s_len:
    print((k*s_len)//2)
    exit() s.count(s[0]) == s_len s.count(s[0]) s.count s count s[0] s 0 s_len print((k*s_len)//2) print (k*s_len)//2 k*s_len k s_len 2 exit() exit cnt = 0 cnt 0 ans = 0 ans 0 flag = "off" flag "off" while cnt <= s_len-2:
    if s[cnt] == s[cnt+1]:
        if cnt == s_len-2:
            flag = "on"
        ans += 1
        cnt += 1
    cnt += 1 cnt <= s_len-2 cnt s_len-2 s_len 2 if s[cnt] == s[cnt+1]:
        if cnt == s_len-2:
            flag = "on"
        ans += 1
        cnt += 1
     s[cnt] == s[cnt+1] s[cnt] s cnt s[cnt+1] s cnt+1 cnt 1 if cnt == s_len-2:
            flag = "on"
         cnt == s_len-2 cnt s_len-2 s_len 2 flag = "on" flag "on" ans += 1 ans 1 cnt += 1 cnt 1 cnt += 1 cnt 1 dum = s[0] dum s[0] s 0 check1 = 0 check1 0 for i in s:
    if dum == i:
        check1 += 1
    else:
        break i s if dum == i:
        check1 += 1
    else:
        break dum == i dum i check1 += 1 check1 1 break dum = s[-1] dum s[-1] s -1 check2 = 0 check2 0 for i in s[::-1]:
    if dum == i:
        check2 += 1
    else:
        break i s[::-1] s ::-1 -1 if dum == i:
        check2 += 1
    else:
        break dum == i dum i check2 += 1 check2 1 break if (check1+check2)%2 == 0 and s[0] == s[-1]:
    print(ans*k+(k-1))
else:
    print(ans*k) (check1+check2)%2 == 0 and s[0] == s[-1] (check1+check2)%2 == 0 (check1+check2)%2 check1+check2 check1 check2 2 0 s[0] == s[-1] s[0] s 0 s[-1] s -1 print(ans*k+(k-1)) print ans*k+(k-1) ans*k ans k k-1 k 1 print(ans*k) print ans*k ans k cnt = 0 0 cnt dum = s[-1] s[-1] dum flag = "on" "on" flag check2 = 0 0 check2 s_len = len(s) len(s) s_len ans = 0 0 ans check1 += 1 1 check1 dum = s[0] s[0] dum check1 = 0 0 check1 flag = "off" "off" flag cnt += 1 1 cnt cnt += 1 1 cnt k = int(input()) int(input()) k s = input() input() s check2 += 1 1 check2 ans += 1 1 ans
s = input()
k = int(input())
s_len = len(s)
if s_len == 1:
    print(k//2)
    exit()
if s.count(s[0]) == s_len:
    print((k*s_len)//2)
    exit()
cnt = 0
ans = 0
flag = "off"
while cnt <= s_len-2:
    if s[cnt] == s[cnt+1]:
        if cnt == s_len-2:
            flag = "on"
        ans += 1
        cnt += 1
    cnt += 1
dum = s[0]
check1 = 0
for i in s:
    if dum == i:
        check1 += 1
    else:
        break
dum = s[-1]
check2 = 0
for i in s[::-1]:
    if dum == i:
        check2 += 1
    else:
        break
if (check1+check2)%2 == 0 and s[0] == s[-1]:
    print(ans*k+(k-1))
else:
    print(ans*k)
