S = gets.chomp
K = gets.to_i

single = S.chars.slice_when{|a,b|a!=b}.map(&:size)
double = (S+S).chars.slice_when{|a,b|a!=b}.map(&:size)

single_num = single.map{|v|v/2}.inject(:+)
double_num = double.map{|v|v/2}.inject(:+)

if single.size == 1
    puts S.size * K / 2
elsif single.size * 2 == double.size
    puts single_num * K
else
    puts single_num + (double_num - single_num) * (K - 1)
end
