# https://atcoder.jp/contests/agc039/tasks/agc039_a

s = list(input())
k = int(input())


i = 0
a = 0

while i < len(s):
  if i == len(s) - 1:
    break
  if s[i] == s[i+1]:
    a += 1
    i += 2
  else:
    i += 1
else:
  print(a * k)
  exit()
  
i = -1
b = 0

while i < len(s):
  if i == len(s) - 1:
    print(a + b * (k - 1))
    exit()
  if s[i] == s[i + 1]:
    b += 1
    i += 2
  else:
    i += 1
else:
  print(a * ((k + 1) // 2) + b * ((k - 1) // 2))
  exit() s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input i = 0 i 0 a = 0 a 0 while i < len(s):
  if i == len(s) - 1:
    break
  if s[i] == s[i+1]:
    a += 1
    i += 2
  else:
    i += 1
else:
  print(a * k)
  exit()
   i < len(s) i len(s) len s if i == len(s) - 1:
    break
   i == len(s) - 1 i len(s) - 1 len(s) len s 1 break if s[i] == s[i+1]:
    a += 1
    i += 2
  else:
    i += 1 s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 a += 1 a 1 i += 2 i 2 i += 1 i 1 print(a * k) print a * k a k exit() exit i = -1 i -1 b = 0 b 0 while i < len(s):
  if i == len(s) - 1:
    print(a + b * (k - 1))
    exit()
  if s[i] == s[i + 1]:
    b += 1
    i += 2
  else:
    i += 1
else:
  print(a * ((k + 1) // 2) + b * ((k - 1) // 2))
  exit() i < len(s) i len(s) len s if i == len(s) - 1:
    print(a + b * (k - 1))
    exit()
   i == len(s) - 1 i len(s) - 1 len(s) len s 1 print(a + b * (k - 1)) print a + b * (k - 1) a b * (k - 1) b k - 1 k 1 exit() exit if s[i] == s[i + 1]:
    b += 1
    i += 2
  else:
    i += 1 s[i] == s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 b += 1 b 1 i += 2 i 2 i += 1 i 1 print(a * ((k + 1) // 2) + b * ((k - 1) // 2)) print a * ((k + 1) // 2) + b * ((k - 1) // 2) a * ((k + 1) // 2) a (k + 1) // 2 k + 1 k 1 2 b * ((k - 1) // 2) b (k - 1) // 2 k - 1 k 1 2 exit() exit i += 1 1 i b += 1 1 b a += 1 1 a b = 0 0 b i += 2 2 i i += 2 2 i k = int(input()) int(input()) k a = 0 0 a i += 1 1 i s = list(input()) list(input()) s i = 0 0 i i = -1 -1 i
# https://atcoder.jp/contests/agc039/tasks/agc039_a

s = list(input())
k = int(input())


i = 0
a = 0

while i < len(s):
  if i == len(s) - 1:
    break
  if s[i] == s[i+1]:
    a += 1
    i += 2
  else:
    i += 1
else:
  print(a * k)
  exit()
  
i = -1
b = 0

while i < len(s):
  if i == len(s) - 1:
    print(a + b * (k - 1))
    exit()
  if s[i] == s[i + 1]:
    b += 1
    i += 2
  else:
    i += 1
else:
  print(a * ((k + 1) // 2) + b * ((k - 1) // 2))
  exit()