
s = gets.chomp.chars
k = gets.to_i

# p s
#
# p (s * 2)
# p (s * 2).chunk_while{|a,b|a==b}.to_a
# p (s * 2).chunk_while{|a,b|a==b}.to_a.map{|a|
#   # return 0 if a.size == 1
#   # return a.size/2 if a.size.even?
#   # return a.size/2 if a.size.odd?
#   if a.size == 1
#     0
#   else
#     a.size/2
#   end
# }
#
res = (s * 2).chunk_while{|a,b|a==b}.to_a.map{|a|
  # return 0 if a.size == 1
  # return a.size/2 if a.size.even?
  # return a.size/2 if a.size.odd?
  if a.size == 1
    0
  else
    a.size/2
  end
}.inject(:+)
result = res * (k/2)
# result += res if k.odd?
# p res
# p res/2
result += res/2 if k.odd?

p result
# p k
# 4 81 8999939997
