S=input()
K=int(input())
N=len(S)

if S.count(S[0])==N:
  ans= K*N//2
else:
  h=0
  for i in range(N):
    if S[i]==S[0]:
      h +=1
    else:
      break
  t=0
  for i in range(N-1,-1,-1):
    if S[i]==S[-1]:
      t +=1
    else:
      break
  ren=1
  cnt=0
  for i in range(h,N-t):
    if S[i]==S[i-1]:
      ren +=1
      if i==N-t-1:
        cnt += ren//2
    else:
      cnt += ren//2
      ren=1    
      
  if S[0]==S[-1]:
    #print(h//2, (K-1)*((h+t)//2), t//2 ,K*cnt)
    ans= h//2 + (K-1)*((h+t)//2) + t//2 + K*cnt
  else:
    #print(h//2,cnt,t//2)
    ans= (h//2 + cnt + t//2)*K
print(ans) S=input() S input() input K=int(input()) K int(input()) int input() input N=len(S) N len(S) len S if S.count(S[0])==N:
  ans= K*N//2
else:
  h=0
  for i in range(N):
    if S[i]==S[0]:
      h +=1
    else:
      break
  t=0
  for i in range(N-1,-1,-1):
    if S[i]==S[-1]:
      t +=1
    else:
      break
  ren=1
  cnt=0
  for i in range(h,N-t):
    if S[i]==S[i-1]:
      ren +=1
      if i==N-t-1:
        cnt += ren//2
    else:
      cnt += ren//2
      ren=1    
      
  if S[0]==S[-1]:
    #print(h//2, (K-1)*((h+t)//2), t//2 ,K*cnt)
    ans= h//2 + (K-1)*((h+t)//2) + t//2 + K*cnt
  else:
    #print(h//2,cnt,t//2)
    ans= (h//2 + cnt + t//2)*K S.count(S[0])==N S.count(S[0]) S.count S count S[0] S 0 N ans= K*N//2 ans K*N//2 K*N K N 2 h=0 h 0 for i in range(N):
    if S[i]==S[0]:
      h +=1
    else:
      break
   i range(N) range N if S[i]==S[0]:
      h +=1
    else:
      break
   S[i]==S[0] S[i] S i S[0] S 0 h +=1 h 1 break t=0 t 0 for i in range(N-1,-1,-1):
    if S[i]==S[-1]:
      t +=1
    else:
      break
   i range(N-1,-1,-1) range N-1 N 1 -1 -1 if S[i]==S[-1]:
      t +=1
    else:
      break
   S[i]==S[-1] S[i] S i S[-1] S -1 t +=1 t 1 break ren=1 ren 1 cnt=0 cnt 0 for i in range(h,N-t):
    if S[i]==S[i-1]:
      ren +=1
      if i==N-t-1:
        cnt += ren//2
    else:
      cnt += ren//2
      ren=1    
      
   i range(h,N-t) range h N-t N t if S[i]==S[i-1]:
      ren +=1
      if i==N-t-1:
        cnt += ren//2
    else:
      cnt += ren//2
      ren=1    
      
   S[i]==S[i-1] S[i] S i S[i-1] S i-1 i 1 ren +=1 ren 1 if i==N-t-1:
        cnt += ren//2
     i==N-t-1 i N-t-1 N-t N t 1 cnt += ren//2 cnt ren//2 ren 2 cnt += ren//2 cnt ren//2 ren 2 ren=1 ren 1 if S[0]==S[-1]:
    #print(h//2, (K-1)*((h+t)//2), t//2 ,K*cnt)
    ans= h//2 + (K-1)*((h+t)//2) + t//2 + K*cnt
  else:
    #print(h//2,cnt,t//2)
    ans= (h//2 + cnt + t//2)*K S[0]==S[-1] S[0] S 0 S[-1] S -1 ans= h//2 + (K-1)*((h+t)//2) + t//2 + K*cnt ans h//2 + (K-1)*((h+t)//2) + t//2 + K*cnt h//2 + (K-1)*((h+t)//2) + t//2 h//2 + (K-1)*((h+t)//2) h//2 h 2 (K-1)*((h+t)//2) K-1 K 1 (h+t)//2 h+t h t 2 t//2 t 2 K*cnt K cnt ans= (h//2 + cnt + t//2)*K ans (h//2 + cnt + t//2)*K h//2 + cnt + t//2 h//2 + cnt h//2 h 2 cnt t//2 t 2 K print(ans) print ans S=input() input() S cnt += ren//2 ren//2 cnt ren +=1 1 ren t +=1 1 t ans= K*N//2 K*N//2 ans ren=1 1 ren ans= h//2 + (K-1)*((h+t)//2) + t//2 + K*cnt h//2 + (K-1)*((h+t)//2) + t//2 + K*cnt ans h +=1 1 h cnt += ren//2 ren//2 cnt t=0 0 t h=0 0 h cnt=0 0 cnt ren=1 1 ren N=len(S) len(S) N ans= (h//2 + cnt + t//2)*K (h//2 + cnt + t//2)*K ans K=int(input()) int(input()) K
S=input()
K=int(input())
N=len(S)

if S.count(S[0])==N:
  ans= K*N//2
else:
  h=0
  for i in range(N):
    if S[i]==S[0]:
      h +=1
    else:
      break
  t=0
  for i in range(N-1,-1,-1):
    if S[i]==S[-1]:
      t +=1
    else:
      break
  ren=1
  cnt=0
  for i in range(h,N-t):
    if S[i]==S[i-1]:
      ren +=1
      if i==N-t-1:
        cnt += ren//2
    else:
      cnt += ren//2
      ren=1    
      
  if S[0]==S[-1]:
    #print(h//2, (K-1)*((h+t)//2), t//2 ,K*cnt)
    ans= h//2 + (K-1)*((h+t)//2) + t//2 + K*cnt
  else:
    #print(h//2,cnt,t//2)
    ans= (h//2 + cnt + t//2)*K
print(ans)