import sys
input = sys.stdin.readline
from collections import *

S = input()[:-1]
K = int(input())

if S==S[0]*len(S):
    print(len(S)*K//2)
    exit()
    
l = []
cnt = 1

for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        l.append((S[i], cnt))
        cnt = 1
    else:
        cnt += 1
    
l.append((S[-1], cnt))

if K==1 or l[0][0]!=l[-1][0]:
    ans = 0
    
    for _, c in l:
        ans += c//2*K
else:
    ans = (l[0][1]+l[-1][1])//2*(K-1)
    ans += l[0][1]//2
    ans += l[-1][1]//2
    
    for _, c in l[1:-1]:
        ans += c//2*K

print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from collections import * S = input()[:-1] S input()[:-1] () input :-1 -1 K = int(input()) K int(input()) int input() input if S==S[0]*len(S):
    print(len(S)*K//2)
    exit()
     S==S[0]*len(S) S S[0]*len(S) S[0] S 0 len(S) len S print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 exit() exit l = [] l [] cnt = 1 cnt 1 for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        l.append((S[i], cnt))
        cnt = 1
    else:
        cnt += 1
     i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i]!=S[i+1]:
        l.append((S[i], cnt))
        cnt = 1
    else:
        cnt += 1
     S[i]!=S[i+1] S[i] S i S[i+1] S i+1 i 1 l.append((S[i], cnt)) l.append l append (S[i], cnt) S[i] S i cnt cnt = 1 cnt 1 cnt += 1 cnt 1 l.append((S[-1], cnt)) l.append l append (S[-1], cnt) S[-1] S -1 cnt if K==1 or l[0][0]!=l[-1][0]:
    ans = 0
    
    for _, c in l:
        ans += c//2*K
else:
    ans = (l[0][1]+l[-1][1])//2*(K-1)
    ans += l[0][1]//2
    ans += l[-1][1]//2
    
    for _, c in l[1:-1]:
        ans += c//2*K K==1 or l[0][0]!=l[-1][0] K==1 K 1 l[0][0]!=l[-1][0] l[0][0] [0] l 0 0 l[-1][0] [-1] l -1 0 ans = 0 ans 0 for _, c in l:
        ans += c//2*K _ c l ans += c//2*K ans c//2*K c//2 c 2 K ans = (l[0][1]+l[-1][1])//2*(K-1) ans (l[0][1]+l[-1][1])//2*(K-1) (l[0][1]+l[-1][1])//2 l[0][1]+l[-1][1] l[0][1] [0] l 0 1 l[-1][1] [-1] l -1 1 2 K-1 K 1 ans += l[0][1]//2 ans l[0][1]//2 l[0][1] [0] l 0 1 2 ans += l[-1][1]//2 ans l[-1][1]//2 l[-1][1] [-1] l -1 1 2 for _, c in l[1:-1]:
        ans += c//2*K _ c l[1:-1] l 1:-1 1 -1 ans += c//2*K ans c//2*K c//2 c 2 K print(ans) print ans cnt += 1 1 cnt ans += c//2*K c//2*K ans ans += l[-1][1]//2 l[-1][1]//2 ans ans += c//2*K c//2*K ans input = sys.stdin.readline sys.stdin.readline input cnt = 1 1 cnt ans = (l[0][1]+l[-1][1])//2*(K-1) (l[0][1]+l[-1][1])//2*(K-1) ans K = int(input()) int(input()) K ans += l[0][1]//2 l[0][1]//2 ans cnt = 1 1 cnt ans = 0 0 ans S = input()[:-1] input()[:-1] S l = [] [] l
import sys
input = sys.stdin.readline
from collections import *

S = input()[:-1]
K = int(input())

if S==S[0]*len(S):
    print(len(S)*K//2)
    exit()
    
l = []
cnt = 1

for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        l.append((S[i], cnt))
        cnt = 1
    else:
        cnt += 1
    
l.append((S[-1], cnt))

if K==1 or l[0][0]!=l[-1][0]:
    ans = 0
    
    for _, c in l:
        ans += c//2*K
else:
    ans = (l[0][1]+l[-1][1])//2*(K-1)
    ans += l[0][1]//2
    ans += l[-1][1]//2
    
    for _, c in l[1:-1]:
        ans += c//2*K

print(ans)