object Main {
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val s = sc.next.toBuffer
    val k = sc.nextLong
    sc.close()

    var count = 0
    (1 until s.length).foreach(i => {
      if (s(i - 1) == s(i)) {
        s.update(i, '_')
        count += 1
      }
    })
    println(count * k)
  }
}