s = input()
t = int(input())
v = set(s)

ans = 0
if len(v) == 1:
  ans = (len(s)*t)//2
  print (ans)
  exit()

a = []
o = s[0]
c = 0

for i in range(len(s)):
  if o == s[i]:
    c += 1
  else:
    a.append([o,c])
    c = 1
    o = s[i]
a.append([o,c])

for i,j in a:
  if j == 1:
    continue
  ans += (j//2)*t

if len(v) > 1:
  if a[0][0] == a[-1][0]:
    if a[0][1]%2 == 1 and a[-1][1]%2 == 1:
      ans += t-1

print (ans) s = input() s input() input t = int(input()) t int(input()) int input() input v = set(s) v set(s) set s ans = 0 ans 0 if len(v) == 1:
  ans = (len(s)*t)//2
  print (ans)
  exit() len(v) == 1 len(v) len v 1 ans = (len(s)*t)//2 ans (len(s)*t)//2 len(s)*t len(s) len s t 2 print (ans) print ans exit() exit a = [] a [] o = s[0] o s[0] s 0 c = 0 c 0 for i in range(len(s)):
  if o == s[i]:
    c += 1
  else:
    a.append([o,c])
    c = 1
    o = s[i] i range(len(s)) range len(s) len s if o == s[i]:
    c += 1
  else:
    a.append([o,c])
    c = 1
    o = s[i] o == s[i] o s[i] s i c += 1 c 1 a.append([o,c]) a.append a append [o,c] o c c = 1 c 1 o = s[i] o s[i] s i a.append([o,c]) a.append a append [o,c] o c for i,j in a:
  if j == 1:
    continue
  ans += (j//2)*t i j a if j == 1:
    continue
   j == 1 j 1 continue ans += (j//2)*t ans (j//2)*t j//2 j 2 t if len(v) > 1:
  if a[0][0] == a[-1][0]:
    if a[0][1]%2 == 1 and a[-1][1]%2 == 1:
      ans += t-1 len(v) > 1 len(v) len v 1 if a[0][0] == a[-1][0]:
    if a[0][1]%2 == 1 and a[-1][1]%2 == 1:
      ans += t-1 a[0][0] == a[-1][0] a[0][0] [0] a 0 0 a[-1][0] [-1] a -1 0 if a[0][1]%2 == 1 and a[-1][1]%2 == 1:
      ans += t-1 a[0][1]%2 == 1 and a[-1][1]%2 == 1 a[0][1]%2 == 1 a[0][1]%2 a[0][1] [0] a 0 1 2 1 a[-1][1]%2 == 1 a[-1][1]%2 a[-1][1] [-1] a -1 1 2 1 ans += t-1 ans t-1 t 1 print (ans) print ans o = s[0] s[0] o v = set(s) set(s) v ans += (j//2)*t (j//2)*t ans a = [] [] a c = 1 1 c t = int(input()) int(input()) t ans = (len(s)*t)//2 (len(s)*t)//2 ans o = s[i] s[i] o ans += t-1 t-1 ans c += 1 1 c c = 0 0 c s = input() input() s ans = 0 0 ans
s = input()
t = int(input())
v = set(s)

ans = 0
if len(v) == 1:
  ans = (len(s)*t)//2
  print (ans)
  exit()

a = []
o = s[0]
c = 0

for i in range(len(s)):
  if o == s[i]:
    c += 1
  else:
    a.append([o,c])
    c = 1
    o = s[i]
a.append([o,c])

for i,j in a:
  if j == 1:
    continue
  ans += (j//2)*t

if len(v) > 1:
  if a[0][0] == a[-1][0]:
    if a[0][1]%2 == 1 and a[-1][1]%2 == 1:
      ans += t-1

print (ans)