import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val s = in.readLine()
    val k = in.readLine().toLong

    val words = split(s)
    val replaceCounts = words.map { word =>
      word.length / 2
    }

    val doubleWords = split(s + s)
    val doubleReplaceCounts = doubleWords.map { word =>
      word.length / 2
    }

    System.out.println(
      if (words.size == doubleWords.size) {
        k * replaceCounts.sum
      } else {
        replaceCounts.head +
        k * replaceCounts.drop(1).dropRight(1).sum +
          (k - 1) * doubleReplaceCounts.drop(replaceCounts.size - 1).head +
          replaceCounts.last
      }
    )
  }

  def split(str: String): List[String] = {
    if (str.isEmpty) {
      Nil
    } else {
      val ch = str.charAt(0)
      str.takeWhile(ch == _) :: split(str.dropWhile(ch == _))
    }
  }
}
