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

N = len(S)
p = S[0]
c = 0

if N == 1:
    print(K//2)
    exit()

if len(set(S)) == 1:
    print(N*K//2)
    exit()

for i in range(1,N):
    if S[i] == p:
        c += 1
        p = ''
    else:
        p = S[i]

ans = c*K
if S[0] == S[-1]:
    p = S[0]
    c = 1
    for i in range(1,N):
        if p == S[i]:
            c += 1
        else:
            break

    d = 1
    for i in range(2,N+1):
        if p == S[-i]:
            d += 1
        else:
            break

    if (c%2)*(d%2) == 1:
        ans += K-1

print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S p = S[0] p S[0] S 0 c = 0 c 0 if N == 1:
    print(K//2)
    exit() N == 1 N 1 print(K//2) print K//2 K 2 exit() exit 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 for i in range(1,N):
    if S[i] == p:
        c += 1
        p = ''
    else:
        p = S[i] i range(1,N) range 1 N if S[i] == p:
        c += 1
        p = ''
    else:
        p = S[i] S[i] == p S[i] S i p c += 1 c 1 p = '' p '' p = S[i] p S[i] S i ans = c*K ans c*K c K if S[0] == S[-1]:
    p = S[0]
    c = 1
    for i in range(1,N):
        if p == S[i]:
            c += 1
        else:
            break

    d = 1
    for i in range(2,N+1):
        if p == S[-i]:
            d += 1
        else:
            break

    if (c%2)*(d%2) == 1:
        ans += K-1 S[0] == S[-1] S[0] S 0 S[-1] S -1 p = S[0] p S[0] S 0 c = 1 c 1 for i in range(1,N):
        if p == S[i]:
            c += 1
        else:
            break

     i range(1,N) range 1 N if p == S[i]:
            c += 1
        else:
            break

     p == S[i] p S[i] S i c += 1 c 1 break d = 1 d 1 for i in range(2,N+1):
        if p == S[-i]:
            d += 1
        else:
            break

     i range(2,N+1) range 2 N+1 N 1 if p == S[-i]:
            d += 1
        else:
            break

     p == S[-i] p S[-i] S -i i d += 1 d 1 break if (c%2)*(d%2) == 1:
        ans += K-1 (c%2)*(d%2) == 1 (c%2)*(d%2) c%2 c 2 d%2 d 2 1 ans += K-1 ans K-1 K 1 print(ans) print ans d = 1 1 d N = len(S) len(S) N d += 1 1 d p = S[0] S[0] p p = S[0] S[0] p ans = c*K c*K ans c = 0 0 c S = input() input() S p = S[i] S[i] p c += 1 1 c K = int(input()) int(input()) K ans += K-1 K-1 ans p = '' '' p c = 1 1 c c += 1 1 c
S = input()
K = int(input())

N = len(S)
p = S[0]
c = 0

if N == 1:
    print(K//2)
    exit()

if len(set(S)) == 1:
    print(N*K//2)
    exit()

for i in range(1,N):
    if S[i] == p:
        c += 1
        p = ''
    else:
        p = S[i]

ans = c*K
if S[0] == S[-1]:
    p = S[0]
    c = 1
    for i in range(1,N):
        if p == S[i]:
            c += 1
        else:
            break

    d = 1
    for i in range(2,N+1):
        if p == S[-i]:
            d += 1
        else:
            break

    if (c%2)*(d%2) == 1:
        ans += K-1

print(ans)
