s = input()
k = int(input())
l = 1
ans = 0
c = []

for i in range(len(s)-1):
  if s[i] == s[i+1]:
    l += 1
  else:
    if c == []:
      c.append(l)
    ans += l//2
    l = 1
    
ans += l//2
if c == []:
  c.append(l)
ans *= k

if len(s) == l:
  ans = k*l//2
elif s[0] == s[-1] and l%2 == 1 and c[0]%2 == 1:
  ans += k-1
  
print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input l = 1 l 1 ans = 0 ans 0 c = [] c [] for i in range(len(s)-1):
  if s[i] == s[i+1]:
    l += 1
  else:
    if c == []:
      c.append(l)
    ans += l//2
    l = 1
     i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i] == s[i+1]:
    l += 1
  else:
    if c == []:
      c.append(l)
    ans += l//2
    l = 1
     s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 l += 1 l 1 if c == []:
      c.append(l)
     c == [] c [] c.append(l) c.append c append l ans += l//2 ans l//2 l 2 l = 1 l 1 ans += l//2 ans l//2 l 2 if c == []:
  c.append(l) c == [] c [] c.append(l) c.append c append l ans *= k ans k if len(s) == l:
  ans = k*l//2
elif s[0] == s[-1] and l%2 == 1 and c[0]%2 == 1:
  ans += k-1
   len(s) == l len(s) len s l ans = k*l//2 ans k*l//2 k*l k l 2 elif s[0] == s[-1] and l%2 == 1 and c[0]%2 == 1:
  ans += k-1
   s[0] == s[-1] and l%2 == 1 and c[0]%2 == 1 s[0] == s[-1] and l%2 == 1 s[0] == s[-1] s[0] s 0 s[-1] s -1 l%2 == 1 l%2 l 2 1 c[0]%2 == 1 c[0]%2 c[0] c 0 2 1 ans += k-1 ans k-1 k 1 print(ans) print ans l = 1 1 l ans += l//2 l//2 ans l = 1 1 l ans = k*l//2 k*l//2 ans ans *= k k ans ans += k-1 k-1 ans s = input() input() s ans = 0 0 ans l += 1 1 l k = int(input()) int(input()) k ans += l//2 l//2 ans c = [] [] c
s = input()
k = int(input())
l = 1
ans = 0
c = []

for i in range(len(s)-1):
  if s[i] == s[i+1]:
    l += 1
  else:
    if c == []:
      c.append(l)
    ans += l//2
    l = 1
    
ans += l//2
if c == []:
  c.append(l)
ans *= k

if len(s) == l:
  ans = k*l//2
elif s[0] == s[-1] and l%2 == 1 and c[0]%2 == 1:
  ans += k-1
  
print(ans)