import sys

s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline())
cnt = 0
i = 0
l = len(s)
if len(set(s)) == 1:
  print(int(l*k/2))
  exit()
while i < l-1:
  if s[i] == s[i+1]:
    cnt += 1
    i += 2
    continue
  i += 1
cnt1 = 0
i1 = 0
s *= 2
while i1 < l*2-1:
  if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 2
    continue
  i1 += 1
print((cnt1 - cnt)*(k-1) + cnt)
 import sys sys s = sys.stdin.readline().rstrip() s sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip k = int(sys.stdin.readline()) k int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline cnt = 0 cnt 0 i = 0 i 0 l = len(s) l len(s) len s if len(set(s)) == 1:
  print(int(l*k/2))
  exit() len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(int(l*k/2)) print int(l*k/2) int l*k/2 l*k l k 2 exit() exit while i < l-1:
  if s[i] == s[i+1]:
    cnt += 1
    i += 2
    continue
  i += 1 i < l-1 i l-1 l 1 if s[i] == s[i+1]:
    cnt += 1
    i += 2
    continue
   s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 cnt += 1 cnt 1 i += 2 i 2 continue i += 1 i 1 cnt1 = 0 cnt1 0 i1 = 0 i1 0 s *= 2 s 2 while i1 < l*2-1:
  if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 2
    continue
  i1 += 1 i1 < l*2-1 i1 l*2-1 l*2 l 2 1 if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 2
    continue
   s[i1] == s[i1+1] s[i1] s i1 s[i1+1] s i1+1 i1 1 cnt1 += 1 cnt1 1 i1 += 2 i1 2 continue 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 l = len(s) len(s) l i += 2 2 i i1 += 2 2 i1 k = int(sys.stdin.readline()) int(sys.stdin.readline()) k cnt = 0 0 cnt cnt1 = 0 0 cnt1 cnt += 1 1 cnt i += 1 1 i i = 0 0 i s *= 2 2 s s = sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() s cnt1 += 1 1 cnt1 i1 = 0 0 i1
import sys

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

