def get_int
  gets.chop.to_i
end

def get_ints
  gets.chop.split.map(&:to_i)
end

def get_double
  gets.chop.to_f
end

def get_str
  gets.chop
end

def get_strs
  gets.chop.split
end

def main
  s = get_str
  k = get_int
  if s.size == 1 or s.chars.uniq.size == 1
    puts (s.size * k / 2)
    exit 0
  end
  groups = []
  pre_c = s[0]
  count = 1
  1.upto(s.size - 1) do |i|
    c = s[i]
    if pre_c == c
      count += 1
    else
      if count > 1
        groups << [count, i - count, i]
      end
      count = 1
    end
    pre_c = c
  end
  if count > 1
    groups << [count, s.size - count, s.size]
  end

  ans = 0
  if s[0] != s[-1]
    groups.each do |g|
      ans += (g[0] / 2) * k
    end
    puts ans
  else
    groups.each do |g|
      if g[1] != 0 and g[2] != s.size
        ans += (g[0] / 2) * k
      end
    end
    l = 0
    if groups.size > 1 and groups[0][1] == 0
      l += groups[0][0]
      ans += (groups[0][0] / 2)
    else
      l += 1
    end
    if groups.size > 1 and groups[-1][2] == s.size
      l += groups[-1][0]
      ans += (groups[-1][0] / 2)
    else
      l += 1
    end
    ans += (l / 2) * (k - 1)
    puts ans
  end
end

if __FILE__ == $0
  main
end
