def count (arr1)
  arr = Marshal.load(Marshal.dump(arr1))
  ret = 0
  (arr.length-1).times{|c|
    if arr[c] == arr[c+1] then
      ret = ret + 1
      arr[c+1] ="1"
    end
  }
  return ret
end

str = gets.chomp.split("")
n = gets.to_i
  
if str[0] != str[str.length - 1] then
  puts n*count(str)
else
  len = str.length
  c0 = str[0]
  dropstart = str.drop_while{ |c| c == c0 }
  if dropstart.length == 0 then
    puts len*n/2
  else
  s = len - dropstart.length
  center = dropstart.reverse.drop_while{ |c| c == c0 }
  e = len - s - center.length
  puts (e / 2) + (s / 2) +  ((e+s)/2)*(n-1) + n*count(center)
  end
end
