S=input()
K=int(input())
N=len(S)
count=1
countlist=[]
anssub=0
for i in range(N-1):
  if S[i]==S[i+1]:
    count+=1
  else: 
    countlist+=[count]
    count=1
if S[N-2]!=S[N-1]:
  count=1
countlist+=[count]  
for i in range(len(countlist)):
  if i!=0 and i!=len(countlist)-1:
    if countlist[i]!=1:
      anssub+=countlist[i]//2
a=countlist[0]+countlist[-1]
if S[0]==S[-1]:
  anssub2=a//2
else:
  anssub2=0
  if countlist[0]!=1:
    anssub2+=countlist[0]//2
  if countlist[-1]!=1:
    anssub2+=countlist[-1]//2
  
b=countlist[0]
c=countlist[-1]
anssub3=0
if b!=1:
  anssub3+=b//2
if c!=1:
  anssub3+=c//2
  
ans=anssub*K+anssub2*(K-1)+anssub3
if len(countlist)==1:
  ans=countlist[0]*K//2
print(ans) S=input() S input() input K=int(input()) K int(input()) int input() input N=len(S) N len(S) len S count=1 count 1 countlist=[] countlist [] anssub=0 anssub 0 for i in range(N-1):
  if S[i]==S[i+1]:
    count+=1
  else: 
    countlist+=[count]
    count=1 i range(N-1) range N-1 N 1 if S[i]==S[i+1]:
    count+=1
  else: 
    countlist+=[count]
    count=1 S[i]==S[i+1] S[i] S i S[i+1] S i+1 i 1 count+=1 count 1 countlist+=[count] countlist [count] count count=1 count 1 if S[N-2]!=S[N-1]:
  count=1 S[N-2]!=S[N-1] S[N-2] S N-2 N 2 S[N-1] S N-1 N 1 count=1 count 1 countlist+=[count] countlist [count] count for i in range(len(countlist)):
  if i!=0 and i!=len(countlist)-1:
    if countlist[i]!=1:
      anssub+=countlist[i]//2 i range(len(countlist)) range len(countlist) len countlist if i!=0 and i!=len(countlist)-1:
    if countlist[i]!=1:
      anssub+=countlist[i]//2 i!=0 and i!=len(countlist)-1 i!=0 i 0 i!=len(countlist)-1 i len(countlist)-1 len(countlist) len countlist 1 if countlist[i]!=1:
      anssub+=countlist[i]//2 countlist[i]!=1 countlist[i] countlist i 1 anssub+=countlist[i]//2 anssub countlist[i]//2 countlist[i] countlist i 2 a=countlist[0]+countlist[-1] a countlist[0]+countlist[-1] countlist[0] countlist 0 countlist[-1] countlist -1 if S[0]==S[-1]:
  anssub2=a//2
else:
  anssub2=0
  if countlist[0]!=1:
    anssub2+=countlist[0]//2
  if countlist[-1]!=1:
    anssub2+=countlist[-1]//2
   S[0]==S[-1] S[0] S 0 S[-1] S -1 anssub2=a//2 anssub2 a//2 a 2 anssub2=0 anssub2 0 if countlist[0]!=1:
    anssub2+=countlist[0]//2
   countlist[0]!=1 countlist[0] countlist 0 1 anssub2+=countlist[0]//2 anssub2 countlist[0]//2 countlist[0] countlist 0 2 if countlist[-1]!=1:
    anssub2+=countlist[-1]//2
   countlist[-1]!=1 countlist[-1] countlist -1 1 anssub2+=countlist[-1]//2 anssub2 countlist[-1]//2 countlist[-1] countlist -1 2 b=countlist[0] b countlist[0] countlist 0 c=countlist[-1] c countlist[-1] countlist -1 anssub3=0 anssub3 0 if b!=1:
  anssub3+=b//2 b!=1 b 1 anssub3+=b//2 anssub3 b//2 b 2 if c!=1:
  anssub3+=c//2
   c!=1 c 1 anssub3+=c//2 anssub3 c//2 c 2 ans=anssub*K+anssub2*(K-1)+anssub3 ans anssub*K+anssub2*(K-1)+anssub3 anssub*K+anssub2*(K-1) anssub*K anssub K anssub2*(K-1) anssub2 K-1 K 1 anssub3 if len(countlist)==1:
  ans=countlist[0]*K//2 len(countlist)==1 len(countlist) len countlist 1 ans=countlist[0]*K//2 ans countlist[0]*K//2 countlist[0]*K countlist[0] countlist 0 K 2 print(ans) print ans count=1 1 count anssub2+=countlist[0]//2 countlist[0]//2 anssub2 count=1 1 count count=1 1 count c=countlist[-1] countlist[-1] c N=len(S) len(S) N countlist+=[count] [count] countlist b=countlist[0] countlist[0] b K=int(input()) int(input()) K a=countlist[0]+countlist[-1] countlist[0]+countlist[-1] a ans=countlist[0]*K//2 countlist[0]*K//2 ans anssub2+=countlist[-1]//2 countlist[-1]//2 anssub2 countlist+=[count] [count] countlist count+=1 1 count anssub3+=b//2 b//2 anssub3 anssub3=0 0 anssub3 S=input() input() S anssub=0 0 anssub anssub3+=c//2 c//2 anssub3 ans=anssub*K+anssub2*(K-1)+anssub3 anssub*K+anssub2*(K-1)+anssub3 ans anssub2=0 0 anssub2 anssub+=countlist[i]//2 countlist[i]//2 anssub countlist=[] [] countlist anssub2=a//2 a//2 anssub2
S=input()
K=int(input())
N=len(S)
count=1
countlist=[]
anssub=0
for i in range(N-1):
  if S[i]==S[i+1]:
    count+=1
  else: 
    countlist+=[count]
    count=1
if S[N-2]!=S[N-1]:
  count=1
countlist+=[count]  
for i in range(len(countlist)):
  if i!=0 and i!=len(countlist)-1:
    if countlist[i]!=1:
      anssub+=countlist[i]//2
a=countlist[0]+countlist[-1]
if S[0]==S[-1]:
  anssub2=a//2
else:
  anssub2=0
  if countlist[0]!=1:
    anssub2+=countlist[0]//2
  if countlist[-1]!=1:
    anssub2+=countlist[-1]//2
  
b=countlist[0]
c=countlist[-1]
anssub3=0
if b!=1:
  anssub3+=b//2
if c!=1:
  anssub3+=c//2
  
ans=anssub*K+anssub2*(K-1)+anssub3
if len(countlist)==1:
  ans=countlist[0]*K//2
print(ans)