def main(argv)
  s = gets.chomp
  k = gets.chomp.to_i

  t = s.dup
  c = 0
  (t.size - 1).times do |i|
    if t[i] == t[i + 1] then
      t[i + 1] = '*'
      c += 1
    end
  end

  x = c * k
  if s[0] == s[s.size - 1] then
    a = 0
    while s[a] == s[0] do
      a += 1
    end

    b = 0
    while s[(s.size - 1) - b] == s[s.size - 1] do
      b += 1
    end
    
    y = (a / 2) + (b / 2) - ((a + b) / 2)
    x -= y * (k - 1)
  end
  puts x.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end