s = gets.chomp.chars
k = gets.to_i
res = 0

pre = s.shift
pcnt = 1
while !s.empty? && pre == s[0]
  s.shift
  pcnt += 1
end

if s.empty?
  res += k * (pcnt / 2)
  puts res
  exit
end

suf = s.pop
scnt = 1
while !s.empty? && suf == s[-1]
  s.pop
  scnt += 1
end

res += pcnt / 2 + scnt / 2
if pre == suf
  res += (k - 1) * (pcnt + scnt) / 2
end

i = 0
while i < s.size - 1
  j = i
  while s[i] == s[j] && j < s.size
    j += 1
  end
  res += ((j - i) / 2) * k
  i = j
end
puts res