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

    val ss = matcher(s ++ s)
    val ans = ss.count(_ == '_') * k / 2
    println(ans)
  }

  import scala.collection.mutable
  def matcher(xs: String): mutable.Buffer[Char] = {
    val buf = xs.toBuffer
    (1 until buf.length).foreach(i => {
      if (buf(i - 1) == buf(i)) {
        buf.update(i, '_')
      }
    })
    buf
  }
}