
fun num(input: String) : Long {
    var i = 0L
    var r = 0L
    var prev = ' '
    input.forEach {
        if (prev != it) {
            r += i / 2
            i = 1
        } else {
            i++
        }
        prev = it
    }
    r += i / 2
    return r
}

fun main(args: Array<String>) {
    val input = readLine()!!
    val k = readLine()!!.toLong()

    val one = num(input)
    val two = num(input.repeat(2))

    val allSame = input.all { it == input.first() }
    if (allSame) {
        println(input.length * k / 2)
    } else {
        println((two - one) * (k - 1) + one)
    }
}

