fun countSame(S: String): Long {
    var same = 0L
    var rep = 0L
    var c = (0).toChar()
    for (s in S) {
        if (s == c) rep++
        else {
            c = s
            same += (rep + 1) / 2
            rep = 0
        }
    }
    same += (rep + 1) / 2
    return same
}
fun main(args: Array<String>) {
    val S = next()
    val K = nextLong()
    val one = countSame(S)
    val two = countSame(S.repeat(2))
    if (S.all { it == S[0] }) {
        println(S.length * K / 2)
    } else {
        println(one + (two - one) * (K - 1))
    }
}
fun next() = readLine()!!
fun nextLong() = next().toLong()