import sys
input = sys.stdin.readline

s = list(input().rstrip())
k = int(input())
n = len(s)

group = []

cnt = 0

from collections import Counter
c = Counter(s)
if len(c) == 1:
    print(n*k//2)
    sys.exit()

for i in range(n):
    if i == 0:
        cnt += 1
        continue
    elif i == n - 1:
        if s[i] == s[i - 1]:
            cnt += 1
            group.append(cnt)
        else:
            group.append(cnt)
            group.append(1)
        continue
    
    if s[i] == s[i - 1]:
        cnt += 1
    else:
        group.append(cnt)
        cnt = 1
ans = 0
if k == 1:
    for i in group:
        ans += i//2
    print(ans)
    sys.exit()
from copy import deepcopy
first = deepcopy(group)
last = deepcopy(group)
if s[0] == s[-1]:
    first[-1] += last[0]
    last[0] = 0

for i in first:
    ans += i//2
for i in last:
    ans += i//2
if k == 2:
    print(ans)
    sys.exit()
mid = deepcopy(first)
if s[0] == s[-1]:
    mid[0] = 0
temp = 0
for i in mid:
    temp += i//2
ans += temp*(k - 2)
print(ans)

 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline s = list(input().rstrip()) s list(input().rstrip()) list input().rstrip() ().rstrip () input rstrip k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s group = [] group [] cnt = 0 cnt 0 from collections import Counter c = Counter(s) c Counter(s) Counter s if len(c) == 1:
    print(n*k//2)
    sys.exit() len(c) == 1 len(c) len c 1 print(n*k//2) print n*k//2 n*k n k 2 sys.exit() sys.exit sys exit for i in range(n):
    if i == 0:
        cnt += 1
        continue
    elif i == n - 1:
        if s[i] == s[i - 1]:
            cnt += 1
            group.append(cnt)
        else:
            group.append(cnt)
            group.append(1)
        continue
    
    if s[i] == s[i - 1]:
        cnt += 1
    else:
        group.append(cnt)
        cnt = 1 i range(n) range n if i == 0:
        cnt += 1
        continue
    elif i == n - 1:
        if s[i] == s[i - 1]:
            cnt += 1
            group.append(cnt)
        else:
            group.append(cnt)
            group.append(1)
        continue
    
     i == 0 i 0 cnt += 1 cnt 1 continue elif i == n - 1:
        if s[i] == s[i - 1]:
            cnt += 1
            group.append(cnt)
        else:
            group.append(cnt)
            group.append(1)
        continue
    
     i == n - 1 i n - 1 n 1 if s[i] == s[i - 1]:
            cnt += 1
            group.append(cnt)
        else:
            group.append(cnt)
            group.append(1)
         s[i] == s[i - 1] s[i] s i s[i - 1] s i - 1 i 1 cnt += 1 cnt 1 group.append(cnt) group.append group append cnt group.append(cnt) group.append group append cnt group.append(1) group.append group append 1 continue if s[i] == s[i - 1]:
        cnt += 1
    else:
        group.append(cnt)
        cnt = 1 s[i] == s[i - 1] s[i] s i s[i - 1] s i - 1 i 1 cnt += 1 cnt 1 group.append(cnt) group.append group append cnt cnt = 1 cnt 1 ans = 0 ans 0 if k == 1:
    for i in group:
        ans += i//2
    print(ans)
    sys.exit() k == 1 k 1 for i in group:
        ans += i//2
     i group ans += i//2 ans i//2 i 2 print(ans) print ans sys.exit() sys.exit sys exit from copy import deepcopy first = deepcopy(group) first deepcopy(group) deepcopy group last = deepcopy(group) last deepcopy(group) deepcopy group if s[0] == s[-1]:
    first[-1] += last[0]
    last[0] = 0 s[0] == s[-1] s[0] s 0 s[-1] s -1 first[-1] += last[0] first[-1] first -1 last[0] last 0 last[0] = 0 last[0] last 0 0 for i in first:
    ans += i//2 i first ans += i//2 ans i//2 i 2 for i in last:
    ans += i//2 i last ans += i//2 ans i//2 i 2 if k == 2:
    print(ans)
    sys.exit() k == 2 k 2 print(ans) print ans sys.exit() sys.exit sys exit mid = deepcopy(first) mid deepcopy(first) deepcopy first if s[0] == s[-1]:
    mid[0] = 0 s[0] == s[-1] s[0] s 0 s[-1] s -1 mid[0] = 0 mid[0] mid 0 0 temp = 0 temp 0 for i in mid:
    temp += i//2 i mid temp += i//2 temp i//2 i 2 ans += temp*(k - 2) ans temp*(k - 2) temp k - 2 k 2 print(ans) print ans s = list(input().rstrip()) list(input().rstrip()) s ans = 0 0 ans input = sys.stdin.readline sys.stdin.readline input cnt += 1 1 cnt last = deepcopy(group) deepcopy(group) last ans += i//2 i//2 ans cnt += 1 1 cnt cnt = 0 0 cnt n = len(s) len(s) n first = deepcopy(group) deepcopy(group) first temp = 0 0 temp cnt += 1 1 cnt ans += i//2 i//2 ans k = int(input()) int(input()) k temp += i//2 i//2 temp cnt = 1 1 cnt mid = deepcopy(first) deepcopy(first) mid c = Counter(s) Counter(s) c group = [] [] group ans += i//2 i//2 ans ans += temp*(k - 2) temp*(k - 2) ans
import sys
input = sys.stdin.readline

s = list(input().rstrip())
k = int(input())
n = len(s)

group = []

cnt = 0

from collections import Counter
c = Counter(s)
if len(c) == 1:
    print(n*k//2)
    sys.exit()

for i in range(n):
    if i == 0:
        cnt += 1
        continue
    elif i == n - 1:
        if s[i] == s[i - 1]:
            cnt += 1
            group.append(cnt)
        else:
            group.append(cnt)
            group.append(1)
        continue
    
    if s[i] == s[i - 1]:
        cnt += 1
    else:
        group.append(cnt)
        cnt = 1
ans = 0
if k == 1:
    for i in group:
        ans += i//2
    print(ans)
    sys.exit()
from copy import deepcopy
first = deepcopy(group)
last = deepcopy(group)
if s[0] == s[-1]:
    first[-1] += last[0]
    last[0] = 0

for i in first:
    ans += i//2
for i in last:
    ans += i//2
if k == 2:
    print(ans)
    sys.exit()
mid = deepcopy(first)
if s[0] == s[-1]:
    mid[0] = 0
temp = 0
for i in mid:
    temp += i//2
ans += temp*(k - 2)
print(ans)


