s = input()
k = int(input())

if len(s) == 1:
    print(k//2)
    exit()

rep = [1]
prev = s[0]
for i in range(1, len(s)):
    if s[i] == prev:
        rep[-1] += 1
    else:
        rep.append(1)
        prev = s[i]

if len(rep) == 1:
    print(rep[0]*k//2)
    exit()

cnt = 0
for r in rep:
    cnt += r//2

if s[0] == s[-1]:
    ans = cnt*k + ((rep[0]+rep[-1])//2 - rep[0]//2 - rep[-1]//2)*(k-1)
    print(ans)
else:
    print(cnt*k) s = input() s input() input k = int(input()) k int(input()) int input() input if len(s) == 1:
    print(k//2)
    exit() len(s) == 1 len(s) len s 1 print(k//2) print k//2 k 2 exit() exit rep = [1] rep [1] 1 prev = s[0] prev s[0] s 0 for i in range(1, len(s)):
    if s[i] == prev:
        rep[-1] += 1
    else:
        rep.append(1)
        prev = s[i] i range(1, len(s)) range 1 len(s) len s if s[i] == prev:
        rep[-1] += 1
    else:
        rep.append(1)
        prev = s[i] s[i] == prev s[i] s i prev rep[-1] += 1 rep[-1] rep -1 1 rep.append(1) rep.append rep append 1 prev = s[i] prev s[i] s i if len(rep) == 1:
    print(rep[0]*k//2)
    exit() len(rep) == 1 len(rep) len rep 1 print(rep[0]*k//2) print rep[0]*k//2 rep[0]*k rep[0] rep 0 k 2 exit() exit cnt = 0 cnt 0 for r in rep:
    cnt += r//2 r rep cnt += r//2 cnt r//2 r 2 if s[0] == s[-1]:
    ans = cnt*k + ((rep[0]+rep[-1])//2 - rep[0]//2 - rep[-1]//2)*(k-1)
    print(ans)
else:
    print(cnt*k) s[0] == s[-1] s[0] s 0 s[-1] s -1 ans = cnt*k + ((rep[0]+rep[-1])//2 - rep[0]//2 - rep[-1]//2)*(k-1) ans cnt*k + ((rep[0]+rep[-1])//2 - rep[0]//2 - rep[-1]//2)*(k-1) cnt*k cnt k ((rep[0]+rep[-1])//2 - rep[0]//2 - rep[-1]//2)*(k-1) (rep[0]+rep[-1])//2 - rep[0]//2 - rep[-1]//2 (rep[0]+rep[-1])//2 - rep[0]//2 (rep[0]+rep[-1])//2 rep[0]+rep[-1] rep[0] rep 0 rep[-1] rep -1 2 rep[0]//2 rep[0] rep 0 2 rep[-1]//2 rep[-1] rep -1 2 k-1 k 1 print(ans) print ans print(cnt*k) print cnt*k cnt k prev = s[0] s[0] prev k = int(input()) int(input()) k prev = s[i] s[i] prev s = input() input() s cnt = 0 0 cnt cnt += r//2 r//2 cnt rep = [1] [1] rep ans = cnt*k + ((rep[0]+rep[-1])//2 - rep[0]//2 - rep[-1]//2)*(k-1) cnt*k + ((rep[0]+rep[-1])//2 - rep[0]//2 - rep[-1]//2)*(k-1) ans
s = input()
k = int(input())

if len(s) == 1:
    print(k//2)
    exit()

rep = [1]
prev = s[0]
for i in range(1, len(s)):
    if s[i] == prev:
        rep[-1] += 1
    else:
        rep.append(1)
        prev = s[i]

if len(rep) == 1:
    print(rep[0]*k//2)
    exit()

cnt = 0
for r in rep:
    cnt += r//2

if s[0] == s[-1]:
    ans = cnt*k + ((rep[0]+rep[-1])//2 - rep[0]//2 - rep[-1]//2)*(k-1)
    print(ans)
else:
    print(cnt*k)
