s = gets.chomp
k = gets.to_i

counts = []
pre = nil
cnt = 1
s.chars.each do |c|
  if pre == nil
    pre = c
  elsif pre == c
    cnt += 1
  else
    counts << cnt
    pre = c
    cnt = 1
  end
end
counts << cnt

ans = 0
if counts.size == 1
  ans = counts[0] * k / 2
elsif s[0] == s[-1]
  counts[1..-2].each { |t| ans += t / 2}
  ans *= k
  ans += (counts[0] + counts[-1]) / 2 * (k - 1)
  ans += counts[0] / 2
  ans += counts[-1] / 2
else
  counts.each { |t| ans += t / 2 }
  ans = ans * k
end
puts ans