def check(s)
	i = 0
	count = 0
	while i < s.length
		j = i + 1
		while s[i] == s[j]
			j = j + 1
		end
		diff = j - i
		if diff > 1 then
			count = count + diff
		end
		i = j
	end
	return count
end

s = gets.chomp
k = gets.to_i

count = s.count(s[0])
if count == s.length then
	print(count * k / 2)
elsif s[0] == s[-1] then
	ca = check(s)
	cb = check(s[-1] + s)
	count = (ca / 2 * k) - (ca / 2 + cb / 2 - (ca + cb) / 2) * (k - 1)
	print(count)
else
	count = check(s)
	print(count / 2 * k)
end