let S = readLine()!.characters.map { String($0) }
let K = Int(readLine()!)!

func minReplacement(s: [String]) -> Int {
  var count = 0
  
  var left = 0
 
  while left < s.count {
    var right = left
    while right < s.count && s[left] == s[right] {
      right += 1
    }
    count += (right - left) / 2
    left = right
  }
  return count
}

if Set(S).count <= 1 {
  print(S.count / 2)
} else {
	let first = minReplacement(S)
	let second = minReplacement(S + S)
  	let diff = second - first
  	print(first + diff * (K - 1))
}
