function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var s = input[0].split("");
  var K = parseInt(input[1]);
  if(s.length == 1){
     myout(parseInt(K / 2));
    return;
  }
  var output = 0;
  for(var i = 1; i < s.length; i++){
    var mae = s[i - 1];
    var ato = s[i];
    if(i != s.length - 1 && (mae == ato)){
       output++;
      s[i] = -1;
    }else if(i == s.length - 1 && s[0] == s[i]){
		output++;
    }
  }
  myout(output * K);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
