fun main(args: Array<String>) {
  val s = readLine()!!.toList()
  val k = readLine()!!.toInt()

  val s1 = s.toMutableList()
  var cnt1 = 0L
  for (i in 1 until s.size) {
    val a = s1[i - 1]
    val b = s1[i]
    if (a == b) {
      s1[i] = '_'
      cnt1++
    }
  }

  val s2 = s.toMutableList()
  s2[0] = '_'
  var cnt2 = 1L
  for (i in 1 until s.size) {
    val a = s2[i - 1]
    val b = s2[i]
    if (a == b) {
      s2[i] = '_'
      cnt2++
    }
  }


  if (k == 1) {
    println(cnt1)
    return
  }
  if (s1.first() != s1.last() || cnt1 == cnt2) {
    println(cnt1 * k)
    return
  }
  if (s1.first() != s2.last()) {
    println((cnt1 + cnt2) * (k / 2) + cnt1 * (k % 2))
  } else {
    println(cnt1 + cnt2 * (k - 1))
  }
}
