def sum(s,k)
  first=s[0]
  if s.split('').all?{|c| c==s[0] }
    puts s.length*k/2
  else
    top=0
    s.each_char.with_index do |c,i|
      next if i == 0
      if c==s[i-1]
        top+=1
      else
        next
      end
    end
    bot=0
    rs=s.reverse
    rs.each_char.with_index do |c,i|
      break if i==s.length-2
      if c==rs[i+1]
        bot+=1
      else
        next
      end
    end
    cnt=0
    s.each_char.with_index do |c,i|
      next if i ==0
      if c == s[i-1]
        s[i]='0'
        cnt+=1
      end
    end
    all=cnt*k
    if first == s[s.length-1]
      a=(top+bot)/2
      b=top/2+(bot/2)
      all-=a-b*(k-1)
      puts all
    else
      puts all
    end
  end
end
 
sum(gets.chomp, gets.chomp.to_i)