s = input()
k = int(input())
sign = 1

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
      
  ans = (count+temp_count//2)*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 = temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
      temp_count = 1

  count_2 = temp_count
  
  ans = count*k + ((count_1 + count_2)//2)*(k-1) + (count_1//2) + (count_2//2)

  if sign == 1:
    ans = (k*num_s)//2
    
if num_s == 1:
  ans = k//2
  
print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input sign = 1 sign 1 num_s = len(list(s)) num_s len(list(s)) len list(s) list s count = 0 count 0 temp_count = 1 temp_count 1 count_1 = 0 count_1 0 count_2 = 0 count_2 0 if s[0] != s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
      
  ans = (count+temp_count//2)*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 = temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
      temp_count = 1

  count_2 = temp_count
  
  ans = count*k + ((count_1 + count_2)//2)*(k-1) + (count_1//2) + (count_2//2)

  if sign == 1:
    ans = (k*num_s)//2
     s[0] != s[-1] s[0] s 0 s[-1] s -1 for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
      
   i range(1,num_s) range 1 num_s if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
      
   s[i-1] == s[i] s[i-1] s i-1 i 1 s[i] s i temp_count += 1 temp_count 1 elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
      
   s[i-1] != s[i] s[i-1] s i-1 i 1 s[i] s i count += temp_count//2 count temp_count//2 temp_count 2 temp_count = 1 temp_count 1 ans = (count+temp_count//2)*k ans (count+temp_count//2)*k count+temp_count//2 count temp_count//2 temp_count 2 k elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 = temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
      temp_count = 1

  count_2 = temp_count
  
  ans = count*k + ((count_1 + count_2)//2)*(k-1) + (count_1//2) + (count_2//2)

  if sign == 1:
    ans = (k*num_s)//2
     s[0] == s[-1] s[0] s 0 s[-1] s -1 for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 = temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
      temp_count = 1

   i range(1,num_s) range 1 num_s if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 = temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
      temp_count = 1

   s[i-1] == s[i] s[i-1] s i-1 i 1 s[i] s i temp_count += 1 temp_count 1 elif s[i-1] != s[i]:
      if sign == 1:
        count_1 = temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
      temp_count = 1

   s[i-1] != s[i] s[i-1] s i-1 i 1 s[i] s i if sign == 1:
        count_1 = temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
       sign == 1 sign 1 count_1 = temp_count count_1 temp_count sign = 0 sign 0 elif sign == 0:
        count += temp_count//2
     
       sign == 0 sign 0 count += temp_count//2 count temp_count//2 temp_count 2 temp_count = 1 temp_count 1 count_2 = temp_count count_2 temp_count ans = count*k + ((count_1 + count_2)//2)*(k-1) + (count_1//2) + (count_2//2) ans count*k + ((count_1 + count_2)//2)*(k-1) + (count_1//2) + (count_2//2) count*k + ((count_1 + count_2)//2)*(k-1) + (count_1//2) count*k + ((count_1 + count_2)//2)*(k-1) count*k count k ((count_1 + count_2)//2)*(k-1) (count_1 + count_2)//2 count_1 + count_2 count_1 count_2 2 k-1 k 1 count_1//2 count_1 2 count_2//2 count_2 2 if sign == 1:
    ans = (k*num_s)//2
     sign == 1 sign 1 ans = (k*num_s)//2 ans (k*num_s)//2 k*num_s k num_s 2 if num_s == 1:
  ans = k//2
   num_s == 1 num_s 1 ans = k//2 ans k//2 k 2 print(ans) print ans count = 0 0 count sign = 0 0 sign temp_count += 1 1 temp_count ans = count*k + ((count_1 + count_2)//2)*(k-1) + (count_1//2) + (count_2//2) count*k + ((count_1 + count_2)//2)*(k-1) + (count_1//2) + (count_2//2) ans s = input() input() s temp_count = 1 1 temp_count count_2 = 0 0 count_2 temp_count += 1 1 temp_count k = int(input()) int(input()) k ans = (count+temp_count//2)*k (count+temp_count//2)*k ans ans = (k*num_s)//2 (k*num_s)//2 ans count += temp_count//2 temp_count//2 count temp_count = 1 1 temp_count count_1 = temp_count temp_count count_1 count_1 = 0 0 count_1 count_2 = temp_count temp_count count_2 num_s = len(list(s)) len(list(s)) num_s sign = 1 1 sign count += temp_count//2 temp_count//2 count ans = k//2 k//2 ans temp_count = 1 1 temp_count
s = input()
k = int(input())
sign = 1

num_s = len(list(s))
count = 0
temp_count = 1
count_1 = 0
count_2 = 0

if s[0] != s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      count += temp_count//2
      temp_count = 1
      
  ans = (count+temp_count//2)*k
  
elif s[0] == s[-1]:
  for i in range(1,num_s):
    if s[i-1] == s[i]:
      temp_count += 1
    elif s[i-1] != s[i]:
      if sign == 1:
        count_1 = temp_count
        sign = 0
      elif sign == 0:
        count += temp_count//2
     
      temp_count = 1

  count_2 = temp_count
  
  ans = count*k + ((count_1 + count_2)//2)*(k-1) + (count_1//2) + (count_2//2)

  if sign == 1:
    ans = (k*num_s)//2
    
if num_s == 1:
  ans = k//2
  
print(ans)