import itertools
def main():
  S = input()
  K = int(input())
  
  if len(set(S)) == 1:
    print(len(S) * K // 2)
    return
  
  cc = 0
  gg = itertools.groupby(S)
  for key, item in gg:
    cc += len(list(item))//2
  a = b = 0
  if S[0] == S[-1]:
    while a < len(S) and S[a] == S[0]:
      a += 1
    S = S[::-1]
    while b < len(S) and S[b] == S[0]:
      b += 1
  output = K * cc - (K-1) * (a//2 + b//2 - (a+b)//2)
  print(output)
  return

if __name__ == '__main__':
  main() import itertools itertools def main():
  S = input()
  K = int(input())
  
  if len(set(S)) == 1:
    print(len(S) * K // 2)
    return
  
  cc = 0
  gg = itertools.groupby(S)
  for key, item in gg:
    cc += len(list(item))//2
  a = b = 0
  if S[0] == S[-1]:
    while a < len(S) and S[a] == S[0]:
      a += 1
    S = S[::-1]
    while b < len(S) and S[b] == S[0]:
      b += 1
  output = K * cc - (K-1) * (a//2 + b//2 - (a+b)//2)
  print(output)
  return main S = input() S input() input K = int(input()) K int(input()) int input() input if len(set(S)) == 1:
    print(len(S) * K // 2)
    return
  
   len(set(S)) == 1 len(set(S)) len set(S) set S 1 print(len(S) * K // 2) print len(S) * K // 2 len(S) * K len(S) len S K 2 return cc = 0 cc 0 gg = itertools.groupby(S) gg itertools.groupby(S) itertools.groupby itertools groupby S for key, item in gg:
    cc += len(list(item))//2
   key item gg cc += len(list(item))//2 cc len(list(item))//2 len(list(item)) len list(item) list item 2 a = b = 0 a 0 = b = 0 b 0 if S[0] == S[-1]:
    while a < len(S) and S[a] == S[0]:
      a += 1
    S = S[::-1]
    while b < len(S) and S[b] == S[0]:
      b += 1
   S[0] == S[-1] S[0] S 0 S[-1] S -1 while a < len(S) and S[a] == S[0]:
      a += 1
     a < len(S) and S[a] == S[0] a < len(S) a len(S) len S S[a] == S[0] S[a] S a S[0] S 0 a += 1 a 1 S = S[::-1] S S[::-1] S ::-1 -1 while b < len(S) and S[b] == S[0]:
      b += 1
   b < len(S) and S[b] == S[0] b < len(S) b len(S) len S S[b] == S[0] S[b] S b S[0] S 0 b += 1 b 1 output = K * cc - (K-1) * (a//2 + b//2 - (a+b)//2) output K * cc - (K-1) * (a//2 + b//2 - (a+b)//2) K * cc K cc (K-1) * (a//2 + b//2 - (a+b)//2) K-1 K 1 a//2 + b//2 - (a+b)//2 a//2 + b//2 a//2 a 2 b//2 b 2 (a+b)//2 a+b a b 2 print(output) print output return if __name__ == '__main__':
  main() __name__ == '__main__' __name__ '__main__' main() main def main():
  S = input()
  K = int(input())
  
  if len(set(S)) == 1:
    print(len(S) * K // 2)
    return
  
  cc = 0
  gg = itertools.groupby(S)
  for key, item in gg:
    cc += len(list(item))//2
  a = b = 0
  if S[0] == S[-1]:
    while a < len(S) and S[a] == S[0]:
      a += 1
    S = S[::-1]
    while b < len(S) and S[b] == S[0]:
      b += 1
  output = K * cc - (K-1) * (a//2 + b//2 - (a+b)//2)
  print(output)
  return def main():
  S = input()
  K = int(input())
  
  if len(set(S)) == 1:
    print(len(S) * K // 2)
    return
  
  cc = 0
  gg = itertools.groupby(S)
  for key, item in gg:
    cc += len(list(item))//2
  a = b = 0
  if S[0] == S[-1]:
    while a < len(S) and S[a] == S[0]:
      a += 1
    S = S[::-1]
    while b < len(S) and S[b] == S[0]:
      b += 1
  output = K * cc - (K-1) * (a//2 + b//2 - (a+b)//2)
  print(output)
  return main
import itertools
def main():
  S = input()
  K = int(input())
  
  if len(set(S)) == 1:
    print(len(S) * K // 2)
    return
  
  cc = 0
  gg = itertools.groupby(S)
  for key, item in gg:
    cc += len(list(item))//2
  a = b = 0
  if S[0] == S[-1]:
    while a < len(S) and S[a] == S[0]:
      a += 1
    S = S[::-1]
    while b < len(S) and S[b] == S[0]:
      b += 1
  output = K * cc - (K-1) * (a//2 + b//2 - (a+b)//2)
  print(output)
  return

if __name__ == '__main__':
  main()