      PROGRAM connectionAndDisconnection
      IMPLICIT NONE
      character(100) :: s
      INTEGER(16) :: k, ans
      
      INTEGER,allocatable :: flags(:)
      INTEGER :: len, i
      LOGICAL :: lastFlag = .false.
      
      
      read*,s
      READ*,k
      
      len = len_trim( s )
      allocate ( flags(len) )
      flags = 0
      
      
      
      DO i = 1,len-1
        IF( s(i:i)==s(i+1:i+1) )THEN
          flags(i) = 1
          s(i+1:i+1) = 'X'
        END IF
      END DO
      !i = len
      IF( s(len:len)==s(1:1) )THEN
        flags(len) = 1
      END IF
      
      
      IF( flags(len-1)==0 )THEN
        IF( flags(len)==1 )THEN
          lastFlag = .true.
        END IF
      END IF
      
      
      ans = sum( flags(:) ) * k
      IF(lastFlag)THEN
        ans = ans -1
      END IF
      
      IF( len==1 )THEN
        IF( mod(k,2)==0 )THEN
          ans = k/2
        ELSE
          ans = (k-1)/2
        END IF
      END IF
      print*,ans
      
      
      
      END PROGRAM