s = gets.chomp
k = gets.to_i
n = s.size

x = 0
x += 1 while x < n && s[0] == s[x]

y = 0
y += 1 while y < n && s[0] == s[-y]

c = 1
sum = 0
(n - 1).times do |i|
    if s[i] == s[i+1]
        c += 1
    else
        sum += c / 2
        c = 1
    end
end
sum += c / 2

if x == n
    puts n * k / 2
elsif s[0] == s[-1]
    puts sum * k - (x / 2 + (y - 1) / 2 - (x + y - 1) / 2) * (k - 1)
else
    puts sum * k
end