s = gets.chomp.split("")
k = gets.to_i
ln = s.length

cnt = 0
first = last = 0
tmp = 0
for i in 1..(ln-1)
  if s[i-1] == s[i]
    tmp += 1
  elsif tmp > 0
    cnt += (tmp+1) / 2
    first = tmp+1 if first == 0
    tmp = 0
  else
    first = 1 if first == 0
  end
end
cnt += (tmp+1) / 2 if tmp > 0
cnt *= k
last = tmp+1

if s[0] == s[ln-1]
  if ((first/2) + (last/2)) != (first+last)/2
    cnt += (k-1) * (((first+last)/2) - ((first/2) + (last/2)))
  end
end
puts cnt