s=gets.chomp
z=s.size
k=gets.to_i
ss=s[0]
r=1
c=0
f=true
(z-1).times do |i|
  if s[i+1]==ss
    r+=1
  else
    g = true if f && r.odd?
    c+=r/2
    r=1
  end
  ss=s[i+1]
end
c+=r/2
if r==z
  p z*k/2
  exit
end
a=c*k
if s[0]==ss && r.odd? && g
  a+=k-1
end
p a
