import sys
s=input()
k=int(input())

s_2=s*2
pre=""
ans=0

if s.count(s[0])==len(s):
  print((len(s)*k)//2)
  sys.exit()

for i in range(len(s)):
  if pre==s[i]:
    ans+=1
    pre=""
  else:
    pre=s[i]

pre=""
ans1=0
for i in range(len(s_2)):
  if pre==s_2[i]:
    ans1+=1
    pre=""
  else:
    pre=s_2[i]

if 2*ans<ans1:
  print(ans+(k-1)*(ans1-ans))
else:
  print(ans*k) import sys sys s=input() s input() input k=int(input()) k int(input()) int input() input s_2=s*2 s_2 s*2 s 2 pre="" pre "" ans=0 ans 0 if s.count(s[0])==len(s):
  print((len(s)*k)//2)
  sys.exit() s.count(s[0])==len(s) s.count(s[0]) s.count s count s[0] s 0 len(s) len s 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)):
  if pre==s[i]:
    ans+=1
    pre=""
  else:
    pre=s[i] i range(len(s)) range len(s) len s if pre==s[i]:
    ans+=1
    pre=""
  else:
    pre=s[i] pre==s[i] pre s[i] s i ans+=1 ans 1 pre="" pre "" pre=s[i] pre s[i] s i pre="" pre "" ans1=0 ans1 0 for i in range(len(s_2)):
  if pre==s_2[i]:
    ans1+=1
    pre=""
  else:
    pre=s_2[i] i range(len(s_2)) range len(s_2) len s_2 if pre==s_2[i]:
    ans1+=1
    pre=""
  else:
    pre=s_2[i] pre==s_2[i] pre s_2[i] s_2 i ans1+=1 ans1 1 pre="" pre "" pre=s_2[i] pre s_2[i] s_2 i if 2*ans<ans1:
  print(ans+(k-1)*(ans1-ans))
else:
  print(ans*k) 2*ans<ans1 2*ans 2 ans ans1 print(ans+(k-1)*(ans1-ans)) print ans+(k-1)*(ans1-ans) ans (k-1)*(ans1-ans) k-1 k 1 ans1-ans ans1 ans print(ans*k) print ans*k ans k pre=s[i] s[i] pre pre=s_2[i] s_2[i] pre pre="" "" pre s_2=s*2 s*2 s_2 ans+=1 1 ans ans=0 0 ans pre="" "" pre k=int(input()) int(input()) k pre="" "" pre ans1+=1 1 ans1 s=input() input() s pre="" "" pre ans1=0 0 ans1
import sys
s=input()
k=int(input())

s_2=s*2
pre=""
ans=0

if s.count(s[0])==len(s):
  print((len(s)*k)//2)
  sys.exit()

for i in range(len(s)):
  if pre==s[i]:
    ans+=1
    pre=""
  else:
    pre=s[i]

pre=""
ans1=0
for i in range(len(s_2)):
  if pre==s_2[i]:
    ans1+=1
    pre=""
  else:
    pre=s_2[i]

if 2*ans<ans1:
  print(ans+(k-1)*(ans1-ans))
else:
  print(ans*k)
