s=gets.chomp
k=gets.to_i
n=s.size
c=0
i=0

while i<n-1
  if s[i]==s[i+1]
    if i<n-2 and s[i+1]==s[i+2]
      i+=1
    end
    c+=1
  end
  i+=1
end
if k==1
  puts c
  exit
end

a=c*k
if s[0]==s[-1]
  i=0
  j=0
  i+=1 while i<n-2 and s[i]==s[i+1]
  j-=1 while j>-n+2 and s[j]==s[j-1] 
  if (i+j.abs).odd?
    a-=k/2
  end
end
puts a