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

N = len(S)
#全て同じ文字の時
if len(set(S)) == 1:
    print(N*K//2)
    exit()

#隣合う文字列が何個等しいか
cycle = 0
tmp = S[0]
cnt = 1
for i in range(1, N):
    if tmp != S[i]:
        cycle += cnt//2
        tmp = S[i]
        cnt = 1
    else:
        cnt += 1
cycle += cnt//2

if S[0] == S[-1]:
    i = 0
    a = 0
    tmp = S[0]
    while S[i] == tmp:
        i += 1
        a += 1
    j = N-1
    b = 0
    tmp = S[-1]
    while S[j] == tmp:
        j -= 1
        b += 1
    print((cycle*K) - (a//2 + b//2 - (a+b)//2)*(K-1))
else:
    print(cycle*K) S = input() S input() input K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S if len(set(S)) == 1:
    print(N*K//2)
    exit()

#隣合う文字列が何個等しいか 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 exit() exit cycle = 0 cycle 0 tmp = S[0] tmp S[0] S 0 cnt = 1 cnt 1 for i in range(1, N):
    if tmp != S[i]:
        cycle += cnt//2
        tmp = S[i]
        cnt = 1
    else:
        cnt += 1 i range(1, N) range 1 N if tmp != S[i]:
        cycle += cnt//2
        tmp = S[i]
        cnt = 1
    else:
        cnt += 1 tmp != S[i] tmp S[i] S i cycle += cnt//2 cycle cnt//2 cnt 2 tmp = S[i] tmp S[i] S i cnt = 1 cnt 1 cnt += 1 cnt 1 cycle += cnt//2 cycle cnt//2 cnt 2 if S[0] == S[-1]:
    i = 0
    a = 0
    tmp = S[0]
    while S[i] == tmp:
        i += 1
        a += 1
    j = N-1
    b = 0
    tmp = S[-1]
    while S[j] == tmp:
        j -= 1
        b += 1
    print((cycle*K) - (a//2 + b//2 - (a+b)//2)*(K-1))
else:
    print(cycle*K) S[0] == S[-1] S[0] S 0 S[-1] S -1 i = 0 i 0 a = 0 a 0 tmp = S[0] tmp S[0] S 0 while S[i] == tmp:
        i += 1
        a += 1
     S[i] == tmp S[i] S i tmp i += 1 i 1 a += 1 a 1 j = N-1 j N-1 N 1 b = 0 b 0 tmp = S[-1] tmp S[-1] S -1 while S[j] == tmp:
        j -= 1
        b += 1
     S[j] == tmp S[j] S j tmp j -= 1 j 1 b += 1 b 1 print((cycle*K) - (a//2 + b//2 - (a+b)//2)*(K-1)) print (cycle*K) - (a//2 + b//2 - (a+b)//2)*(K-1) cycle*K cycle K (a//2 + b//2 - (a+b)//2)*(K-1) a//2 + b//2 - (a+b)//2 a//2 + b//2 a//2 a 2 b//2 b 2 (a+b)//2 a+b a b 2 K-1 K 1 print(cycle*K) print cycle*K cycle K tmp = S[0] S[0] tmp i = 0 0 i cycle += cnt//2 cnt//2 cycle j = N-1 N-1 j tmp = S[-1] S[-1] tmp i += 1 1 i j -= 1 1 j S = input() input() S K = int(input()) int(input()) K cnt += 1 1 cnt cycle = 0 0 cycle N = len(S) len(S) N tmp = S[i] S[i] tmp b = 0 0 b a = 0 0 a cnt = 1 1 cnt cnt = 1 1 cnt cycle += cnt//2 cnt//2 cycle b += 1 1 b tmp = S[0] S[0] tmp a += 1 1 a
S = input()
K = int(input())

N = len(S)
#全て同じ文字の時
if len(set(S)) == 1:
    print(N*K//2)
    exit()

#隣合う文字列が何個等しいか
cycle = 0
tmp = S[0]
cnt = 1
for i in range(1, N):
    if tmp != S[i]:
        cycle += cnt//2
        tmp = S[i]
        cnt = 1
    else:
        cnt += 1
cycle += cnt//2

if S[0] == S[-1]:
    i = 0
    a = 0
    tmp = S[0]
    while S[i] == tmp:
        i += 1
        a += 1
    j = N-1
    b = 0
    tmp = S[-1]
    while S[j] == tmp:
        j -= 1
        b += 1
    print((cycle*K) - (a//2 + b//2 - (a+b)//2)*(K-1))
else:
    print(cycle*K)