S = input()
k = int(input())

prev = S[0]
cnt = 0
for i in range(1,len(S)):
    if prev == S[i]:
        cnt += 1
        prev = "$"
        continue
    prev = S[i]

ans = k*cnt

if S[0] == S[-1]:
    m = 0
    for s in S:
        if s == S[0]:
            m += 1
        else:
            break
    a = 0
    for s in S[::-1]:
        if s == S[-1]:
            a += 1
        else:
            break
    if a%2 and m%2:
        ans += k-1
if len(set(S)) == 1:
    ans = (len(S)*k//2)
print(ans) S = input() S input() input k = int(input()) k int(input()) int input() input prev = S[0] prev S[0] S 0 cnt = 0 cnt 0 for i in range(1,len(S)):
    if prev == S[i]:
        cnt += 1
        prev = "$"
        continue
    prev = S[i] i range(1,len(S)) range 1 len(S) len S if prev == S[i]:
        cnt += 1
        prev = "$"
        continue
     prev == S[i] prev S[i] S i cnt += 1 cnt 1 prev = "$" prev "$" continue prev = S[i] prev S[i] S i ans = k*cnt ans k*cnt k cnt if S[0] == S[-1]:
    m = 0
    for s in S:
        if s == S[0]:
            m += 1
        else:
            break
    a = 0
    for s in S[::-1]:
        if s == S[-1]:
            a += 1
        else:
            break
    if a%2 and m%2:
        ans += k-1 S[0] == S[-1] S[0] S 0 S[-1] S -1 m = 0 m 0 for s in S:
        if s == S[0]:
            m += 1
        else:
            break
     s S if s == S[0]:
            m += 1
        else:
            break
     s == S[0] s S[0] S 0 m += 1 m 1 break a = 0 a 0 for s in S[::-1]:
        if s == S[-1]:
            a += 1
        else:
            break
     s S[::-1] S ::-1 -1 if s == S[-1]:
            a += 1
        else:
            break
     s == S[-1] s S[-1] S -1 a += 1 a 1 break if a%2 and m%2:
        ans += k-1 a%2 and m%2 a%2 a 2 m%2 m 2 ans += k-1 ans k-1 k 1 if len(set(S)) == 1:
    ans = (len(S)*k//2) len(set(S)) == 1 len(set(S)) len set(S) set S 1 ans = (len(S)*k//2) ans len(S)*k//2 len(S)*k len(S) len S k 2 print(ans) print ans cnt = 0 0 cnt a += 1 1 a prev = "$" "$" prev ans += k-1 k-1 ans cnt += 1 1 cnt S = input() input() S k = int(input()) int(input()) k m = 0 0 m m += 1 1 m prev = S[i] S[i] prev ans = k*cnt k*cnt ans a = 0 0 a ans = (len(S)*k//2) len(S)*k//2 ans prev = S[0] S[0] prev
S = input()
k = int(input())

prev = S[0]
cnt = 0
for i in range(1,len(S)):
    if prev == S[i]:
        cnt += 1
        prev = "$"
        continue
    prev = S[i]

ans = k*cnt

if S[0] == S[-1]:
    m = 0
    for s in S:
        if s == S[0]:
            m += 1
        else:
            break
    a = 0
    for s in S[::-1]:
        if s == S[-1]:
            a += 1
        else:
            break
    if a%2 and m%2:
        ans += k-1
if len(set(S)) == 1:
    ans = (len(S)*k//2)
print(ans)