#!/usr/bin/env python3

s = list(str(input()))
k = int(input())

count = [[s[0], 1]]


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

ans = 0
if len(count) == 1:
    ans += (count[0][1]*k)//2

elif count[0][0] != count[-1][0]:
    for i in range(0, len(count)):
        letter, num = count[i]
        ans += (num//2)*k
else:
    for i in range(1, len(count)-1):
        letter, num = count[i]
        ans += (num//2)*k

    letter, num = count[0][0], count[0][1]+count[-1][1]
    ans += (num//2)*(k-1)

    ans += count[0][1]//2
    ans += count[-1][1]//2

print(ans) s = list(str(input())) s list(str(input())) list str(input()) str input() input k = int(input()) k int(input()) int input() input count = [[s[0], 1]] count [[s[0], 1]] [s[0], 1] s[0] s 0 1 for i in range(1, len(s)):
    if count[-1][0] == s[i]:
        count[-1][1] += 1
    else:
        count.append([s[i], 1])
# print(count) i range(1, len(s)) range 1 len(s) len s if count[-1][0] == s[i]:
        count[-1][1] += 1
    else:
        count.append([s[i], 1])
# print(count) count[-1][0] == s[i] count[-1][0] [-1] count -1 0 s[i] s i count[-1][1] += 1 count[-1][1] [-1] count -1 1 1 count.append([s[i], 1]) count.append count append [s[i], 1] s[i] s i 1 ans = 0 ans 0 if len(count) == 1:
    ans += (count[0][1]*k)//2

elif count[0][0] != count[-1][0]:
    for i in range(0, len(count)):
        letter, num = count[i]
        ans += (num//2)*k
else:
    for i in range(1, len(count)-1):
        letter, num = count[i]
        ans += (num//2)*k

    letter, num = count[0][0], count[0][1]+count[-1][1]
    ans += (num//2)*(k-1)

    ans += count[0][1]//2
    ans += count[-1][1]//2 len(count) == 1 len(count) len count 1 ans += (count[0][1]*k)//2 ans (count[0][1]*k)//2 count[0][1]*k count[0][1] [0] count 0 1 k 2 elif count[0][0] != count[-1][0]:
    for i in range(0, len(count)):
        letter, num = count[i]
        ans += (num//2)*k count[0][0] != count[-1][0] count[0][0] [0] count 0 0 count[-1][0] [-1] count -1 0 for i in range(0, len(count)):
        letter, num = count[i]
        ans += (num//2)*k i range(0, len(count)) range 0 len(count) len count letter, num = count[i] letter count[i] count i num ans += (num//2)*k ans (num//2)*k num//2 num 2 k for i in range(1, len(count)-1):
        letter, num = count[i]
        ans += (num//2)*k

     i range(1, len(count)-1) range 1 len(count)-1 len(count) len count 1 letter, num = count[i] letter count[i] count i num ans += (num//2)*k ans (num//2)*k num//2 num 2 k letter, num = count[0][0], count[0][1]+count[-1][1] letter count[0][0] [0] count 0 0 num count[0][1]+count[-1][1] count[0][1] [0] count 0 1 count[-1][1] [-1] count -1 1 ans += (num//2)*(k-1) ans (num//2)*(k-1) num//2 num 2 k-1 k 1 ans += count[0][1]//2 ans count[0][1]//2 count[0][1] [0] count 0 1 2 ans += count[-1][1]//2 ans count[-1][1]//2 count[-1][1] [-1] count -1 1 2 print(ans) print ans ans += (num//2)*k (num//2)*k ans ans += count[0][1]//2 count[0][1]//2 ans num = count[i] count[i] num k = int(input()) int(input()) k ans += (count[0][1]*k)//2 (count[0][1]*k)//2 ans count = [[s[0], 1]] [[s[0], 1]] count ans += (num//2)*(k-1) (num//2)*(k-1) ans num = count[i] count[i] num letter, num = count[0][0], count[0][1]+count[-1][1] count[0][0] letter ans += count[-1][1]//2 count[-1][1]//2 ans letter, num = count[i] count[i] letter ans += (num//2)*k (num//2)*k ans s = list(str(input())) list(str(input())) s num = count[0][0], count[0][1]+count[-1][1] count[0][1]+count[-1][1] num ans = 0 0 ans letter, num = count[i] count[i] letter
#!/usr/bin/env python3

s = list(str(input()))
k = int(input())

count = [[s[0], 1]]


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

ans = 0
if len(count) == 1:
    ans += (count[0][1]*k)//2

elif count[0][0] != count[-1][0]:
    for i in range(0, len(count)):
        letter, num = count[i]
        ans += (num//2)*k
else:
    for i in range(1, len(count)-1):
        letter, num = count[i]
        ans += (num//2)*k

    letter, num = count[0][0], count[0][1]+count[-1][1]
    ans += (num//2)*(k-1)

    ans += count[0][1]//2
    ans += count[-1][1]//2

print(ans)
