function Main(input) {
  input.trim();
  input = input.split("\n");
var S = input[0].split("");
var K = input[1];
  var Count = 1;
  var Change = 0;
for(var i=0;i<S.length;i++){
  if(S[i] == S[i+1]){
    Count ++;
  }else{
    Change += Math.floor(Count/2);
    Count = 1;
  }
}
  console.log(Change)
Change *= K;
if(S[0] == S[S.length-1]){
  Change += Number(K);
}
  console.log(Change);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));