s = gets.chomp.chars
k = gets.to_i
n = s.size

i = 0
chunk = []
cur = s[i]
cnt = 1
i += 1
i.step(n - 1) do |j|
  if s[j] == cur
    cnt += 1
  else
    chunk << cnt
    cnt = 1
    cur = s[j]
  end
end
chunk << cnt

res = 0
if chunk.size == 1
  res += n * k / 2
else
  if s[0] == s[-1]
    pr = chunk.shift
    su = chunk.pop
    res += pr / 2
    res += su / 2
    res += ((pr + su) / 2) * (k - 1)
  end
  
  chunk.each do |c|
    res += (c / 2) * k
  end
end
puts res