import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val s = sc.next()
  val k = sc.nextLong()

  val len = s.length

  var now = s.first()
  var count = 1L
  var ans = 0L
  var flag = true
  var topCount = 1L
  var bottomCount = 1L
  for (i in 1 until len) {
    if (s[i] != now) {
      flag = false
      ans += count / 2
      count = 1L
      now = s[i]
    } else {
      count++
      if (flag) topCount++
    }
  }
  if (count > 1L) ans += count / 2
  now = s.last()
  for (i in len-2 downTo 0) {
    if (now != s[i]) break
    bottomCount++
  }

  if (topCount == len.toLong()) println(len * k / 2)
  else if (s.first() == s.last()) println(ans * k - (topCount / 2 + bottomCount / 2 - (topCount + bottomCount)/2) * (k-1))
  else println(ans * k)

}
