s = gets.chomp
k = gets.to_i

c = s[0]
count = 1
count_arr = []
1.upto(s.size - 1) do |i|
  if c == s[i]
    count += 1
  else
    count_arr << count
    count = 1
  end
  c = s[i]
end

count_arr << count

ans = 0
count_arr.each do |count|
  ans += (count / 2) * k
end

if s.size > 1 && s[0] == s[-1] && count_arr[-1] % 2 == 1
  ans += k - 1
end

puts ans