import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def cnt(s: String): Long = {
    var cnt = 0L
    var prev = '.'
    s.foreach { c =>
      if (prev == c) {
        cnt += 1
        prev = '.'
      } else {
        prev = c
      }
    }
    cnt
  }

  def solve(sc: Scanner): String = {
    val S = sc.next
    val K = sc.nextInt

    val c1 = cnt(S)
    val c2 = cnt(S + S)

    ((K / 2) * c2 + (K % 2) * c1).toString
  }
}
