def f(s, k)
  all_same = true
  for i in 1...s.size
    if s[i-1] != s[i]
      all_same = false
    end
  end

  if all_same
    return (s.size / 2).to_i * k
  elsif s[0] == s[-1]
    head_count = 1
    for i in 1...s.size
      if s[i-1] != s[i]
        break
      end
      head_count += 1
    end

    tail_count = 1
    for i in 1...s.size
      if s[-i-1] != s[-i]
        break
      end
      tail_count += 1
    end

    same = 0
    for i in (head_count + 1)...(s.size - tail_count)
      if s[i-1] == s[i]
        same += 1
        if (i - 2) < 0 || (s[i-2] != s[i])
          same += 1
        end
      end
    end

    return (same / 2).to_i * k + ((head_count + tail_count) / 2).to_i * (k - 1) + (head_count / 2).to_i + (tail_count) / 2.to_i
  else
    same = 0
    for i in 1...s.size
      if s[i-1] == s[i]
        same += 1
        if (i - 2) < 0 || (s[i-2] != s[i])
          same += 1
        end
      end
    end
    return (same / 2).to_i * k
  end
end


s = gets.strip
k = gets.to_i
puts f(s, k)
