fun main(args: Array<String>) {
    val S = readInputLine().toCharArray()
    val K = readInputLine().toLong()
    val S_ = S.copyOf()

    var allSame = true

    for (i in 1 until S.size) {
        if (S[i] != S[i - 1]) {
            allSame = false
            break
        }
    }
    if (allSame) {
        println(S.size * K / 2L)
        return
    }

    var concurrentCnt = 0L

    for (i in 1 until S.size) {
        if (S_[i] == S_[i - 1]) {
            concurrentCnt++
            S_[i] = '*'
        }
    }

    if (S[S.size - 1] == S[0]) {
        var header = 1L
        for (i in 1 until S.size) {
            if (S[i] == S[i - 1]) {
                header++
            } else {
                break
            }
        }
        var footer = 1L
        for (i in S.size - 2 downTo 0) {
            if (S[i] == S[i + 1]) {
                footer++
            } else {
                break
            }
        }

        println(concurrentCnt * K - (K - 1) * (header / 2L + footer / 2L - (header + footer) / 2L))
    } else {
        println(concurrentCnt * K)
    }
}

fun readInputLine(): String {
    return readLine()!!
}
