S = input()
K = int(input())
N = len(S)

bef = ""
start = 0
l = []
for i, s in enumerate(S):
    if bef=="":
        start = i
    elif bef!=s:
        l.append(i-start)
        start = i
    bef = s
l.append(i-start+1)

if len(set(S))==1:
    print((N*K)//2)
else:
    if S[0]==S[-1]:
        ans = (l[0]//2)+(l[-1]//2)+((l[0]+l[-1])//2)*(K-1)
    else:
        ans = (l[0]//2)*K+(l[-1]//2)*K
    for i in l[1:-1]:
        ans += (i//2)*K
    print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S bef = "" bef "" start = 0 start 0 l = [] l [] for i, s in enumerate(S):
    if bef=="":
        start = i
    elif bef!=s:
        l.append(i-start)
        start = i
    bef = s i s enumerate(S) enumerate S if bef=="":
        start = i
    elif bef!=s:
        l.append(i-start)
        start = i
     bef=="" bef "" start = i start i elif bef!=s:
        l.append(i-start)
        start = i
     bef!=s bef s l.append(i-start) l.append l append i-start i start start = i start i bef = s bef s l.append(i-start+1) l.append l append i-start+1 i-start i start 1 if len(set(S))==1:
    print((N*K)//2)
else:
    if S[0]==S[-1]:
        ans = (l[0]//2)+(l[-1]//2)+((l[0]+l[-1])//2)*(K-1)
    else:
        ans = (l[0]//2)*K+(l[-1]//2)*K
    for i in l[1:-1]:
        ans += (i//2)*K
    print(ans) len(set(S))==1 len(set(S)) len set(S) set S 1 print((N*K)//2) print (N*K)//2 N*K N K 2 if S[0]==S[-1]:
        ans = (l[0]//2)+(l[-1]//2)+((l[0]+l[-1])//2)*(K-1)
    else:
        ans = (l[0]//2)*K+(l[-1]//2)*K
     S[0]==S[-1] S[0] S 0 S[-1] S -1 ans = (l[0]//2)+(l[-1]//2)+((l[0]+l[-1])//2)*(K-1) ans (l[0]//2)+(l[-1]//2)+((l[0]+l[-1])//2)*(K-1) (l[0]//2)+(l[-1]//2) l[0]//2 l[0] l 0 2 l[-1]//2 l[-1] l -1 2 ((l[0]+l[-1])//2)*(K-1) (l[0]+l[-1])//2 l[0]+l[-1] l[0] l 0 l[-1] l -1 2 K-1 K 1 ans = (l[0]//2)*K+(l[-1]//2)*K ans (l[0]//2)*K+(l[-1]//2)*K (l[0]//2)*K l[0]//2 l[0] l 0 2 K (l[-1]//2)*K l[-1]//2 l[-1] l -1 2 K for i in l[1:-1]:
        ans += (i//2)*K
     i l[1:-1] l 1:-1 1 -1 ans += (i//2)*K ans (i//2)*K i//2 i 2 K print(ans) print ans S = input() input() S bef = "" "" bef ans = (l[0]//2)+(l[-1]//2)+((l[0]+l[-1])//2)*(K-1) (l[0]//2)+(l[-1]//2)+((l[0]+l[-1])//2)*(K-1) ans start = i i start N = len(S) len(S) N ans += (i//2)*K (i//2)*K ans K = int(input()) int(input()) K start = 0 0 start l = [] [] l start = i i start bef = s s bef ans = (l[0]//2)*K+(l[-1]//2)*K (l[0]//2)*K+(l[-1]//2)*K ans
S = input()
K = int(input())
N = len(S)

bef = ""
start = 0
l = []
for i, s in enumerate(S):
    if bef=="":
        start = i
    elif bef!=s:
        l.append(i-start)
        start = i
    bef = s
l.append(i-start+1)

if len(set(S))==1:
    print((N*K)//2)
else:
    if S[0]==S[-1]:
        ans = (l[0]//2)+(l[-1]//2)+((l[0]+l[-1])//2)*(K-1)
    else:
        ans = (l[0]//2)*K+(l[-1]//2)*K
    for i in l[1:-1]:
        ans += (i//2)*K
    print(ans)
