S = input()
K = int(input())

if S.count(S[0]) == len(S):
    print(len(S)*K//2)
    exit()

count = 0
i = 1
flg = [False] * len(S)
while i < len(S):
    if S[i] == S[i-1]:
        count += 1
        flg[i] = True
        i += 2
    else:
        i += 1
count *= K
if (not flg[len(S)-1]) and S[0] == S[-1]:
    a = 1
    for i in range(1, len(S)):
        if S[0] == S[i]:
            a += 1
        else:
            break
    if a % 2 == 1:
        count += (K-1)
print(count) S = input() S input() input K = int(input()) K int(input()) int input() input if S.count(S[0]) == len(S):
    print(len(S)*K//2)
    exit() S.count(S[0]) == len(S) S.count(S[0]) S.count S count 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 count = 0 count 0 i = 1 i 1 flg = [False] * len(S) flg [False] * len(S) [False] False len(S) len S while i < len(S):
    if S[i] == S[i-1]:
        count += 1
        flg[i] = True
        i += 2
    else:
        i += 1 i < len(S) i len(S) len S if S[i] == S[i-1]:
        count += 1
        flg[i] = True
        i += 2
    else:
        i += 1 S[i] == S[i-1] S[i] S i S[i-1] S i-1 i 1 count += 1 count 1 flg[i] = True flg[i] flg i True i += 2 i 2 i += 1 i 1 count *= K count K if (not flg[len(S)-1]) and S[0] == S[-1]:
    a = 1
    for i in range(1, len(S)):
        if S[0] == S[i]:
            a += 1
        else:
            break
    if a % 2 == 1:
        count += (K-1) (not flg[len(S)-1]) and S[0] == S[-1] not flg[len(S)-1] flg[len(S)-1] flg len(S)-1 len(S) len S 1 S[0] == S[-1] S[0] S 0 S[-1] S -1 a = 1 a 1 for i in range(1, len(S)):
        if S[0] == S[i]:
            a += 1
        else:
            break
     i range(1, len(S)) range 1 len(S) len S if S[0] == S[i]:
            a += 1
        else:
            break
     S[0] == S[i] S[0] S 0 S[i] S i a += 1 a 1 break if a % 2 == 1:
        count += (K-1) a % 2 == 1 a % 2 a 2 1 count += (K-1) count K-1 K 1 print(count) print count flg = [False] * len(S) [False] * len(S) flg count += 1 1 count i += 2 2 i i += 1 1 i a += 1 1 a count = 0 0 count S = input() input() S i = 1 1 i count *= K K count a = 1 1 a count += (K-1) K-1 count K = int(input()) int(input()) K
S = input()
K = int(input())

if S.count(S[0]) == len(S):
    print(len(S)*K//2)
    exit()

count = 0
i = 1
flg = [False] * len(S)
while i < len(S):
    if S[i] == S[i-1]:
        count += 1
        flg[i] = True
        i += 2
    else:
        i += 1
count *= K
if (not flg[len(S)-1]) and S[0] == S[-1]:
    a = 1
    for i in range(1, len(S)):
        if S[0] == S[i]:
            a += 1
        else:
            break
    if a % 2 == 1:
        count += (K-1)
print(count)
