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

func minReplacement(s: [String]) -> Int {
  var str = s
  var replace = 0
  for i in 0..<str.count {
  	if i == 0 {
    	continue
  	}
  	if str[i-1] == str[i] {
    	replace += 1
    	let nothing = "z".unicodeScalars.first!.value + 1
    	str[i] = String(Character(UnicodeScalar(nothing)))
  	}
  }
  return replace
}

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