import sys

rr = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(sys.stdin.readline())

s = rr()
k = ri()
cnt = 0
i = 0
if len(set(s)) == 1:
  print(int(len(s)*k/2))
  exit()
while i < len(s)-1:
  if s[i] == s[i+1]:
    cnt += 1
    i += 1
  i += 1
cnt1 = 0
i1 = 0
s *= 2
while i1 < len(s)-1:
  if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 1
  i1 += 1
print((cnt1 - cnt)*(k-1) + cnt)
 import sys sys rr = lambda: sys.stdin.readline().rstrip() rr lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip ri = lambda: int(sys.stdin.readline()) ri lambda: int(sys.stdin.readline()) int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline s = rr() s rr() rr k = ri() k ri() ri cnt = 0 cnt 0 i = 0 i 0 if len(set(s)) == 1:
  print(int(len(s)*k/2))
  exit() len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(int(len(s)*k/2)) print int(len(s)*k/2) int len(s)*k/2 len(s)*k len(s) len s k 2 exit() exit while i < len(s)-1:
  if s[i] == s[i+1]:
    cnt += 1
    i += 1
  i += 1 i < len(s)-1 i len(s)-1 len(s) len s 1 if s[i] == s[i+1]:
    cnt += 1
    i += 1
   s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 cnt += 1 cnt 1 i += 1 i 1 i += 1 i 1 cnt1 = 0 cnt1 0 i1 = 0 i1 0 s *= 2 s 2 while i1 < len(s)-1:
  if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 1
  i1 += 1 i1 < len(s)-1 i1 len(s)-1 len(s) len s 1 if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 1
   s[i1] == s[i1+1] s[i1] s i1 s[i1+1] s i1+1 i1 1 cnt1 += 1 cnt1 1 i1 += 1 i1 1 i1 += 1 i1 1 print((cnt1 - cnt)*(k-1) + cnt) print (cnt1 - cnt)*(k-1) + cnt (cnt1 - cnt)*(k-1) cnt1 - cnt cnt1 cnt k-1 k 1 cnt i1 += 1 1 i1 i = 0 0 i cnt1 += 1 1 cnt1 ri = lambda: int(sys.stdin.readline()) lambda: int(sys.stdin.readline()) ri i += 1 1 i i1 = 0 0 i1 s = rr() rr() s cnt = 0 0 cnt i += 1 1 i cnt += 1 1 cnt i1 += 1 1 i1 rr = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() rr cnt1 = 0 0 cnt1 k = ri() ri() k s *= 2 2 s
import sys

rr = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(sys.stdin.readline())

s = rr()
k = ri()
cnt = 0
i = 0
if len(set(s)) == 1:
  print(int(len(s)*k/2))
  exit()
while i < len(s)-1:
  if s[i] == s[i+1]:
    cnt += 1
    i += 1
  i += 1
cnt1 = 0
i1 = 0
s *= 2
while i1 < len(s)-1:
  if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 1
  i1 += 1
print((cnt1 - cnt)*(k-1) + cnt)

