local s=io.read()
local k=io.read("n")

local t={}
for i=1,#s do
    t[i]=s:sub(i,i)
end
t[#s+1]=s:sub(1,1)

local counter=0
for i=1,#s do
    if t[i]==t[i+1] then
        t[i+1]=0
        counter=counter+1
    end
end
print(counter*k)