s = input()
k = int(input())
ren = []
n = 1
p = s[0]
for i in range(1,len(s)):
    if p == s[i]:
        n += 1
    else:
        ren.append(n)
        p = s[i]
        n = 1
ren.append(n)

ans = 0
if ren[0] == len(s):
    ans = (ren[0]*k)//2
elif s[0] == s[-1]:
    ans = ren[0]//2 + ren[-1]//2 - (ren[0]+ren[-1])//2
    ren[0] += ren[-1]
    ren[-1] = 0
    for i in ren:
        ans += (i//2)*k
else:
    for i in ren:
        ans += (i//2)*k

print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input ren = [] ren [] n = 1 n 1 p = s[0] p s[0] s 0 for i in range(1,len(s)):
    if p == s[i]:
        n += 1
    else:
        ren.append(n)
        p = s[i]
        n = 1 i range(1,len(s)) range 1 len(s) len s if p == s[i]:
        n += 1
    else:
        ren.append(n)
        p = s[i]
        n = 1 p == s[i] p s[i] s i n += 1 n 1 ren.append(n) ren.append ren append n p = s[i] p s[i] s i n = 1 n 1 ren.append(n) ren.append ren append n ans = 0 ans 0 if ren[0] == len(s):
    ans = (ren[0]*k)//2
elif s[0] == s[-1]:
    ans = ren[0]//2 + ren[-1]//2 - (ren[0]+ren[-1])//2
    ren[0] += ren[-1]
    ren[-1] = 0
    for i in ren:
        ans += (i//2)*k
else:
    for i in ren:
        ans += (i//2)*k ren[0] == len(s) ren[0] ren 0 len(s) len s ans = (ren[0]*k)//2 ans (ren[0]*k)//2 ren[0]*k ren[0] ren 0 k 2 elif s[0] == s[-1]:
    ans = ren[0]//2 + ren[-1]//2 - (ren[0]+ren[-1])//2
    ren[0] += ren[-1]
    ren[-1] = 0
    for i in ren:
        ans += (i//2)*k s[0] == s[-1] s[0] s 0 s[-1] s -1 ans = ren[0]//2 + ren[-1]//2 - (ren[0]+ren[-1])//2 ans ren[0]//2 + ren[-1]//2 - (ren[0]+ren[-1])//2 ren[0]//2 + ren[-1]//2 ren[0]//2 ren[0] ren 0 2 ren[-1]//2 ren[-1] ren -1 2 (ren[0]+ren[-1])//2 ren[0]+ren[-1] ren[0] ren 0 ren[-1] ren -1 2 ren[0] += ren[-1] ren[0] ren 0 ren[-1] ren -1 ren[-1] = 0 ren[-1] ren -1 0 for i in ren:
        ans += (i//2)*k i ren ans += (i//2)*k ans (i//2)*k i//2 i 2 k for i in ren:
        ans += (i//2)*k i ren ans += (i//2)*k ans (i//2)*k i//2 i 2 k print(ans) print ans n = 1 1 n ren = [] [] ren s = input() input() s ans = 0 0 ans ans += (i//2)*k (i//2)*k ans n += 1 1 n ans = (ren[0]*k)//2 (ren[0]*k)//2 ans n = 1 1 n k = int(input()) int(input()) k ans = ren[0]//2 + ren[-1]//2 - (ren[0]+ren[-1])//2 ren[0]//2 + ren[-1]//2 - (ren[0]+ren[-1])//2 ans p = s[0] s[0] p p = s[i] s[i] p ans += (i//2)*k (i//2)*k ans
s = input()
k = int(input())
ren = []
n = 1
p = s[0]
for i in range(1,len(s)):
    if p == s[i]:
        n += 1
    else:
        ren.append(n)
        p = s[i]
        n = 1
ren.append(n)

ans = 0
if ren[0] == len(s):
    ans = (ren[0]*k)//2
elif s[0] == s[-1]:
    ans = ren[0]//2 + ren[-1]//2 - (ren[0]+ren[-1])//2
    ren[0] += ren[-1]
    ren[-1] = 0
    for i in ren:
        ans += (i//2)*k
else:
    for i in ren:
        ans += (i//2)*k

print(ans)
