import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
N = len(S)
K = ii()
cnt = 0
#for i in range(1, N):
i = 1
flag = 0

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

while i < N:
    if S[i] == S[i-1]:
        cnt += 1
        if i + 1 < N and S[i] == S[i+1]:
            i += 1
        if i == N-1:
            flag = 1
    i += 1

if flag and S[0] == S[-1]:
    cnt += 1
    cnt_sub = 0
    S = S[1:] + S[0]
    i = 1
    flag = 0
    while i < N:
        if S[i] == S[i-1]:
            cnt_sub += 1
            if i + 1 < N and S[i] == S[i+1]:
                i += 1
        i += 1
    print(cnt + cnt_sub * (K-2) + cnt_sub - 1)

else:
    print(cnt * K) import sys sys sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 def ii(): return int(sys.stdin.readline()) ii def mi(): return map(int, sys.stdin.readline().split()) mi def li(): return list(map(int, sys.stdin.readline().split())) li list(map(int, sys.stdin.readline().split())) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) list(map(int, sys.stdin.readline().split())) list map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] li2 N N [ini]*i for _ in range(j) for _ in range(j) _ range(j) range j for _ in range(j) [ini]*i [ini] ini i def dp2(ini, i, j): return [[ini]*i for _ in range(j)] dp2 ini ini i i j j [[ini]*i for _ in range(j)] for _ in range(k) for _ in range(k) _ range(k) range k for _ in range(k) [[ini]*i for _ in range(j)] def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A)) dp3 ini ini i i j j k k S = input() S input() input N = len(S) N len(S) len S K = ii() K ii() ii cnt = 0 cnt 0 i = 1 i 1 flag = 0 flag 0 if S.count(S[0]) == N:
    print(N * K // 2)
    exit() S.count(S[0]) == N S.count(S[0]) S.count S count S[0] S 0 N print(N * K // 2) print N * K // 2 N * K N K 2 exit() exit while i < N:
    if S[i] == S[i-1]:
        cnt += 1
        if i + 1 < N and S[i] == S[i+1]:
            i += 1
        if i == N-1:
            flag = 1
    i += 1 i < N i N if S[i] == S[i-1]:
        cnt += 1
        if i + 1 < N and S[i] == S[i+1]:
            i += 1
        if i == N-1:
            flag = 1
     S[i] == S[i-1] S[i] S i S[i-1] S i-1 i 1 cnt += 1 cnt 1 if i + 1 < N and S[i] == S[i+1]:
            i += 1
         i + 1 < N and S[i] == S[i+1] i + 1 < N i + 1 i 1 N S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 i += 1 i 1 if i == N-1:
            flag = 1
     i == N-1 i N-1 N 1 flag = 1 flag 1 i += 1 i 1 if flag and S[0] == S[-1]:
    cnt += 1
    cnt_sub = 0
    S = S[1:] + S[0]
    i = 1
    flag = 0
    while i < N:
        if S[i] == S[i-1]:
            cnt_sub += 1
            if i + 1 < N and S[i] == S[i+1]:
                i += 1
        i += 1
    print(cnt + cnt_sub * (K-2) + cnt_sub - 1)

else:
    print(cnt * K) flag and S[0] == S[-1] flag S[0] == S[-1] S[0] S 0 S[-1] S -1 cnt += 1 cnt 1 cnt_sub = 0 cnt_sub 0 S = S[1:] + S[0] S S[1:] + S[0] S[1:] S 1: 1 S[0] S 0 i = 1 i 1 flag = 0 flag 0 while i < N:
        if S[i] == S[i-1]:
            cnt_sub += 1
            if i + 1 < N and S[i] == S[i+1]:
                i += 1
        i += 1
     i < N i N if S[i] == S[i-1]:
            cnt_sub += 1
            if i + 1 < N and S[i] == S[i+1]:
                i += 1
         S[i] == S[i-1] S[i] S i S[i-1] S i-1 i 1 cnt_sub += 1 cnt_sub 1 if i + 1 < N and S[i] == S[i+1]:
                i += 1
         i + 1 < N and S[i] == S[i+1] i + 1 < N i + 1 i 1 N S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 i += 1 i 1 i += 1 i 1 print(cnt + cnt_sub * (K-2) + cnt_sub - 1) print cnt + cnt_sub * (K-2) + cnt_sub - 1 cnt + cnt_sub * (K-2) + cnt_sub cnt + cnt_sub * (K-2) cnt cnt_sub * (K-2) cnt_sub K-2 K 2 cnt_sub 1 print(cnt * K) print cnt * K cnt K i = 1 1 i i += 1 1 i def li(): return list(map(int, sys.stdin.readline().split())) def li(): return list(map(int, sys.stdin.readline().split())) li def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A)) def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A)) dp3 cnt = 0 0 cnt i += 1 1 i flag = 0 0 flag K = ii() ii() K S = input() input() S S = S[1:] + S[0] S[1:] + S[0] S def dp2(ini, i, j): return [[ini]*i for _ in range(j)] def dp2(ini, i, j): return [[ini]*i for _ in range(j)] dp2 i += 1 1 i cnt_sub = 0 0 cnt_sub def ii(): return int(sys.stdin.readline()) def ii(): return int(sys.stdin.readline()) ii cnt += 1 1 cnt N = len(S) len(S) N cnt_sub += 1 1 cnt_sub flag = 1 1 flag def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)] li2 i += 1 1 i def mi(): return map(int, sys.stdin.readline().split()) def mi(): return map(int, sys.stdin.readline().split()) mi i = 1 1 i cnt += 1 1 cnt flag = 0 0 flag
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
N = len(S)
K = ii()
cnt = 0
#for i in range(1, N):
i = 1
flag = 0

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

while i < N:
    if S[i] == S[i-1]:
        cnt += 1
        if i + 1 < N and S[i] == S[i+1]:
            i += 1
        if i == N-1:
            flag = 1
    i += 1

if flag and S[0] == S[-1]:
    cnt += 1
    cnt_sub = 0
    S = S[1:] + S[0]
    i = 1
    flag = 0
    while i < N:
        if S[i] == S[i-1]:
            cnt_sub += 1
            if i + 1 < N and S[i] == S[i+1]:
                i += 1
        i += 1
    print(cnt + cnt_sub * (K-2) + cnt_sub - 1)

else:
    print(cnt * K)