S=gets.chomp
K=gets.to_i
mark=S[0]
cnt=1
ms=Array.new
if S.codepoints.uniq.size==1
  puts S.size*K/2
  exit
end
for i in 1..S.size-1
  if i!=S.size-1
    if S[i]==mark
      cnt+=1
    else
      ms << cnt
      cnt=1
      mark=S[i]
    end
  else
    if S[i]==mark
      ms << cnt+1
    else
      ms << cnt
      ms << 1
    end
  end
end
ans=ms.map{|e|e/2}.inject(:+)*K
if S[0]==S[-1]
  ans+=(ms[0]+ms[-1])/2*(K-1)-(ms[0]/2)*(K-1)-(ms[-1]/2)*(K-1)
end
puts ans