function Main(arg) {
 
    var K = arg.split("\n")[0];
    var S = arg.split("\n")[1]-0;
 
    var T = K + K[0];
 
    var ans = 0;
    var f = false;
    if (K.length === 1) {
        if (S % 2 === 0) {
            console.log(S/2);            
        }
        else {
            console.log((S-1)/2);            
        }
        return;
    }
 
    for (var i = 1; i < T.length; i++){
        if (T[i - 1] === T[i]) {
            var tmp = T.slice(0, i) + "*" + T.slice(i+1, T.length);
            T = tmp;
            ans++;
            if (i === T.length - 1) f = true;
        }
    }
        
    if (S === 1) {
        console.log(f ? ans * S - 1 : ans * S);
        return;
    }
 
    if (!f) {
        console.log(ans*S);            
    }
    else {
        if (S%2===0) {
            console.log(f ? ans * S - 1 : ans * S);
        }
        else {
            var a = Math.floor((K.length * S) / T.length);
            var b = K.length * S - T.length * a;

            T = K.slice(K.length - b);
            ans = ans * a;
            for (var i = 1; i < T.length; i++){
                if (T[i - 1] === T[i]) {
                    var tmp = T.slice(0, i) + "*" + T.slice(i+1, T.length);
                    T = tmp;
                    ans++;
                    if (i === T.length - 1) f = true;
                }
            }

            console.log(ans);                        
        }
    }
 
    return;
}

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