S = list(input())
K = int(input())
l = len(S)

if len(set(S)) == 1:
    print(l*K//2)
    exit()
else:
    ans = 0
    tmp = ""
    count = [1]
    for i in range(l-1):
        if S[i] == S[i+1]:
            count[-1] += 1
        else:
            count.append(1)
    
    for i in count:
        ans += i//2*K

    if S[0] == S[-1] and count[0]%2 == count[-1]%2:
        ans += K-1

    print(ans) S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input l = len(S) l len(S) len S if len(set(S)) == 1:
    print(l*K//2)
    exit()
else:
    ans = 0
    tmp = ""
    count = [1]
    for i in range(l-1):
        if S[i] == S[i+1]:
            count[-1] += 1
        else:
            count.append(1)
    
    for i in count:
        ans += i//2*K

    if S[0] == S[-1] and count[0]%2 == count[-1]%2:
        ans += K-1

    print(ans) len(set(S)) == 1 len(set(S)) len set(S) set S 1 print(l*K//2) print l*K//2 l*K l K 2 exit() exit ans = 0 ans 0 tmp = "" tmp "" count = [1] count [1] 1 for i in range(l-1):
        if S[i] == S[i+1]:
            count[-1] += 1
        else:
            count.append(1)
    
     i range(l-1) range l-1 l 1 if S[i] == S[i+1]:
            count[-1] += 1
        else:
            count.append(1)
    
     S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 count[-1] += 1 count[-1] count -1 1 count.append(1) count.append count append 1 for i in count:
        ans += i//2*K

     i count ans += i//2*K ans i//2*K i//2 i 2 K if S[0] == S[-1] and count[0]%2 == count[-1]%2:
        ans += K-1

     S[0] == S[-1] and count[0]%2 == count[-1]%2 S[0] == S[-1] S[0] S 0 S[-1] S -1 count[0]%2 == count[-1]%2 count[0]%2 count[0] count 0 2 count[-1]%2 count[-1] count -1 2 ans += K-1 ans K-1 K 1 print(ans) print ans count = [1] [1] count S = list(input()) list(input()) S ans += K-1 K-1 ans tmp = "" "" tmp ans += i//2*K i//2*K ans l = len(S) len(S) l K = int(input()) int(input()) K ans = 0 0 ans
S = list(input())
K = int(input())
l = len(S)

if len(set(S)) == 1:
    print(l*K//2)
    exit()
else:
    ans = 0
    tmp = ""
    count = [1]
    for i in range(l-1):
        if S[i] == S[i+1]:
            count[-1] += 1
        else:
            count.append(1)
    
    for i in count:
        ans += i//2*K

    if S[0] == S[-1] and count[0]%2 == count[-1]%2:
        ans += K-1

    print(ans)