s=input()
n=len(s)
k=int(input())
if s[0]==s[n-1]:
  d=1
  ans=0
  for i in range(1,n):
    if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
  if d==0:
    print(ans*k)
  else:
    ans2=0
    for i in range(n):
      if s[i-1]==s[i] and d==1:
        ans2+=1
        d=0
      elif s[i-1]==s[i] and d==0:
        d=1
      elif s[i-1]!=s[i]:
        d=1
    if d==1:
      print(ans+ans2*(k-1))
    else:
      if k%2==0:
        print((ans+ans2)*k//2)
      else:
        print((ans+ans2)*(k//2)+ans)
elif s[0]!=s[n-1]:
  d=1
  ans=0
  for i in range(1,n):
    if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
  print(ans*k) s=input() s input() input n=len(s) n len(s) len s k=int(input()) k int(input()) int input() input if s[0]==s[n-1]:
  d=1
  ans=0
  for i in range(1,n):
    if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
  if d==0:
    print(ans*k)
  else:
    ans2=0
    for i in range(n):
      if s[i-1]==s[i] and d==1:
        ans2+=1
        d=0
      elif s[i-1]==s[i] and d==0:
        d=1
      elif s[i-1]!=s[i]:
        d=1
    if d==1:
      print(ans+ans2*(k-1))
    else:
      if k%2==0:
        print((ans+ans2)*k//2)
      else:
        print((ans+ans2)*(k//2)+ans)
elif s[0]!=s[n-1]:
  d=1
  ans=0
  for i in range(1,n):
    if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
  print(ans*k) s[0]==s[n-1] s[0] s 0 s[n-1] s n-1 n 1 d=1 d 1 ans=0 ans 0 for i in range(1,n):
    if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
   i range(1,n) range 1 n if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
   s[i-1]==s[i] and d==1 s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i d==1 d 1 ans+=1 ans 1 d=0 d 0 elif s[i-1]==s[i] and d==0:
      d=1
     s[i-1]==s[i] and d==0 s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i d==0 d 0 d=1 d 1 elif s[i-1]!=s[i]:
      d=1
   s[i-1]!=s[i] s[i-1] s i-1 i 1 s[i] s i d=1 d 1 if d==0:
    print(ans*k)
  else:
    ans2=0
    for i in range(n):
      if s[i-1]==s[i] and d==1:
        ans2+=1
        d=0
      elif s[i-1]==s[i] and d==0:
        d=1
      elif s[i-1]!=s[i]:
        d=1
    if d==1:
      print(ans+ans2*(k-1))
    else:
      if k%2==0:
        print((ans+ans2)*k//2)
      else:
        print((ans+ans2)*(k//2)+ans) d==0 d 0 print(ans*k) print ans*k ans k ans2=0 ans2 0 for i in range(n):
      if s[i-1]==s[i] and d==1:
        ans2+=1
        d=0
      elif s[i-1]==s[i] and d==0:
        d=1
      elif s[i-1]!=s[i]:
        d=1
     i range(n) range n if s[i-1]==s[i] and d==1:
        ans2+=1
        d=0
      elif s[i-1]==s[i] and d==0:
        d=1
      elif s[i-1]!=s[i]:
        d=1
     s[i-1]==s[i] and d==1 s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i d==1 d 1 ans2+=1 ans2 1 d=0 d 0 elif s[i-1]==s[i] and d==0:
        d=1
       s[i-1]==s[i] and d==0 s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i d==0 d 0 d=1 d 1 elif s[i-1]!=s[i]:
        d=1
     s[i-1]!=s[i] s[i-1] s i-1 i 1 s[i] s i d=1 d 1 if d==1:
      print(ans+ans2*(k-1))
    else:
      if k%2==0:
        print((ans+ans2)*k//2)
      else:
        print((ans+ans2)*(k//2)+ans) d==1 d 1 print(ans+ans2*(k-1)) print ans+ans2*(k-1) ans ans2*(k-1) ans2 k-1 k 1 if k%2==0:
        print((ans+ans2)*k//2)
      else:
        print((ans+ans2)*(k//2)+ans) k%2==0 k%2 k 2 0 print((ans+ans2)*k//2) print (ans+ans2)*k//2 (ans+ans2)*k ans+ans2 ans ans2 k 2 print((ans+ans2)*(k//2)+ans) print (ans+ans2)*(k//2)+ans (ans+ans2)*(k//2) ans+ans2 ans ans2 k//2 k 2 ans elif s[0]!=s[n-1]:
  d=1
  ans=0
  for i in range(1,n):
    if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
  print(ans*k) s[0]!=s[n-1] s[0] s 0 s[n-1] s n-1 n 1 d=1 d 1 ans=0 ans 0 for i in range(1,n):
    if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
   i range(1,n) range 1 n if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
   s[i-1]==s[i] and d==1 s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i d==1 d 1 ans+=1 ans 1 d=0 d 0 elif s[i-1]==s[i] and d==0:
      d=1
     s[i-1]==s[i] and d==0 s[i-1]==s[i] s[i-1] s i-1 i 1 s[i] s i d==0 d 0 d=1 d 1 elif s[i-1]!=s[i]:
      d=1
   s[i-1]!=s[i] s[i-1] s i-1 i 1 s[i] s i d=1 d 1 print(ans*k) print ans*k ans k d=1 1 d d=1 1 d d=1 1 d ans2+=1 1 ans2 d=1 1 d ans+=1 1 ans ans+=1 1 ans d=0 0 d d=1 1 d d=1 1 d d=0 0 d k=int(input()) int(input()) k ans2=0 0 ans2 ans=0 0 ans d=0 0 d d=1 1 d s=input() input() s d=1 1 d ans=0 0 ans n=len(s) len(s) n
s=input()
n=len(s)
k=int(input())
if s[0]==s[n-1]:
  d=1
  ans=0
  for i in range(1,n):
    if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
  if d==0:
    print(ans*k)
  else:
    ans2=0
    for i in range(n):
      if s[i-1]==s[i] and d==1:
        ans2+=1
        d=0
      elif s[i-1]==s[i] and d==0:
        d=1
      elif s[i-1]!=s[i]:
        d=1
    if d==1:
      print(ans+ans2*(k-1))
    else:
      if k%2==0:
        print((ans+ans2)*k//2)
      else:
        print((ans+ans2)*(k//2)+ans)
elif s[0]!=s[n-1]:
  d=1
  ans=0
  for i in range(1,n):
    if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
  print(ans*k)