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

if len(set(S))==1:
  ans = int(len(S)*K/2)
elif K == 1:
  ans = 0
  serial = 1
  #print(serial)
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      serial += 1
    else:
      ans += int(serial/2)
      serial = 1
  ans += int(serial/2)
else:
  #first
  first=0
  serial = 1
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      serial += 1
    else:
      first += int(serial/2)
      serial = 1
  initial = 1
  for i in range(len(S)-1,1,-1):
    if S[i]==S[i-1]:
      initial += 1
    else:
      break
  cnt = 0
  serial = initial
  #print(serial)
  for i in range(len(S)):
    if S[i] == S[i-1]:
      serial += 1
    else:
      cnt += int(serial/2)
      serial = 1
    #print(cnt)
  #last
      
  #print(cnt)
  last = 0
  serial = initial
  for i in range(len(S)):
    if S[i] == S[i-1]:
      serial += 1
    else:
      last += int(serial/2)
      serial = 1
  last += int(serial/2)
  #print(first,cnt,last)
  ans = first+(K-2)*cnt+last

print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input if len(set(S))==1:
  ans = int(len(S)*K/2)
elif K == 1:
  ans = 0
  serial = 1
  #print(serial)
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      serial += 1
    else:
      ans += int(serial/2)
      serial = 1
  ans += int(serial/2)
else:
  #first
  first=0
  serial = 1
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      serial += 1
    else:
      first += int(serial/2)
      serial = 1
  initial = 1
  for i in range(len(S)-1,1,-1):
    if S[i]==S[i-1]:
      initial += 1
    else:
      break
  cnt = 0
  serial = initial
  #print(serial)
  for i in range(len(S)):
    if S[i] == S[i-1]:
      serial += 1
    else:
      cnt += int(serial/2)
      serial = 1
    #print(cnt)
  #last
      
  #print(cnt)
  last = 0
  serial = initial
  for i in range(len(S)):
    if S[i] == S[i-1]:
      serial += 1
    else:
      last += int(serial/2)
      serial = 1
  last += int(serial/2)
  #print(first,cnt,last)
  ans = first+(K-2)*cnt+last len(set(S))==1 len(set(S)) len set(S) set S 1 ans = int(len(S)*K/2) ans int(len(S)*K/2) int len(S)*K/2 len(S)*K len(S) len S K 2 elif K == 1:
  ans = 0
  serial = 1
  #print(serial)
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      serial += 1
    else:
      ans += int(serial/2)
      serial = 1
  ans += int(serial/2) K == 1 K 1 ans = 0 ans 0 serial = 1 serial 1 for i in range(len(S)-1):
    if S[i] == S[i+1]:
      serial += 1
    else:
      ans += int(serial/2)
      serial = 1
   i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i] == S[i+1]:
      serial += 1
    else:
      ans += int(serial/2)
      serial = 1
   S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 serial += 1 serial 1 ans += int(serial/2) ans int(serial/2) int serial/2 serial 2 serial = 1 serial 1 ans += int(serial/2) ans int(serial/2) int serial/2 serial 2 first=0 first 0 serial = 1 serial 1 for i in range(len(S)-1):
    if S[i] == S[i+1]:
      serial += 1
    else:
      first += int(serial/2)
      serial = 1
   i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i] == S[i+1]:
      serial += 1
    else:
      first += int(serial/2)
      serial = 1
   S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 serial += 1 serial 1 first += int(serial/2) first int(serial/2) int serial/2 serial 2 serial = 1 serial 1 initial = 1 initial 1 for i in range(len(S)-1,1,-1):
    if S[i]==S[i-1]:
      initial += 1
    else:
      break
   i range(len(S)-1,1,-1) range len(S)-1 len(S) len S 1 1 -1 if S[i]==S[i-1]:
      initial += 1
    else:
      break
   S[i]==S[i-1] S[i] S i S[i-1] S i-1 i 1 initial += 1 initial 1 break cnt = 0 cnt 0 serial = initial serial initial for i in range(len(S)):
    if S[i] == S[i-1]:
      serial += 1
    else:
      cnt += int(serial/2)
      serial = 1
    #print(cnt)
  #last
      
  #print(cnt)
   i range(len(S)) range len(S) len S if S[i] == S[i-1]:
      serial += 1
    else:
      cnt += int(serial/2)
      serial = 1
    #print(cnt)
  #last
      
  #print(cnt)
   S[i] == S[i-1] S[i] S i S[i-1] S i-1 i 1 serial += 1 serial 1 cnt += int(serial/2) cnt int(serial/2) int serial/2 serial 2 serial = 1 serial 1 last = 0 last 0 serial = initial serial initial for i in range(len(S)):
    if S[i] == S[i-1]:
      serial += 1
    else:
      last += int(serial/2)
      serial = 1
   i range(len(S)) range len(S) len S if S[i] == S[i-1]:
      serial += 1
    else:
      last += int(serial/2)
      serial = 1
   S[i] == S[i-1] S[i] S i S[i-1] S i-1 i 1 serial += 1 serial 1 last += int(serial/2) last int(serial/2) int serial/2 serial 2 serial = 1 serial 1 last += int(serial/2) last int(serial/2) int serial/2 serial 2 ans = first+(K-2)*cnt+last ans first+(K-2)*cnt+last first+(K-2)*cnt first (K-2)*cnt K-2 K 2 cnt last print(ans) print ans cnt += int(serial/2) int(serial/2) cnt first=0 0 first serial = 1 1 serial serial = initial initial serial serial = 1 1 serial serial += 1 1 serial initial += 1 1 initial first += int(serial/2) int(serial/2) first ans += int(serial/2) int(serial/2) ans last += int(serial/2) int(serial/2) last ans = first+(K-2)*cnt+last first+(K-2)*cnt+last ans ans += int(serial/2) int(serial/2) ans serial = 1 1 serial ans = int(len(S)*K/2) int(len(S)*K/2) ans serial = 1 1 serial serial += 1 1 serial last = 0 0 last ans = 0 0 ans S = input() input() S initial = 1 1 initial last += int(serial/2) int(serial/2) last serial += 1 1 serial serial = 1 1 serial serial += 1 1 serial K = int(input()) int(input()) K cnt = 0 0 cnt serial = 1 1 serial serial = initial initial serial
S = input()
K = int(input())

if len(set(S))==1:
  ans = int(len(S)*K/2)
elif K == 1:
  ans = 0
  serial = 1
  #print(serial)
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      serial += 1
    else:
      ans += int(serial/2)
      serial = 1
  ans += int(serial/2)
else:
  #first
  first=0
  serial = 1
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      serial += 1
    else:
      first += int(serial/2)
      serial = 1
  initial = 1
  for i in range(len(S)-1,1,-1):
    if S[i]==S[i-1]:
      initial += 1
    else:
      break
  cnt = 0
  serial = initial
  #print(serial)
  for i in range(len(S)):
    if S[i] == S[i-1]:
      serial += 1
    else:
      cnt += int(serial/2)
      serial = 1
    #print(cnt)
  #last
      
  #print(cnt)
  last = 0
  serial = initial
  for i in range(len(S)):
    if S[i] == S[i-1]:
      serial += 1
    else:
      last += int(serial/2)
      serial = 1
  last += int(serial/2)
  #print(first,cnt,last)
  ans = first+(K-2)*cnt+last

print(ans)