/**
 * agc039a
 * A - Connection and Disconnection
 */

fun main(args: Array<String>){
	val s: String = readLine()!!.toString()
	val k = readLine()!!.toInt()
	println(agc039a(s, k))
}

fun agc039a(s: String, k: Int): Long{
	val s1 = opeCounter(s, 1)
	val s2 = opeCounter(s, 2)
	val s3 = opeCounter(s, 3)
	val d1 = s2 - s1
	val d2 = s3 - s2
	val d = d1 + d2

	var ans: Long
	if(d1 == d2) ans = s1 + d1 * (k-1)
	else
		if(k%2 != 0) ans = s1 + d * ((k+2-1)/2-1) //(k/2):roundup
		else ans = s2 + d * (k/2-1)
	return ans;
}

fun opeCounter(s: String, k:Int): Long{
	var t = s
	for(i in 1..k-1) t += s
	var c = 0L
	var i = 1
	while(i<t.length){
		if(t[i-1] == t[i]){ c++; i++ }
		i++
	}
	return c;
}