const lineList = require('fs').readFileSync('/dev/stdin','utf8').trim().split('\n')

const s = lineList[0]
const k = parseInt(lineList[1])

var currentBlockCharcter = ''
var currentBlockSize = 0
var blockList = []

for(var i=0;i<s.length;i++) {
  if(currentBlockCharcter !== s[i]) {
    currentBlockSize ?  blockList.push([currentBlockCharcter, currentBlockSize]) : null
    currentBlockCharcter = s[i]
    currentBlockSize = 1
  } else {
    currentBlockSize += 1
  }
}

blockList.push([currentBlockCharcter, currentBlockSize])

var timesOfRewrite = 0
for(var i=0;i<blockList.length;i++) {
  var block = blockList[i]
  timesOfRewrite += (block[1] - block[1] % 2) / 2
}

total = timesOfRewrite * k

var headBlock = blockList[0]
var tailBlock = blockList[blockList.length-1]
if(headBlock[0] === tailBlock[0] && headBlock[1] % 2 === 1 && tailBlock[1] % 2 === 1) {
  total += 1
}

if(s.length === 1) {
  total = (k - k % 2) / 2
}

console.log(total)
