#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
S = input()
K = int(input())
ls = len(S)
t1 = []

t = 1
for i in range(1, ls):
    if S[i - 1] == S[i]:
        t += 1
    else:
        if t > 1:
            t1.append(t)
        t = 1

if t > 1 or t == ls:
    t1.append(t)

ans = 0
for t in t1:
    ans += t // 2

if len(t1) == 1:
    if t1[0] == ls:
        print(ls * K // 2)

else:
    if S[0] != S[-1]:
        print(ans * K)
    
    else:
        ta = t1[0]
        tb = t1[-1]
        print(ans * K - (ta // 2 + tb // 2 - (ta + tb) // 2) * (K - 1))



 S = input() S input() input K = int(input()) K int(input()) int input() input ls = len(S) ls len(S) len S t1 = [] t1 [] t = 1 t 1 for i in range(1, ls):
    if S[i - 1] == S[i]:
        t += 1
    else:
        if t > 1:
            t1.append(t)
        t = 1 i range(1, ls) range 1 ls if S[i - 1] == S[i]:
        t += 1
    else:
        if t > 1:
            t1.append(t)
        t = 1 S[i - 1] == S[i] S[i - 1] S i - 1 i 1 S[i] S i t += 1 t 1 if t > 1:
            t1.append(t)
         t > 1 t 1 t1.append(t) t1.append t1 append t t = 1 t 1 if t > 1 or t == ls:
    t1.append(t) t > 1 or t == ls t > 1 t 1 t == ls t ls t1.append(t) t1.append t1 append t ans = 0 ans 0 for t in t1:
    ans += t // 2 t t1 ans += t // 2 ans t // 2 t 2 if len(t1) == 1:
    if t1[0] == ls:
        print(ls * K // 2)

else:
    if S[0] != S[-1]:
        print(ans * K)
    
    else:
        ta = t1[0]
        tb = t1[-1]
        print(ans * K - (ta // 2 + tb // 2 - (ta + tb) // 2) * (K - 1)) len(t1) == 1 len(t1) len t1 1 if t1[0] == ls:
        print(ls * K // 2) t1[0] == ls t1[0] t1 0 ls print(ls * K // 2) print ls * K // 2 ls * K ls K 2 if S[0] != S[-1]:
        print(ans * K)
    
    else:
        ta = t1[0]
        tb = t1[-1]
        print(ans * K - (ta // 2 + tb // 2 - (ta + tb) // 2) * (K - 1)) S[0] != S[-1] S[0] S 0 S[-1] S -1 print(ans * K) print ans * K ans K ta = t1[0] ta t1[0] t1 0 tb = t1[-1] tb t1[-1] t1 -1 print(ans * K - (ta // 2 + tb // 2 - (ta + tb) // 2) * (K - 1)) print ans * K - (ta // 2 + tb // 2 - (ta + tb) // 2) * (K - 1) ans * K ans K (ta // 2 + tb // 2 - (ta + tb) // 2) * (K - 1) ta // 2 + tb // 2 - (ta + tb) // 2 ta // 2 + tb // 2 ta // 2 ta 2 tb // 2 tb 2 (ta + tb) // 2 ta + tb ta tb 2 K - 1 K 1 K = int(input()) int(input()) K t = 1 1 t t = 1 1 t tb = t1[-1] t1[-1] tb ls = len(S) len(S) ls ans += t // 2 t // 2 ans t += 1 1 t ans = 0 0 ans t1 = [] [] t1 S = input() input() S ta = t1[0] t1[0] ta
#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
S = input()
K = int(input())
ls = len(S)
t1 = []

t = 1
for i in range(1, ls):
    if S[i - 1] == S[i]:
        t += 1
    else:
        if t > 1:
            t1.append(t)
        t = 1

if t > 1 or t == ls:
    t1.append(t)

ans = 0
for t in t1:
    ans += t // 2

if len(t1) == 1:
    if t1[0] == ls:
        print(ls * K // 2)

else:
    if S[0] != S[-1]:
        print(ans * K)
    
    else:
        ta = t1[0]
        tb = t1[-1]
        print(ans * K - (ta // 2 + tb // 2 - (ta + tb) // 2) * (K - 1))




