io = STDIN
s=io.gets.chomp
k=io.gets.to_i
def div(str)
  str.each_byte.chunk_while{|x,y|x==y}.map{|ar|ar.size}
end
def cnt(struct)
  struct.map{|i|i/2}.inject(:+)
end
if s.size==1
  puts cnt(div(s*k))
elsif s.split(//).uniq.size==1
  puts cnt([s.size*k])
elsif s[0]==s[-1]
  struct=div(s)
  left=struct[0..-2]
  mid=struct[1..-2]
  right=struct[1..-1]
  if k==1
    puts cnt(div(s))
  elsif k==2
    puts cnt(left)+cnt(right)+cnt([left[0]+right[-1]])
  else
    connect=left[0]+right[-1]
    puts cnt(left)+cnt([connect]+right)+cnt([connect]+mid)*(k-2)
  end
else
  puts cnt(div(s))*k
end
