s=gets.chomp
k=gets.to_i
n=s.size
c=0
i=0
f=true if s.split("").uniq.size==1

if s.size==1
  puts k/2
  exit
end

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
#puts c

if f
  puts (n.odd?)? c*k+k/2 : c*k
  exit
end

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