s = input()
ss = s + s
sss = s + s + s
k = int(input())
n = 0
nn = 0
nnn = 0
s = list(s)
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    n += 1
    s[i] = '.'
ss = list(ss)
for i in range(1,len(ss)):
  if ss[i-1] == ss[i]:
    nn += 1
    ss[i] = '.'
sss = list(sss)
for i in range(1,len(sss)):
  if sss[i-1] == sss[i]:
    nnn += 1
    sss[i] = '.'
a = nn-n*2
if nnn == n*3+a*2:
  print(n*k+a*(k-1))
else:
  print((len(s)*k)//2) s = input() s input() input ss = s + s ss s + s s s sss = s + s + s sss s + s + s s + s s s s k = int(input()) k int(input()) int input() input n = 0 n 0 nn = 0 nn 0 nnn = 0 nnn 0 s = list(s) s list(s) list s for i in range(1,len(s)):
  if s[i-1] == s[i]:
    n += 1
    s[i] = '.' i range(1,len(s)) range 1 len(s) len s if s[i-1] == s[i]:
    n += 1
    s[i] = '.' s[i-1] == s[i] s[i-1] s i-1 i 1 s[i] s i n += 1 n 1 s[i] = '.' s[i] s i '.' ss = list(ss) ss list(ss) list ss for i in range(1,len(ss)):
  if ss[i-1] == ss[i]:
    nn += 1
    ss[i] = '.' i range(1,len(ss)) range 1 len(ss) len ss if ss[i-1] == ss[i]:
    nn += 1
    ss[i] = '.' ss[i-1] == ss[i] ss[i-1] ss i-1 i 1 ss[i] ss i nn += 1 nn 1 ss[i] = '.' ss[i] ss i '.' sss = list(sss) sss list(sss) list sss for i in range(1,len(sss)):
  if sss[i-1] == sss[i]:
    nnn += 1
    sss[i] = '.' i range(1,len(sss)) range 1 len(sss) len sss if sss[i-1] == sss[i]:
    nnn += 1
    sss[i] = '.' sss[i-1] == sss[i] sss[i-1] sss i-1 i 1 sss[i] sss i nnn += 1 nnn 1 sss[i] = '.' sss[i] sss i '.' a = nn-n*2 a nn-n*2 nn n*2 n 2 if nnn == n*3+a*2:
  print(n*k+a*(k-1))
else:
  print((len(s)*k)//2) nnn == n*3+a*2 nnn n*3+a*2 n*3 n 3 a*2 a 2 print(n*k+a*(k-1)) print n*k+a*(k-1) n*k n k a*(k-1) a k-1 k 1 print((len(s)*k)//2) print (len(s)*k)//2 len(s)*k len(s) len s k 2 sss = s + s + s s + s + s sss sss = list(sss) list(sss) sss a = nn-n*2 nn-n*2 a s = input() input() s ss = list(ss) list(ss) ss k = int(input()) int(input()) k nnn += 1 1 nnn nn = 0 0 nn nnn = 0 0 nnn nn += 1 1 nn n += 1 1 n ss = s + s s + s ss n = 0 0 n s = list(s) list(s) s
s = input()
ss = s + s
sss = s + s + s
k = int(input())
n = 0
nn = 0
nnn = 0
s = list(s)
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    n += 1
    s[i] = '.'
ss = list(ss)
for i in range(1,len(ss)):
  if ss[i-1] == ss[i]:
    nn += 1
    ss[i] = '.'
sss = list(sss)
for i in range(1,len(sss)):
  if sss[i-1] == sss[i]:
    nnn += 1
    sss[i] = '.'
a = nn-n*2
if nnn == n*3+a*2:
  print(n*k+a*(k-1))
else:
  print((len(s)*k)//2)