s=input()
k=int(input())
n=len(s)
counter=1
allsame=0
samefirst=1
samelast=1
firstletter=''
lastletter='.'
for i in range(n):
  if s[i]!=s[0]:
    firstletter=s[i]
    samefirst=i
    break
  if i==n-1:
    allsame=1
for i in range(n):
  if s[n-i-1]!=s[n-1]:
    lastletter=s[n-i-1]
    samelast=i
    break
  if i==n-1:
    allsame=1
anstemp=0
previousletter=s[samefirst-1]
for i in range(samefirst,n-samelast+1):
  currentletter=s[i]
  if currentletter==previousletter:
    counter+=1
  else:
    anstemp+=counter//2
    counter=1
    previousletter=currentletter
if allsame==1:
  print((k*n)//2)
elif firstletter==lastletter:
  print(anstemp*k+samefirst//2+samelast//2+(k-1)*((samefirst+samelast)//2))
else:
  print((anstemp+samefirst//2+samelast//2)*k) s=input() s input() input k=int(input()) k int(input()) int input() input n=len(s) n len(s) len s counter=1 counter 1 allsame=0 allsame 0 samefirst=1 samefirst 1 samelast=1 samelast 1 firstletter='' firstletter '' lastletter='.' lastletter '.' for i in range(n):
  if s[i]!=s[0]:
    firstletter=s[i]
    samefirst=i
    break
  if i==n-1:
    allsame=1 i range(n) range n if s[i]!=s[0]:
    firstletter=s[i]
    samefirst=i
    break
   s[i]!=s[0] s[i] s i s[0] s 0 firstletter=s[i] firstletter s[i] s i samefirst=i samefirst i break if i==n-1:
    allsame=1 i==n-1 i n-1 n 1 allsame=1 allsame 1 for i in range(n):
  if s[n-i-1]!=s[n-1]:
    lastletter=s[n-i-1]
    samelast=i
    break
  if i==n-1:
    allsame=1 i range(n) range n if s[n-i-1]!=s[n-1]:
    lastletter=s[n-i-1]
    samelast=i
    break
   s[n-i-1]!=s[n-1] s[n-i-1] s n-i-1 n-i n i 1 s[n-1] s n-1 n 1 lastletter=s[n-i-1] lastletter s[n-i-1] s n-i-1 n-i n i 1 samelast=i samelast i break if i==n-1:
    allsame=1 i==n-1 i n-1 n 1 allsame=1 allsame 1 anstemp=0 anstemp 0 previousletter=s[samefirst-1] previousletter s[samefirst-1] s samefirst-1 samefirst 1 for i in range(samefirst,n-samelast+1):
  currentletter=s[i]
  if currentletter==previousletter:
    counter+=1
  else:
    anstemp+=counter//2
    counter=1
    previousletter=currentletter i range(samefirst,n-samelast+1) range samefirst n-samelast+1 n-samelast n samelast 1 currentletter=s[i] currentletter s[i] s i if currentletter==previousletter:
    counter+=1
  else:
    anstemp+=counter//2
    counter=1
    previousletter=currentletter currentletter==previousletter currentletter previousletter counter+=1 counter 1 anstemp+=counter//2 anstemp counter//2 counter 2 counter=1 counter 1 previousletter=currentletter previousletter currentletter if allsame==1:
  print((k*n)//2)
elif firstletter==lastletter:
  print(anstemp*k+samefirst//2+samelast//2+(k-1)*((samefirst+samelast)//2))
else:
  print((anstemp+samefirst//2+samelast//2)*k) allsame==1 allsame 1 print((k*n)//2) print (k*n)//2 k*n k n 2 elif firstletter==lastletter:
  print(anstemp*k+samefirst//2+samelast//2+(k-1)*((samefirst+samelast)//2)) firstletter==lastletter firstletter lastletter print(anstemp*k+samefirst//2+samelast//2+(k-1)*((samefirst+samelast)//2)) print anstemp*k+samefirst//2+samelast//2+(k-1)*((samefirst+samelast)//2) anstemp*k+samefirst//2+samelast//2 anstemp*k+samefirst//2 anstemp*k anstemp k samefirst//2 samefirst 2 samelast//2 samelast 2 (k-1)*((samefirst+samelast)//2) k-1 k 1 (samefirst+samelast)//2 samefirst+samelast samefirst samelast 2 print((anstemp+samefirst//2+samelast//2)*k) print (anstemp+samefirst//2+samelast//2)*k anstemp+samefirst//2+samelast//2 anstemp+samefirst//2 anstemp samefirst//2 samefirst 2 samelast//2 samelast 2 k firstletter=s[i] s[i] firstletter allsame=0 0 allsame previousletter=s[samefirst-1] s[samefirst-1] previousletter previousletter=currentletter currentletter previousletter lastletter=s[n-i-1] s[n-i-1] lastletter samelast=i i samelast counter+=1 1 counter s=input() input() s firstletter='' '' firstletter anstemp=0 0 anstemp counter=1 1 counter allsame=1 1 allsame k=int(input()) int(input()) k allsame=1 1 allsame anstemp+=counter//2 counter//2 anstemp samefirst=i i samefirst samefirst=1 1 samefirst samelast=1 1 samelast currentletter=s[i] s[i] currentletter n=len(s) len(s) n counter=1 1 counter lastletter='.' '.' lastletter
s=input()
k=int(input())
n=len(s)
counter=1
allsame=0
samefirst=1
samelast=1
firstletter=''
lastletter='.'
for i in range(n):
  if s[i]!=s[0]:
    firstletter=s[i]
    samefirst=i
    break
  if i==n-1:
    allsame=1
for i in range(n):
  if s[n-i-1]!=s[n-1]:
    lastletter=s[n-i-1]
    samelast=i
    break
  if i==n-1:
    allsame=1
anstemp=0
previousletter=s[samefirst-1]
for i in range(samefirst,n-samelast+1):
  currentletter=s[i]
  if currentletter==previousletter:
    counter+=1
  else:
    anstemp+=counter//2
    counter=1
    previousletter=currentletter
if allsame==1:
  print((k*n)//2)
elif firstletter==lastletter:
  print(anstemp*k+samefirst//2+samelast//2+(k-1)*((samefirst+samelast)//2))
else:
  print((anstemp+samefirst//2+samelast//2)*k)