def input_list():
  return list(map(int, input().split()))


def main():
  s = list(input())
  k = int(input())
  if len(set(s)) == 1:
    print(int(len(s)*(k/2)))
    exit()
  
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji % 2 == 0:
      print(a * k + (k-1))
      exit()
  print(ans - b)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main() def input_list():
  return list(map(int, input().split())) input_list return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def main():
  s = list(input())
  k = int(input())
  if len(set(s)) == 1:
    print(int(len(s)*(k/2)))
    exit()
  
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji % 2 == 0:
      print(a * k + (k-1))
      exit()
  print(ans - b)
   main s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
    print(int(len(s)*(k/2)))
    exit()
  
   len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(int(len(s)*(k/2))) print int(len(s)*(k/2)) int len(s)*(k/2) len(s) len s k/2 k 2 exit() exit sw = [s[0]] sw [s[0]] s[0] s 0 num = 0 num 0 numbers = [num] numbers [num] num for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

   i range(1, len(s)) range 1 len(s) len s if s[i-1] != s[i]:
      num += 1
     s[i-1] != s[i] s[i-1] s i-1 i 1 s[i] s i num += 1 num 1 numbers.append(num) numbers.append numbers append num if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

   num == 0 and sw[0] == s[i] num == 0 num 0 sw[0] == s[i] sw[0] sw 0 s[i] s i sw.append(s[i]) sw.append sw append s[i] s i num = 0 num 0 end_w = s[-1] end_w s[-1] s -1 ew = [] ew [] for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
   i range(len(s)-1, -1, -1) range len(s)-1 len(s) len s 1 -1 -1 if end_w != s[i]:
      num += 1
     end_w != s[i] end_w s[i] s i num += 1 num 1 if num == 0 and end_w == s[i]:
      ew.append(s[i])
   num == 0 and end_w == s[i] num == 0 num 0 end_w == s[i] end_w s[i] s i ew.append(s[i]) ew.append ew append s[i] s i nc = collections.Counter(numbers) nc collections.Counter(numbers) collections.Counter collections Counter numbers a = 0 a 0 for n,c in nc.items():
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
   n c nc.items() nc.items nc items if c == 1:
      continue
     c == 1 c 1 continue if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
   c % 2 == 0 c % 2 c 2 0 a += c // 2 a c // 2 c 2 a += (c-1)//2 a (c-1)//2 c-1 c 1 2 ans = a * k ans a * k a k b = 0 b 0 if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji % 2 == 0:
      print(a * k + (k-1))
      exit()
   ew[0] == sw[0] ew[0] ew 0 sw[0] sw 0 haji = len(sw) + len(ew) haji len(sw) + len(ew) len(sw) len sw len(ew) len ew if haji % 2 == 0:
      print(a * k + (k-1))
      exit()
   haji % 2 == 0 haji % 2 haji 2 0 print(a * k + (k-1)) print a * k + (k-1) a * k a k k-1 k 1 exit() exit print(ans - b) print ans - b ans b import math math import fractions fractions import collections collections import itertools itertools from functools import reduce main() main def input_list():
  return list(map(int, input().split())) def input_list():
  return list(map(int, input().split())) input_list def main():
  s = list(input())
  k = int(input())
  if len(set(s)) == 1:
    print(int(len(s)*(k/2)))
    exit()
  
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji % 2 == 0:
      print(a * k + (k-1))
      exit()
  print(ans - b)
   def main():
  s = list(input())
  k = int(input())
  if len(set(s)) == 1:
    print(int(len(s)*(k/2)))
    exit()
  
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji % 2 == 0:
      print(a * k + (k-1))
      exit()
  print(ans - b)
   main
def input_list():
  return list(map(int, input().split()))


def main():
  s = list(input())
  k = int(input())
  if len(set(s)) == 1:
    print(int(len(s)*(k/2)))
    exit()
  
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji % 2 == 0:
      print(a * k + (k-1))
      exit()
  print(ans - b)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()