s = gets.chomp
t = s+s
k = gets.to_i
n = s.size
f = true
(n-1).times do |i|
    f = false if s[i] != s[i+1]
end
if f
    puts (n*k)/2
    exit
end
if s[0] == s[-1]
    ans = 0
    a = 1
    b = 1
    n.times do |i|
        if s[i] == s[i+1]
            a += 1
        else
            break
        end
    end
    n.times do |j|
        i = n-1-j
        if s[i] == s[i-1]
            b += 1
        else
            break
        end
    end
    ans += a/2
    ans += b/2
    ans += (a+b)/2*(k-1)
    c = 1
    (a..(n-b-2)).each do |i|
        if s[i] == s[i+1]
            c += 1
        else
            if c > 1
                ans += c/2*k
            end
            c = 1
        end
    end
    ans += c/2*k
    puts ans
else
    ans = 0
    c = 1
    (0..(n-1)).each do |i|
        if s[i] == s[i+1]
            c += 1
        else
            if c > 1
                ans += c/2*k
            end
            c = 1
        end
    end
    ans += c/2*k
    puts ans
end