s = gets.chomp
k = gets.to_i

if s.split('').count(s[0]) == s.size
  puts s.size*k/2
  exit
end

ans = 0
cnt = 1
(s.size-1).times do |i|
  if s[i] == s[i+1]
    cnt += 1
  else
    ans += cnt / 2
    cnt = 1
  end
end
ans += cnt / 2

ans *= k



if s[0] == s[-1]
  i = 0
  while true
    if s[i] != s[i+1]
      break
    end
    i += 1
  end
  j = -1
  while true
    if s[j] != s[j-1]
      break
    end
    j -= 1
  end
  i += 1
  j *= -1
  ans -= ((i/2)+(j/2)-(i+j)/2)*(k-1)
end

puts ans