def count(st)
  idx=0
  cnt=0
  while true
    break if idx>=st.size
    if idx==0
      if st.size==1
        return 0
      else
        idx+=1
        next
      end
    end
    if st[idx]==st[idx-1]
      cnt+=1
      idx+=1
    end
    idx+=1
  end
  cnt
end
s=gets.chomp
k=gets.to_i
S=s+s
K=k/2
if k==1
  puts count(s)
elsif k.even?
  puts count(S+S[0])*K + (S[-2]!=S[-1] && S[-1]==S[0] ? -1 : 0)
else
  puts count(S+S[0])*K+count(s)
end
