S = gets.chomp!
K = gets.to_i

if S.size == 1
  puts K / 2
  exit
end

count = 0
past = ''
S.each_char.with_index do |c, i|
  if past != c && c == S[i + 1]
    count += 1
    past = c
  else
    past = ''
  end
end


if S[0] == S[-1]
  a = 0
  S.each_char do |c|
    if c == S[0]
      a += 1
    else
      break
    end
  end
  b = 0
  S.each_char.reverse_each do |c|
    if c == S[-1]
      b += 1
    else
      break
    end
  end

  puts count * K - (((a/2 + b/2 - (a+b) / 2)) * (K - 1))
else
  puts count * K
end
