def sum(s,k)
  first=s[0]
  if s.split('').all?{|c| c==s[0] }
    puts s.length*k/2
  else
    top=0
    bot=0
    cnt=0
    i=0
    while i < s.length
      n=1
      for j in (i+1)..s.length
        if s[i] == s[j]
          n+=1
        else
          break
        end
      end
      if i.zero?
        top = n
        i+=n
        next
      end
      if i + n >= s.length
        bot = n
        i+=n
        next
      end
      i+=n
      cnt += n/2
    end
    all=cnt*k
    if first == s[s.length-1]
      a=(top+bot)/2*(k-1)
      b=top/2+(bot/2)
      all+=a+b
      puts all
    else
      all+=k*(top/2+(bot/2))
      puts all
    end
  end
end

sum(gets.chomp, gets.chomp.to_i)