#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=get_nsp
N=S.size
K=gets.to_i
kind={}
S.each do|s|
    kind[s]=1
end
if kind.size==1
    puts N*K/2
    exit
end
cnt=1
ans=0
flag=false
add=0
(N-1).times do|i|
  if S[i]==S[i+1]
      cnt+=1
  else
      unless flag
          add=cnt
          flag=true
          ans+=cnt/2
      else
        ans+=cnt/2*K
      end
      cnt=1
  end
end
if S[N-1]!=S[0]
  ans+=cnt/2*K+add/2*(K-1)
else
    ans+=(cnt+add)/2*(K-1)+cnt/2
end
puts ans