S = input()
K = int(input())
 
INNER = 0
  
if len(set(list(S))) == 1:
  print(K*len(S)//2)
else: 
  i = 0
  while i < len(S)-1:
    if S[i] == S[i+1]:
      INNER += 1
      i += 1
    i += 1
  
  if (S[0] != S[-1]):#最初の文字と最後の文字が違うなら、
    print(INNER*K)
  else:
    same_from_start = 0
    same_from_end = 0
    
    count_from_start = 0
    count_from_end = 0
    
    flag_same_from_start = 0
    flag_same_from_end = 0
    
    while flag_same_from_start == 0:
      if S[count_from_start] == S[count_from_start+1]:
        count_from_start += 1
      else:
        count_from_start += 1
        flag_same_from_start = 1
    
    while flag_same_from_end == 0:
      if S[len(S)-count_from_end-1] == S[len(S)-count_from_end-2]:
        count_from_end += 1
      else:
        count_from_end += 1
        flag_same_from_end = 1
    print(INNER*K + (K -1) * ((count_from_start+count_from_end)//2 -\
                              count_from_start//2- count_from_end//2)) S = input() S input() input K = int(input()) K int(input()) int input() input INNER = 0 INNER 0 if len(set(list(S))) == 1:
  print(K*len(S)//2)
else: 
  i = 0
  while i < len(S)-1:
    if S[i] == S[i+1]:
      INNER += 1
      i += 1
    i += 1
  
  if (S[0] != S[-1]):#最初の文字と最後の文字が違うなら、
    print(INNER*K)
  else:
    same_from_start = 0
    same_from_end = 0
    
    count_from_start = 0
    count_from_end = 0
    
    flag_same_from_start = 0
    flag_same_from_end = 0
    
    while flag_same_from_start == 0:
      if S[count_from_start] == S[count_from_start+1]:
        count_from_start += 1
      else:
        count_from_start += 1
        flag_same_from_start = 1
    
    while flag_same_from_end == 0:
      if S[len(S)-count_from_end-1] == S[len(S)-count_from_end-2]:
        count_from_end += 1
      else:
        count_from_end += 1
        flag_same_from_end = 1
    print(INNER*K + (K -1) * ((count_from_start+count_from_end)//2 -\
                              count_from_start//2- count_from_end//2)) len(set(list(S))) == 1 len(set(list(S))) len set(list(S)) set list(S) list S 1 print(K*len(S)//2) print K*len(S)//2 K*len(S) K len(S) len S 2 i = 0 i 0 while i < len(S)-1:
    if S[i] == S[i+1]:
      INNER += 1
      i += 1
    i += 1
  
   i < len(S)-1 i len(S)-1 len(S) len S 1 if S[i] == S[i+1]:
      INNER += 1
      i += 1
     S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 INNER += 1 INNER 1 i += 1 i 1 i += 1 i 1 if (S[0] != S[-1]):#最初の文字と最後の文字が違うなら、
    print(INNER*K)
  else:
    same_from_start = 0
    same_from_end = 0
    
    count_from_start = 0
    count_from_end = 0
    
    flag_same_from_start = 0
    flag_same_from_end = 0
    
    while flag_same_from_start == 0:
      if S[count_from_start] == S[count_from_start+1]:
        count_from_start += 1
      else:
        count_from_start += 1
        flag_same_from_start = 1
    
    while flag_same_from_end == 0:
      if S[len(S)-count_from_end-1] == S[len(S)-count_from_end-2]:
        count_from_end += 1
      else:
        count_from_end += 1
        flag_same_from_end = 1
    print(INNER*K + (K -1) * ((count_from_start+count_from_end)//2 -\
                              count_from_start//2- count_from_end//2)) S[0] != S[-1] S[0] S 0 S[-1] S -1 print(INNER*K) print INNER*K INNER K same_from_start = 0 same_from_start 0 same_from_end = 0 same_from_end 0 count_from_start = 0 count_from_start 0 count_from_end = 0 count_from_end 0 flag_same_from_start = 0 flag_same_from_start 0 flag_same_from_end = 0 flag_same_from_end 0 while flag_same_from_start == 0:
      if S[count_from_start] == S[count_from_start+1]:
        count_from_start += 1
      else:
        count_from_start += 1
        flag_same_from_start = 1
    
     flag_same_from_start == 0 flag_same_from_start 0 if S[count_from_start] == S[count_from_start+1]:
        count_from_start += 1
      else:
        count_from_start += 1
        flag_same_from_start = 1
    
     S[count_from_start] == S[count_from_start+1] S[count_from_start] S count_from_start S[count_from_start+1] S count_from_start+1 count_from_start 1 count_from_start += 1 count_from_start 1 count_from_start += 1 count_from_start 1 flag_same_from_start = 1 flag_same_from_start 1 while flag_same_from_end == 0:
      if S[len(S)-count_from_end-1] == S[len(S)-count_from_end-2]:
        count_from_end += 1
      else:
        count_from_end += 1
        flag_same_from_end = 1
     flag_same_from_end == 0 flag_same_from_end 0 if S[len(S)-count_from_end-1] == S[len(S)-count_from_end-2]:
        count_from_end += 1
      else:
        count_from_end += 1
        flag_same_from_end = 1
     S[len(S)-count_from_end-1] == S[len(S)-count_from_end-2] S[len(S)-count_from_end-1] S len(S)-count_from_end-1 len(S)-count_from_end len(S) len S count_from_end 1 S[len(S)-count_from_end-2] S len(S)-count_from_end-2 len(S)-count_from_end len(S) len S count_from_end 2 count_from_end += 1 count_from_end 1 count_from_end += 1 count_from_end 1 flag_same_from_end = 1 flag_same_from_end 1 print(INNER*K + (K -1) * ((count_from_start+count_from_end)//2 -\
                              count_from_start//2- count_from_end//2)) print INNER*K + (K -1) * ((count_from_start+count_from_end)//2 -\
                              count_from_start//2- count_from_end//2) INNER*K INNER K (K -1) * ((count_from_start+count_from_end)//2 -\
                              count_from_start//2- count_from_end//2) K -1 K 1 (count_from_start+count_from_end)//2 -\
                              count_from_start//2- count_from_end//2 (count_from_start+count_from_end)//2 -\
                              count_from_start//2 (count_from_start+count_from_end)//2 count_from_start+count_from_end count_from_start count_from_end 2 count_from_start//2 count_from_start 2 count_from_end//2 count_from_end 2 count_from_end = 0 0 count_from_end flag_same_from_start = 1 1 flag_same_from_start count_from_start = 0 0 count_from_start INNER += 1 1 INNER S = input() input() S K = int(input()) int(input()) K count_from_start += 1 1 count_from_start i += 1 1 i flag_same_from_end = 0 0 flag_same_from_end count_from_end += 1 1 count_from_end INNER = 0 0 INNER count_from_start += 1 1 count_from_start count_from_end += 1 1 count_from_end i = 0 0 i flag_same_from_start = 0 0 flag_same_from_start flag_same_from_end = 1 1 flag_same_from_end same_from_end = 0 0 same_from_end i += 1 1 i same_from_start = 0 0 same_from_start
S = input()
K = int(input())
 
INNER = 0
  
if len(set(list(S))) == 1:
  print(K*len(S)//2)
else: 
  i = 0
  while i < len(S)-1:
    if S[i] == S[i+1]:
      INNER += 1
      i += 1
    i += 1
  
  if (S[0] != S[-1]):#最初の文字と最後の文字が違うなら、
    print(INNER*K)
  else:
    same_from_start = 0
    same_from_end = 0
    
    count_from_start = 0
    count_from_end = 0
    
    flag_same_from_start = 0
    flag_same_from_end = 0
    
    while flag_same_from_start == 0:
      if S[count_from_start] == S[count_from_start+1]:
        count_from_start += 1
      else:
        count_from_start += 1
        flag_same_from_start = 1
    
    while flag_same_from_end == 0:
      if S[len(S)-count_from_end-1] == S[len(S)-count_from_end-2]:
        count_from_end += 1
      else:
        count_from_end += 1
        flag_same_from_end = 1
    print(INNER*K + (K -1) * ((count_from_start+count_from_end)//2 -\
                              count_from_start//2- count_from_end//2))