s = list(input())
k = int(input())
ans = []
now = s[0]
cou = 0
if len(s) == 1:
    print(k//2)
    exit()

for i in range(len(s)):
    if now == s[i]:
        cou += 1
    elif now != s[i]:
        ans.append(cou)
        cou = 1
        now = s[i]
if cou > 0:
    ans.append(cou)
if ans[0] == len(s):
    print((ans[0]*k)//2)
    exit()
    
p = 0
for i in ans:
    p += (i//2)*k

if s[0] == s[-1]:
    p -= (ans[0]//2 + ans[-1]//2)*(k-1)
    p += ((ans[0]+ans[-1])//2)*(k-1)

print(p) s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input ans = [] ans [] now = s[0] now s[0] s 0 cou = 0 cou 0 if len(s) == 1:
    print(k//2)
    exit() len(s) == 1 len(s) len s 1 print(k//2) print k//2 k 2 exit() exit for i in range(len(s)):
    if now == s[i]:
        cou += 1
    elif now != s[i]:
        ans.append(cou)
        cou = 1
        now = s[i] i range(len(s)) range len(s) len s if now == s[i]:
        cou += 1
    elif now != s[i]:
        ans.append(cou)
        cou = 1
        now = s[i] now == s[i] now s[i] s i cou += 1 cou 1 elif now != s[i]:
        ans.append(cou)
        cou = 1
        now = s[i] now != s[i] now s[i] s i ans.append(cou) ans.append ans append cou cou = 1 cou 1 now = s[i] now s[i] s i if cou > 0:
    ans.append(cou) cou > 0 cou 0 ans.append(cou) ans.append ans append cou if ans[0] == len(s):
    print((ans[0]*k)//2)
    exit()
     ans[0] == len(s) ans[0] ans 0 len(s) len s print((ans[0]*k)//2) print (ans[0]*k)//2 ans[0]*k ans[0] ans 0 k 2 exit() exit p = 0 p 0 for i in ans:
    p += (i//2)*k i ans p += (i//2)*k p (i//2)*k i//2 i 2 k if s[0] == s[-1]:
    p -= (ans[0]//2 + ans[-1]//2)*(k-1)
    p += ((ans[0]+ans[-1])//2)*(k-1) s[0] == s[-1] s[0] s 0 s[-1] s -1 p -= (ans[0]//2 + ans[-1]//2)*(k-1) p (ans[0]//2 + ans[-1]//2)*(k-1) ans[0]//2 + ans[-1]//2 ans[0]//2 ans[0] ans 0 2 ans[-1]//2 ans[-1] ans -1 2 k-1 k 1 p += ((ans[0]+ans[-1])//2)*(k-1) p ((ans[0]+ans[-1])//2)*(k-1) (ans[0]+ans[-1])//2 ans[0]+ans[-1] ans[0] ans 0 ans[-1] ans -1 2 k-1 k 1 print(p) print p now = s[i] s[i] now p = 0 0 p cou = 0 0 cou cou += 1 1 cou s = list(input()) list(input()) s now = s[0] s[0] now cou = 1 1 cou p -= (ans[0]//2 + ans[-1]//2)*(k-1) (ans[0]//2 + ans[-1]//2)*(k-1) p p += (i//2)*k (i//2)*k p k = int(input()) int(input()) k ans = [] [] ans p += ((ans[0]+ans[-1])//2)*(k-1) ((ans[0]+ans[-1])//2)*(k-1) p
s = list(input())
k = int(input())
ans = []
now = s[0]
cou = 0
if len(s) == 1:
    print(k//2)
    exit()

for i in range(len(s)):
    if now == s[i]:
        cou += 1
    elif now != s[i]:
        ans.append(cou)
        cou = 1
        now = s[i]
if cou > 0:
    ans.append(cou)
if ans[0] == len(s):
    print((ans[0]*k)//2)
    exit()
    
p = 0
for i in ans:
    p += (i//2)*k

if s[0] == s[-1]:
    p -= (ans[0]//2 + ans[-1]//2)*(k-1)
    p += ((ans[0]+ans[-1])//2)*(k-1)

print(p)