A=list(input())
n=int(input())
tmp=0
if len(set(A)) == 1:
   print(len(A)*n//2)
   exit()
sum_n=0
tmp3=0
while A[0] == A[tmp3]:
   tmp3+=1
sum_n+=tmp3
tmp3=0
while A[-1] == A[-1-tmp3]:
   tmp3+=1
sum_n+=tmp3
for i in range(len(A)-1):
   if A[i] == A[i+1]:
      A[i+1]="1"
      tmp+=1
tmp2=0
if A[0] == A[-1]:
   tmp2=n-1
   if sum_n%2 == 1:
      tmp2-=n-1
print(tmp*n+tmp2) A=list(input()) A list(input()) list input() input n=int(input()) n int(input()) int input() input tmp=0 tmp 0 if len(set(A)) == 1:
   print(len(A)*n//2)
   exit() len(set(A)) == 1 len(set(A)) len set(A) set A 1 print(len(A)*n//2) print len(A)*n//2 len(A)*n len(A) len A n 2 exit() exit sum_n=0 sum_n 0 tmp3=0 tmp3 0 while A[0] == A[tmp3]:
   tmp3+=1 A[0] == A[tmp3] A[0] A 0 A[tmp3] A tmp3 tmp3+=1 tmp3 1 sum_n+=tmp3 sum_n tmp3 tmp3=0 tmp3 0 while A[-1] == A[-1-tmp3]:
   tmp3+=1 A[-1] == A[-1-tmp3] A[-1] A -1 A[-1-tmp3] A -1-tmp3 -1 tmp3 tmp3+=1 tmp3 1 sum_n+=tmp3 sum_n tmp3 for i in range(len(A)-1):
   if A[i] == A[i+1]:
      A[i+1]="1"
      tmp+=1 i range(len(A)-1) range len(A)-1 len(A) len A 1 if A[i] == A[i+1]:
      A[i+1]="1"
      tmp+=1 A[i] == A[i+1] A[i] A i A[i+1] A i+1 i 1 A[i+1]="1" A[i+1] A i+1 i 1 "1" tmp+=1 tmp 1 tmp2=0 tmp2 0 if A[0] == A[-1]:
   tmp2=n-1
   if sum_n%2 == 1:
      tmp2-=n-1 A[0] == A[-1] A[0] A 0 A[-1] A -1 tmp2=n-1 tmp2 n-1 n 1 if sum_n%2 == 1:
      tmp2-=n-1 sum_n%2 == 1 sum_n%2 sum_n 2 1 tmp2-=n-1 tmp2 n-1 n 1 print(tmp*n+tmp2) print tmp*n+tmp2 tmp*n tmp n tmp2 tmp+=1 1 tmp n=int(input()) int(input()) n sum_n=0 0 sum_n tmp3+=1 1 tmp3 A=list(input()) list(input()) A tmp2=n-1 n-1 tmp2 sum_n+=tmp3 tmp3 sum_n tmp3=0 0 tmp3 tmp=0 0 tmp tmp3+=1 1 tmp3 sum_n+=tmp3 tmp3 sum_n tmp3=0 0 tmp3 tmp2-=n-1 n-1 tmp2 tmp2=0 0 tmp2
A=list(input())
n=int(input())
tmp=0
if len(set(A)) == 1:
   print(len(A)*n//2)
   exit()
sum_n=0
tmp3=0
while A[0] == A[tmp3]:
   tmp3+=1
sum_n+=tmp3
tmp3=0
while A[-1] == A[-1-tmp3]:
   tmp3+=1
sum_n+=tmp3
for i in range(len(A)-1):
   if A[i] == A[i+1]:
      A[i+1]="1"
      tmp+=1
tmp2=0
if A[0] == A[-1]:
   tmp2=n-1
   if sum_n%2 == 1:
      tmp2-=n-1
print(tmp*n+tmp2)