s = gets.chomp
k = gets.chomp.to_i


# besides a, b
def alphabet(a, b)
  ("a".."z").each do |c|
    return c if a != c && b != c
  end
end

count = 0

s2 = s.dup

s.size.times do |i|
  next if i == 0
  if s[i] == s[i-1]
    count+=1
    if i+1 < s.size
      s[i] = alphabet(s[i-1], s[i+1])
    else
      s[i] = alphabet(s[i-1], s[0])
    end
  end
end

s2_count = 0

s2.size.times do |i|
  before = if i == 0
    s[-1]
  else
    s2[i-1]
  end
  after = if i+1 < s2.size
    s2[i+1]
  else
    s[0]
  end
  if before == s2[i]
    s2_count+=1
    s2[i] = alphabet(before, after)
  end
end

if s[0] == s[-1]
  l = k / 2
  m = k - l
  puts s2_count * l + count * m
else
  puts count * k
end
