S = input()
K = int(input())
now,cnt,num = S[0],1,0
for i in S[1:-1]:
    if i == now:
        cnt += 1
    else:
        num += cnt//2
        cnt = 1
        now = i
if S[-1] == now:
    num += (cnt+1)//2
else: num += cnt//2

S = S + S
now,cnt,num2 = S[0],1,0
for i in S[1:-1]:
    if i == now:
        cnt += 1
    else:
        num2 += cnt//2
        cnt = 1
        now = i
if S[-1] == now:
    num2 += (cnt+1)//2
else: num2 += cnt//2

length = len(S)//2
if len(set(S)) == 1 and length%2 == 1:
    print(length//2*K + K//2)
    exit()

if num2 - num*2 == 1:
    ans = K - 1 + num*K
else:
    ans = num*K
print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input now,cnt,num = S[0],1,0 now S[0] S 0 cnt 1 num 0 for i in S[1:-1]:
    if i == now:
        cnt += 1
    else:
        num += cnt//2
        cnt = 1
        now = i i S[1:-1] S 1:-1 1 -1 if i == now:
        cnt += 1
    else:
        num += cnt//2
        cnt = 1
        now = i i == now i now cnt += 1 cnt 1 num += cnt//2 num cnt//2 cnt 2 cnt = 1 cnt 1 now = i now i if S[-1] == now:
    num += (cnt+1)//2
else: num += cnt//2 S[-1] == now S[-1] S -1 now num += (cnt+1)//2 num (cnt+1)//2 cnt+1 cnt 1 2 S = S + S S S + S S S now,cnt,num2 = S[0],1,0 now S[0] S 0 cnt 1 num2 0 for i in S[1:-1]:
    if i == now:
        cnt += 1
    else:
        num2 += cnt//2
        cnt = 1
        now = i i S[1:-1] S 1:-1 1 -1 if i == now:
        cnt += 1
    else:
        num2 += cnt//2
        cnt = 1
        now = i i == now i now cnt += 1 cnt 1 num2 += cnt//2 num2 cnt//2 cnt 2 cnt = 1 cnt 1 now = i now i if S[-1] == now:
    num2 += (cnt+1)//2
else: num2 += cnt//2 S[-1] == now S[-1] S -1 now num2 += (cnt+1)//2 num2 (cnt+1)//2 cnt+1 cnt 1 2 length = len(S)//2 length len(S)//2 len(S) len S 2 if len(set(S)) == 1 and length%2 == 1:
    print(length//2*K + K//2)
    exit() len(set(S)) == 1 and length%2 == 1 len(set(S)) == 1 len(set(S)) len set(S) set S 1 length%2 == 1 length%2 length 2 1 print(length//2*K + K//2) print length//2*K + K//2 length//2*K length//2 length 2 K K//2 K 2 exit() exit if num2 - num*2 == 1:
    ans = K - 1 + num*K
else:
    ans = num*K num2 - num*2 == 1 num2 - num*2 num2 num*2 num 2 1 ans = K - 1 + num*K ans K - 1 + num*K K - 1 K 1 num*K num K ans = num*K ans num*K num K print(ans) print ans cnt += 1 1 cnt now = i i now now,cnt,num2 = S[0],1,0 S[0] now num2 += cnt//2 cnt//2 num2 S = S + S S + S S cnt,num2 = S[0],1,0 1 cnt cnt += 1 1 cnt now,cnt,num = S[0],1,0 S[0] now num = S[0],1,0 0 num cnt = 1 1 cnt cnt = 1 1 cnt num2 += (cnt+1)//2 (cnt+1)//2 num2 num += cnt//2 cnt//2 num num2 = S[0],1,0 0 num2 now = i i now length = len(S)//2 len(S)//2 length ans = K - 1 + num*K K - 1 + num*K ans cnt,num = S[0],1,0 1 cnt ans = num*K num*K ans S = input() input() S num += (cnt+1)//2 (cnt+1)//2 num K = int(input()) int(input()) K
S = input()
K = int(input())
now,cnt,num = S[0],1,0
for i in S[1:-1]:
    if i == now:
        cnt += 1
    else:
        num += cnt//2
        cnt = 1
        now = i
if S[-1] == now:
    num += (cnt+1)//2
else: num += cnt//2

S = S + S
now,cnt,num2 = S[0],1,0
for i in S[1:-1]:
    if i == now:
        cnt += 1
    else:
        num2 += cnt//2
        cnt = 1
        now = i
if S[-1] == now:
    num2 += (cnt+1)//2
else: num2 += cnt//2

length = len(S)//2
if len(set(S)) == 1 and length%2 == 1:
    print(length//2*K + K//2)
    exit()

if num2 - num*2 == 1:
    ans = K - 1 + num*K
else:
    ans = num*K
print(ans)