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

if len(set(s)) == 1:
    print((len(s)*k)//2)
    exit()

ss = s + s

shoko = 0
prev = ''
cnt = 0
for i in range(len(s)):
    if s[i] == prev:
        cnt += 1
    else:
        shoko += cnt // 2
        cnt = 1
    prev = s[i]
shoko += cnt // 2

kosa = 0
prev = ''
cnt = 0
for i in range(len(ss)):
    if ss[i] == prev:
        cnt += 1
    else:
        kosa += cnt // 2
        cnt = 1
    prev = ss[i]
kosa += cnt // 2
kosa -= shoko

print(shoko + (k-1)*kosa) s = input() s input() input k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
    print((len(s)*k)//2)
    exit() len(set(s)) == 1 len(set(s)) len set(s) set s 1 print((len(s)*k)//2) print (len(s)*k)//2 len(s)*k len(s) len s k 2 exit() exit ss = s + s ss s + s s s shoko = 0 shoko 0 prev = '' prev '' cnt = 0 cnt 0 for i in range(len(s)):
    if s[i] == prev:
        cnt += 1
    else:
        shoko += cnt // 2
        cnt = 1
    prev = s[i] i range(len(s)) range len(s) len s if s[i] == prev:
        cnt += 1
    else:
        shoko += cnt // 2
        cnt = 1
     s[i] == prev s[i] s i prev cnt += 1 cnt 1 shoko += cnt // 2 shoko cnt // 2 cnt 2 cnt = 1 cnt 1 prev = s[i] prev s[i] s i shoko += cnt // 2 shoko cnt // 2 cnt 2 kosa = 0 kosa 0 prev = '' prev '' cnt = 0 cnt 0 for i in range(len(ss)):
    if ss[i] == prev:
        cnt += 1
    else:
        kosa += cnt // 2
        cnt = 1
    prev = ss[i] i range(len(ss)) range len(ss) len ss if ss[i] == prev:
        cnt += 1
    else:
        kosa += cnt // 2
        cnt = 1
     ss[i] == prev ss[i] ss i prev cnt += 1 cnt 1 kosa += cnt // 2 kosa cnt // 2 cnt 2 cnt = 1 cnt 1 prev = ss[i] prev ss[i] ss i kosa += cnt // 2 kosa cnt // 2 cnt 2 kosa -= shoko kosa shoko print(shoko + (k-1)*kosa) print shoko + (k-1)*kosa shoko (k-1)*kosa k-1 k 1 kosa prev = s[i] s[i] prev ss = s + s s + s ss cnt = 0 0 cnt kosa += cnt // 2 cnt // 2 kosa kosa += cnt // 2 cnt // 2 kosa shoko += cnt // 2 cnt // 2 shoko cnt = 0 0 cnt prev = ss[i] ss[i] prev prev = '' '' prev shoko += cnt // 2 cnt // 2 shoko cnt += 1 1 cnt prev = '' '' prev kosa -= shoko shoko kosa cnt = 1 1 cnt shoko = 0 0 shoko cnt = 1 1 cnt s = input() input() s k = int(input()) int(input()) k cnt += 1 1 cnt kosa = 0 0 kosa
s = input()
k = int(input())

if len(set(s)) == 1:
    print((len(s)*k)//2)
    exit()

ss = s + s

shoko = 0
prev = ''
cnt = 0
for i in range(len(s)):
    if s[i] == prev:
        cnt += 1
    else:
        shoko += cnt // 2
        cnt = 1
    prev = s[i]
shoko += cnt // 2

kosa = 0
prev = ''
cnt = 0
for i in range(len(ss)):
    if ss[i] == prev:
        cnt += 1
    else:
        kosa += cnt // 2
        cnt = 1
    prev = ss[i]
kosa += cnt // 2
kosa -= shoko

print(shoko + (k-1)*kosa)