"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    const K = parseInt(arg[1]);

    let streakS = 0;
    
    if(S.length === 1) {
        console.log(Math.floor(K / 2));
        return;
    }
    
    // まずSの連続箇所を調べる
    for(let i=1; i<S.length; i++) {
        // 連続している
        if(S[i] === S[i-1]) {
            streakS++;
            S[i] = "@";
        }
    }
    
    let first = S[0];
    let last  = S[S.length-1];
    
    let answer = streakS * K;
    
    if(first === last) {
        answer += K - 1;
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));