S = input()
K = int(input())

def calc(S):
  ret = 0
  seq = 1
  for i in range(1,len(S)):
    if S[i-1] == S[i]:
      seq += 1
    else:
      ret += seq // 2
      seq = 1
  ret += seq // 2
  return ret
## pK + q（K-1)  として解けるきがします
## pK + q


if S[0] * len(S) == S:
  # 全部おなじだったら
  print((len(S) * K) // 2)
elif K < 1000:
  print(calc(S*K))
else:
  x1 = calc(S)    # p+q
  x2 = calc(S*2)  #2p+q
  print((x2-x1) * K + 2*x1 - x2)
   S = input() S input() input K = int(input()) K int(input()) int input() input def calc(S):
  ret = 0
  seq = 1
  for i in range(1,len(S)):
    if S[i-1] == S[i]:
      seq += 1
    else:
      ret += seq // 2
      seq = 1
  ret += seq // 2
  return ret
## pK + q（K-1)  として解けるきがします
## pK + q calc ret = 0 ret 0 seq = 1 seq 1 for i in range(1,len(S)):
    if S[i-1] == S[i]:
      seq += 1
    else:
      ret += seq // 2
      seq = 1
   i range(1,len(S)) range 1 len(S) len S if S[i-1] == S[i]:
      seq += 1
    else:
      ret += seq // 2
      seq = 1
   S[i-1] == S[i] S[i-1] S i-1 i 1 S[i] S i seq += 1 seq 1 ret += seq // 2 ret seq // 2 seq 2 seq = 1 seq 1 ret += seq // 2 ret seq // 2 seq 2 return ret ret S S if S[0] * len(S) == S:
  # 全部おなじだったら
  print((len(S) * K) // 2)
elif K < 1000:
  print(calc(S*K))
else:
  x1 = calc(S)    # p+q
  x2 = calc(S*2)  #2p+q
  print((x2-x1) * K + 2*x1 - x2)
   S[0] * len(S) == S S[0] * len(S) S[0] S 0 len(S) len S S print((len(S) * K) // 2) print (len(S) * K) // 2 len(S) * K len(S) len S K 2 elif K < 1000:
  print(calc(S*K)) K < 1000 K 1000 print(calc(S*K)) print calc(S*K) calc S*K S K x1 = calc(S) x1 calc(S) calc S x2 = calc(S*2) x2 calc(S*2) calc S*2 S 2 print((x2-x1) * K + 2*x1 - x2) print (x2-x1) * K + 2*x1 - x2 (x2-x1) * K + 2*x1 (x2-x1) * K x2-x1 x2 x1 K 2*x1 2 x1 x2 K = int(input()) int(input()) K x2 = calc(S*2) calc(S*2) x2 x1 = calc(S) calc(S) x1 S = input() input() S def calc(S):
  ret = 0
  seq = 1
  for i in range(1,len(S)):
    if S[i-1] == S[i]:
      seq += 1
    else:
      ret += seq // 2
      seq = 1
  ret += seq // 2
  return ret
## pK + q（K-1)  として解けるきがします
## pK + q def calc(S):
  ret = 0
  seq = 1
  for i in range(1,len(S)):
    if S[i-1] == S[i]:
      seq += 1
    else:
      ret += seq // 2
      seq = 1
  ret += seq // 2
  return ret
## pK + q（K-1)  として解けるきがします
## pK + q calc
S = input()
K = int(input())

def calc(S):
  ret = 0
  seq = 1
  for i in range(1,len(S)):
    if S[i-1] == S[i]:
      seq += 1
    else:
      ret += seq // 2
      seq = 1
  ret += seq // 2
  return ret
## pK + q（K-1)  として解けるきがします
## pK + q


if S[0] * len(S) == S:
  # 全部おなじだったら
  print((len(S) * K) // 2)
elif K < 1000:
  print(calc(S*K))
else:
  x1 = calc(S)    # p+q
  x2 = calc(S*2)  #2p+q
  print((x2-x1) * K + 2*x1 - x2)
  
