program aaa
implicit none

integer(8) :: k, l, i, j, res, same, ress
character(100) :: s
character(1) :: a

read*, s
read*, k

l=len_trim(s)
s=trim(s)
res=0
same=2
ress=0

if(s(1:1)==s(l:l)) then
 do i=2,l
  if(s(1:1)==s(i:i)) then
  same=same+1
  s(i:i)='#'
  else
  exit
  end if
 end do
 if(same/=l) then
  do i=l-1,2,-1
   if(s(l:l)==s(i:i)) then
   same=same+1
   s(i:i)='#'
   else
   exit
   end if
  end do
 end if
s(1:1)='#'
s(l:l)='#'
ress=ress+same/2
end if

 do i=1,l
  if (s(i:i)/='#') then
   do j=i+1,l
    if(s(i:i)==s(j:j)) then
    res=res+1
    s(j:j)='#'
     if(j/=l) then
      if(s(i:i)/=s(j+1:j+1)) then
      res=res+1
      ress=ress+res/2
      res=0
      end if
     end if
    else
    exit
    end if
   end do
  end if
 end do
    
ress=ress*k

write(*,'(i0)') ress

end program