fun main(args: Array<String>) {
    val str = readLine()!!
    val k = readLine()!!.toInt()
    val str2 = str + str
    val str3 = str2 + str
    val p = str.toCharArray()
    val q = str2.toCharArray()
    val r = str3.toCharArray()

    val x = cntOperationNum(p)
    val y = cntOperationNum(q)
    val z = cntOperationNum(r)

    when {
        y == 2 * x -> println(x.toLong() * k.toLong())
        y - x == z - y -> println(x.toLong() + (y - x).toLong() * (k - 1).toLong())
        z - y == x -> println(y.toLong() * (k / 2).toLong() + (k % 2).toLong() * x.toLong())
    }
}

fun cntOperationNum(s : CharArray) : Int{
    var cnt = 1
    var x = 0
    for (i in 1 until s.size) {
        if (s[i - 1] == s[i]) {
            cnt += 1
        } else {
            x += cnt / 2
            cnt = 1
        }
    }
    x += cnt / 2
    return x
}