"use strict"

function main(input) {
    const lines = input.split(/\n/);
    let count = 0;
    let line = lines[0];
    line = line + line[0];
    const inter = Number(lines[1]);
    const matches = line.match(/(\w)\1+/g);
    
    if(!matches){
        console.log(0);
        return;
    }
    matches.forEach(str=>{
        count += Math.floor(str.length / 2);
    });

    console.log(count * inter);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));