str = gets.chomp.split("")
mInd = str.length - 1
n = gets.to_i
count = 0
diff = 0
if str[0] == str[mInd] && n % 2 == 0 then
  str.concat(str)
  mInd = 2*mInd + 1
  n = n / 2
end
if str[0] == str[mInd] && n % 2 == 1 then
mInd.times{|c|
  str1 = Marshal.load(Marshal.dump(str))
  if str1[c] == str1[c+1] then
    diff = diff + 1
    str1[c+1] ="1"
  end
    } 
  str.concat(str)
  mInd = 2*mInd + 1
  n = n / 2
end
mInd.times{|c|
  if str[c] == str[c+1] then
    count = count + 1
    str[c+1] = '1'
  end
    }
puts count * n + diff
