s=input()
k=int(input())
s0=s[0]
s1=s[-1]
cs=[]
p=s[0]
c=1
for i in range(1,len(s)):
      if p==s[i]:
            c+=1
      else:
            cs.append(c)
            p=s[i]
            c=1
cs.append(c)
if len(cs)==1:
      print((cs[0]*k)//2)
      exit()
ans=0
if s0!=s1:
      for csi in cs:
            ans+=csi//2
      ans*=k
      print(ans)
      exit()
else:
      for i in range(1,len(cs)-1):
            ans+=cs[i]//2
      ans*=k
      ans+=cs[0]//2+cs[-1]//2
      ans+=((cs[0]+cs[-1])//2)*(k-1)
      print(ans)

 s=input() s input() input k=int(input()) k int(input()) int input() input s0=s[0] s0 s[0] s 0 s1=s[-1] s1 s[-1] s -1 cs=[] cs [] p=s[0] p s[0] s 0 c=1 c 1 for i in range(1,len(s)):
      if p==s[i]:
            c+=1
      else:
            cs.append(c)
            p=s[i]
            c=1 i range(1,len(s)) range 1 len(s) len s if p==s[i]:
            c+=1
      else:
            cs.append(c)
            p=s[i]
            c=1 p==s[i] p s[i] s i c+=1 c 1 cs.append(c) cs.append cs append c p=s[i] p s[i] s i c=1 c 1 cs.append(c) cs.append cs append c if len(cs)==1:
      print((cs[0]*k)//2)
      exit() len(cs)==1 len(cs) len cs 1 print((cs[0]*k)//2) print (cs[0]*k)//2 cs[0]*k cs[0] cs 0 k 2 exit() exit ans=0 ans 0 if s0!=s1:
      for csi in cs:
            ans+=csi//2
      ans*=k
      print(ans)
      exit()
else:
      for i in range(1,len(cs)-1):
            ans+=cs[i]//2
      ans*=k
      ans+=cs[0]//2+cs[-1]//2
      ans+=((cs[0]+cs[-1])//2)*(k-1)
      print(ans) s0!=s1 s0 s1 for csi in cs:
            ans+=csi//2
       csi cs ans+=csi//2 ans csi//2 csi 2 ans*=k ans k print(ans) print ans exit() exit for i in range(1,len(cs)-1):
            ans+=cs[i]//2
       i range(1,len(cs)-1) range 1 len(cs)-1 len(cs) len cs 1 ans+=cs[i]//2 ans cs[i]//2 cs[i] cs i 2 ans*=k ans k ans+=cs[0]//2+cs[-1]//2 ans cs[0]//2+cs[-1]//2 cs[0]//2 cs[0] cs 0 2 cs[-1]//2 cs[-1] cs -1 2 ans+=((cs[0]+cs[-1])//2)*(k-1) ans ((cs[0]+cs[-1])//2)*(k-1) (cs[0]+cs[-1])//2 cs[0]+cs[-1] cs[0] cs 0 cs[-1] cs -1 2 k-1 k 1 print(ans) print ans k=int(input()) int(input()) k ans+=((cs[0]+cs[-1])//2)*(k-1) ((cs[0]+cs[-1])//2)*(k-1) ans p=s[0] s[0] p ans=0 0 ans c=1 1 c p=s[i] s[i] p ans+=csi//2 csi//2 ans s=input() input() s c+=1 1 c ans+=cs[i]//2 cs[i]//2 ans ans+=cs[0]//2+cs[-1]//2 cs[0]//2+cs[-1]//2 ans s1=s[-1] s[-1] s1 cs=[] [] cs s0=s[0] s[0] s0 c=1 1 c ans*=k k ans ans*=k k ans
s=input()
k=int(input())
s0=s[0]
s1=s[-1]
cs=[]
p=s[0]
c=1
for i in range(1,len(s)):
      if p==s[i]:
            c+=1
      else:
            cs.append(c)
            p=s[i]
            c=1
cs.append(c)
if len(cs)==1:
      print((cs[0]*k)//2)
      exit()
ans=0
if s0!=s1:
      for csi in cs:
            ans+=csi//2
      ans*=k
      print(ans)
      exit()
else:
      for i in range(1,len(cs)-1):
            ans+=cs[i]//2
      ans*=k
      ans+=cs[0]//2+cs[-1]//2
      ans+=((cs[0]+cs[-1])//2)*(k-1)
      print(ans)


