"use strict"

const arg_str = require('fs').readFileSync('/dev/stdin', 'UTF-8')
const arg = arg_str.split('\n')
const S = arg[0]
const K = parseInt(arg[1])

let T = S.split('')
let T_org = T.map(x=>x)

let result = 0

let T_only_1_type = true
let T_temp = ''
for(let i=1;i<=T.length;i++){
  if(T_temp == T[i]){
  }else if(!!T_temp && !!T[i]){
    T_only_1_type = false
    break
  }else{
    T_temp = T[i]
  }
}

if(!T_only_1_type){
  for(let i=0;i<T.length;i++){
      let a = i > 0 ? T[i-1] : T[T.length-1]
      let b = T[i]
      if(a == b){
          T[i] = 'X'
          result++
      }
  }
  result *= K
  if(T_org[0] == T_org[T.length-1]) result--
}else{
  const TK = T.length * K
  result += TK % 2 == 0 ? TK / 2 : (TK - 1) / 2
}

console.log(result)