s = gets.chomp!.to_s
k = gets.chomp!.to_i

#s = s * k
p = 0
count = 0

ls = s.split("")
n = ls.length-1

#p ls
#

#接続について計算してしまう => 再帰をなくす
#再帰を簡単な数式で代用(S<=100)
=begin
def check(ls, p, count)
  if p >= ls.length-1
    return count
  end
  if ls[p] == ls[p+1]
    p += 2
    count += 1
    check(ls, p, count)
  else
    p += 1
    check(ls, p, count)
  end
end
=end
i=0
while i <= n-1
  if ls[i]==ls[i+1]
    count+=1
    i+=2
  else
    i+=1
  end
end

c=count
#c = check(ls, p, count)



if ls[0] == ls[n]
  if ls[n] == ls[n-1]
    c = c*k
  else
    c = c*k + (k-1)
  end
else
  c = c * k
end

p c