var str = readLine()!.characters.map { String($0) }

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)))
  }
}
replace *= Int(readLine()!)!
if str.first! == str.last! {
  replace += str.count - 1
}
print(replace)