s = gets.chomp.chars
l = s.length
k = gets.to_i
s << "_"

conts = []
cont = 1
[*1..l].each{|i|
  if s[i] == s[i-1]
    cont += 1
  else
    conts << cont
    cont = 1
  end
}
if conts.length == 1
  ans = conts[0]*k/2
elsif s[0] != s[l-1]
  ans = conts.map{|i|i/2}.inject(:+)
  ans *= k
else
  ans1 = conts.map{|i|i/2}.inject(:+)
  conts.push (conts.pop + conts.shift)
  ans2 = conts.map{|i|i/2}.inject(:+)
  ans = ans1 + ans2 * (k-1)
end
p ans
