def sum(s,k)
  first=s[0]
  if s.split('').all?{|c| c==s[0] }
    puts s.length*k/2
  else
    top=1
    s.each_char.with_index do |c,i|
      next if i == 0
      if c==s[i-1]
        top+=1
      else
        break
      end
    end
    bot=1
    rs=s.reverse
    rs.each_char.with_index do |c,i|
      next if i == 0
      if c==rs[i-1]
        bot+=1
      else
        break
      end
    end
    cnt=0
    for i in 0..s.length
      n=1
      for j in 0..s.length
        if s[i] == s[j]
          n+=1
        else
          break
        end
      end
      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
      puts all
    end
  end
end

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