import sys
s=input()
k=int(input())
distinct=0
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    distinct=1
    first=i
    break
if distinct==0:
  print((len(s)*k)//2)
  sys.exit()
for i in range(len(s)-1,0,-1):
  if s[i]!=s[i-1]:
    last=i
    break
ans=(first+1)//2
ans+=((len(s)-last)//2)
count=1
for i in range(first+1,last):
  if s[i]!=s[i+1]:
    ans+=k*(count//2)
    count=1
  else:
    count+=1
if s[0]==s[-1]:
  ans+=((len(s)+first+1-last)//2)*(k-1)
else:
  ans+=((len(s)-last)//2+(first+1)//2)*(k-1)
print(ans) import sys sys s=input() s input() input k=int(input()) k int(input()) int input() input distinct=0 distinct 0 for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    distinct=1
    first=i
    break i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i]!=s[i+1]:
    distinct=1
    first=i
    break s[i]!=s[i+1] s[i] s i s[i+1] s i+1 i 1 distinct=1 distinct 1 first=i first i break if distinct==0:
  print((len(s)*k)//2)
  sys.exit() distinct==0 distinct 0 print((len(s)*k)//2) print (len(s)*k)//2 len(s)*k len(s) len s k 2 sys.exit() sys.exit sys exit for i in range(len(s)-1,0,-1):
  if s[i]!=s[i-1]:
    last=i
    break i range(len(s)-1,0,-1) range len(s)-1 len(s) len s 1 0 -1 if s[i]!=s[i-1]:
    last=i
    break s[i]!=s[i-1] s[i] s i s[i-1] s i-1 i 1 last=i last i break ans=(first+1)//2 ans (first+1)//2 first+1 first 1 2 ans+=((len(s)-last)//2) ans (len(s)-last)//2 len(s)-last len(s) len s last 2 count=1 count 1 for i in range(first+1,last):
  if s[i]!=s[i+1]:
    ans+=k*(count//2)
    count=1
  else:
    count+=1 i range(first+1,last) range first+1 first 1 last if s[i]!=s[i+1]:
    ans+=k*(count//2)
    count=1
  else:
    count+=1 s[i]!=s[i+1] s[i] s i s[i+1] s i+1 i 1 ans+=k*(count//2) ans k*(count//2) k count//2 count 2 count=1 count 1 count+=1 count 1 if s[0]==s[-1]:
  ans+=((len(s)+first+1-last)//2)*(k-1)
else:
  ans+=((len(s)-last)//2+(first+1)//2)*(k-1) s[0]==s[-1] s[0] s 0 s[-1] s -1 ans+=((len(s)+first+1-last)//2)*(k-1) ans ((len(s)+first+1-last)//2)*(k-1) (len(s)+first+1-last)//2 len(s)+first+1-last len(s)+first+1 len(s)+first len(s) len s first 1 last 2 k-1 k 1 ans+=((len(s)-last)//2+(first+1)//2)*(k-1) ans ((len(s)-last)//2+(first+1)//2)*(k-1) (len(s)-last)//2+(first+1)//2 (len(s)-last)//2 len(s)-last len(s) len s last 2 (first+1)//2 first+1 first 1 2 k-1 k 1 print(ans) print ans count=1 1 count s=input() input() s count=1 1 count ans+=((len(s)+first+1-last)//2)*(k-1) ((len(s)+first+1-last)//2)*(k-1) ans ans+=k*(count//2) k*(count//2) ans k=int(input()) int(input()) k ans=(first+1)//2 (first+1)//2 ans count+=1 1 count ans+=((len(s)-last)//2) (len(s)-last)//2 ans last=i i last distinct=1 1 distinct first=i i first distinct=0 0 distinct ans+=((len(s)-last)//2+(first+1)//2)*(k-1) ((len(s)-last)//2+(first+1)//2)*(k-1) ans
import sys
s=input()
k=int(input())
distinct=0
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    distinct=1
    first=i
    break
if distinct==0:
  print((len(s)*k)//2)
  sys.exit()
for i in range(len(s)-1,0,-1):
  if s[i]!=s[i-1]:
    last=i
    break
ans=(first+1)//2
ans+=((len(s)-last)//2)
count=1
for i in range(first+1,last):
  if s[i]!=s[i+1]:
    ans+=k*(count//2)
    count=1
  else:
    count+=1
if s[0]==s[-1]:
  ans+=((len(s)+first+1-last)//2)*(k-1)
else:
  ans+=((len(s)-last)//2+(first+1)//2)*(k-1)
print(ans)