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

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

local a=0
local b=0
if t[1]==t[#s] then
    for i=1,#s do
        a=a+1
        if t[i]~=t[i+1] then
            break
        end
    end
    for i=#s,1,-1 do
        b=b+1
        if t[i]~=t[i-1] then
            break
        end
    end
end

local c=0
for i=1,#s-1 do
    if t[i]==t[i+1] then
        t[i+1]=0
        c=c+1
    end
end

if a==#s then
    print(#s*k//2)
elseif a==0 then
    print(c*k)
else
    print(c*k-(a//2+b//2-(a+b)//2)*(k-1))
end