import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val s = readLine()!!
    val k = readLong()

    val runLengthS = runLengthEncode(s)
    if (runLengthS.size == 1) {
        println(s.length * k / 2)
        return
    }

    var ansForS = 0
    for (run in runLengthS) {
        ansForS +=  run.length / 2
    }

    val runLengthSS = runLengthEncode(s + s)
    var ansForSS = 0
    for (run in runLengthSS) {
        ansForSS += run.length / 2
    }

    val diff = ansForSS - ansForS
    println(ansForS + diff * (k - 1))
}

data class RunLength<T>(val value: T, val length: Int)

/** O(s.length) */
//fun runLengthEncode(s: String): List<RunLength<Char>> {
//    if (s.isEmpty()) return emptyList()
//
//    val runLengthList = mutableListOf<RunLength<Char>>()
//    var currentChar = s.first()
//    var length = 1
//    for (c in s.substring(1)) {
//        if (c == currentChar) {
//            length++
//        } else {
//            runLengthList += RunLength(currentChar, length)
//            currentChar = c
//            length = 1
//        }
//    }
//    runLengthList += RunLength(currentChar, length)
//
//    return runLengthList
//}

//fun runLengthEncode(s: CharSequence): List<RunLength<Char>> = s.fold(mutableListOf<RunLength<Char>>()) { acc, value ->
//    if (acc.isNotEmpty() && acc.last().value == value) {
//        acc.last().length++
//    } else {
//        acc += RunLength(value, 1)
//    }
//    acc
//}

fun runLengthEncode(s: CharSequence): List<RunLength<Char>> = s.fold(listOf<RunLength<Char>>()) { acc, value ->
    if (acc.isNotEmpty() && acc.last().value == value) {
        acc.dropLast(1) + acc.last().copy(length = acc.last().length + 1)
    } else {
        acc + RunLength(value, 1)
    }
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)
