s = gets.chomp.split('')
k = gets.chomp.to_i

def c(a)
  arr = []
  count = 0
  a.size.times do |t|
    if t > 0 && a[t] != a[t-1]
      arr.push(count)
      count = 1
    else
      count += 1
      arr.push(count) if t == a.size - 1
    end
  end
  ans = 0
  arr.each do |i|
    ans += i / 2
  end
  ans
end

if s.all? { |t| t == s[0] } # 全部一緒
  p (s.size * k) / 2
  exit
elsif s.first == s.last
  f_ind = nil
  1.upto(s.size - 1) do |i|
    if s.first != s[i]
      f_ind = i
      break
    end
  end
  new_arr = s[f_ind..s.size-1] + s[0...f_ind]
  p (f_ind / 2) + c(new_arr) * (k-1) + c(s[f_ind..s.size-1])
  exit
else
  p c(s) * k
end