s = input()
k = int(input())

if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()

l = head = 0
now = s[0]
for i in range(len(s)):
    if s[i] == now:
      head += 1
    else:
        l = i
        break
        
r = tail = 0
now = s[-1]
for i in range(len(s))[::-1]:
    if s[i] == now:
        tail += 1
    else:
        r = i+1
        break

ans = 0
cnt = 0
now = s[l]
for i in range(l,r):
    if s[i] == now:
        cnt += 1
    else:
        ans += cnt//2
        cnt = 1
        now = s[i]
ans += cnt//2
ans *= k

if s[0] == s[-1]:
    ans += (head+tail)//2*(k-1)
    ans += head//2+tail//2
else:
    ans += (head//2+tail//2)*k
print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
    print(len(s)*k//2)
    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 exit() exit l = head = 0 l 0 = head = 0 head 0 now = s[0] now s[0] s 0 for i in range(len(s)):
    if s[i] == now:
      head += 1
    else:
        l = i
        break
         i range(len(s)) range len(s) len s if s[i] == now:
      head += 1
    else:
        l = i
        break
         s[i] == now s[i] s i now head += 1 head 1 l = i l i break r = tail = 0 r 0 = tail = 0 tail 0 now = s[-1] now s[-1] s -1 for i in range(len(s))[::-1]:
    if s[i] == now:
        tail += 1
    else:
        r = i+1
        break i range(len(s))[::-1] (len(s)) range len(s) len s ::-1 -1 if s[i] == now:
        tail += 1
    else:
        r = i+1
        break s[i] == now s[i] s i now tail += 1 tail 1 r = i+1 r i+1 i 1 break ans = 0 ans 0 cnt = 0 cnt 0 now = s[l] now s[l] s l for i in range(l,r):
    if s[i] == now:
        cnt += 1
    else:
        ans += cnt//2
        cnt = 1
        now = s[i] i range(l,r) range l r if s[i] == now:
        cnt += 1
    else:
        ans += cnt//2
        cnt = 1
        now = s[i] s[i] == now s[i] s i now cnt += 1 cnt 1 ans += cnt//2 ans cnt//2 cnt 2 cnt = 1 cnt 1 now = s[i] now s[i] s i ans += cnt//2 ans cnt//2 cnt 2 ans *= k ans k if s[0] == s[-1]:
    ans += (head+tail)//2*(k-1)
    ans += head//2+tail//2
else:
    ans += (head//2+tail//2)*k s[0] == s[-1] s[0] s 0 s[-1] s -1 ans += (head+tail)//2*(k-1) ans (head+tail)//2*(k-1) (head+tail)//2 head+tail head tail 2 k-1 k 1 ans += head//2+tail//2 ans head//2+tail//2 head//2 head 2 tail//2 tail 2 ans += (head//2+tail//2)*k ans (head//2+tail//2)*k head//2+tail//2 head//2 head 2 tail//2 tail 2 k print(ans) print ans ans += (head//2+tail//2)*k (head//2+tail//2)*k ans tail = 0 0 tail ans += cnt//2 cnt//2 ans r = i+1 i+1 r cnt = 0 0 cnt head = 0 0 head s = input() input() s tail += 1 1 tail ans += cnt//2 cnt//2 ans now = s[0] s[0] now cnt = 1 1 cnt cnt += 1 1 cnt now = s[-1] s[-1] now ans += head//2+tail//2 head//2+tail//2 ans r = tail = 0 0 r ans *= k k ans l = head = 0 0 l l = i i l now = s[l] s[l] now head += 1 1 head ans = 0 0 ans ans += (head+tail)//2*(k-1) (head+tail)//2*(k-1) ans k = int(input()) int(input()) k now = s[i] s[i] now
s = input()
k = int(input())

if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()

l = head = 0
now = s[0]
for i in range(len(s)):
    if s[i] == now:
      head += 1
    else:
        l = i
        break
        
r = tail = 0
now = s[-1]
for i in range(len(s))[::-1]:
    if s[i] == now:
        tail += 1
    else:
        r = i+1
        break

ans = 0
cnt = 0
now = s[l]
for i in range(l,r):
    if s[i] == now:
        cnt += 1
    else:
        ans += cnt//2
        cnt = 1
        now = s[i]
ans += cnt//2
ans *= k

if s[0] == s[-1]:
    ans += (head+tail)//2*(k-1)
    ans += head//2+tail//2
else:
    ans += (head//2+tail//2)*k
print(ans)