s = input()
k = int(input())
n = len(s)

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

ss = s + s
cnts = 0
now = s[0]
temp = 1
for i in range(1, n):
    if s[i] == now:
        temp += 1
    else:
        cnts += temp // 2
        temp = 1
        now = s[i]
cnts += temp // 2

cntss = 0
now = ss[0]
temp = 1
for i in range(1, 2*n):
    if ss[i] == now:
        temp += 1
    else:
        cntss += temp // 2
        temp = 1
        now = ss[i]
cntss += temp // 2

kousa = cntss - cnts
print(cnts + kousa*(k-1)) s = input() s input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s if len(set(s)) == 1:
    print(n*k//2)
    exit() len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(n*k//2) print n*k//2 n*k n k 2 exit() exit ss = s + s ss s + s s s cnts = 0 cnts 0 now = s[0] now s[0] s 0 temp = 1 temp 1 for i in range(1, n):
    if s[i] == now:
        temp += 1
    else:
        cnts += temp // 2
        temp = 1
        now = s[i] i range(1, n) range 1 n if s[i] == now:
        temp += 1
    else:
        cnts += temp // 2
        temp = 1
        now = s[i] s[i] == now s[i] s i now temp += 1 temp 1 cnts += temp // 2 cnts temp // 2 temp 2 temp = 1 temp 1 now = s[i] now s[i] s i cnts += temp // 2 cnts temp // 2 temp 2 cntss = 0 cntss 0 now = ss[0] now ss[0] ss 0 temp = 1 temp 1 for i in range(1, 2*n):
    if ss[i] == now:
        temp += 1
    else:
        cntss += temp // 2
        temp = 1
        now = ss[i] i range(1, 2*n) range 1 2*n 2 n if ss[i] == now:
        temp += 1
    else:
        cntss += temp // 2
        temp = 1
        now = ss[i] ss[i] == now ss[i] ss i now temp += 1 temp 1 cntss += temp // 2 cntss temp // 2 temp 2 temp = 1 temp 1 now = ss[i] now ss[i] ss i cntss += temp // 2 cntss temp // 2 temp 2 kousa = cntss - cnts kousa cntss - cnts cntss cnts print(cnts + kousa*(k-1)) print cnts + kousa*(k-1) cnts kousa*(k-1) kousa k-1 k 1 cnts = 0 0 cnts s = input() input() s now = ss[i] ss[i] now temp += 1 1 temp k = int(input()) int(input()) k cnts += temp // 2 temp // 2 cnts kousa = cntss - cnts cntss - cnts kousa temp = 1 1 temp now = s[0] s[0] now temp = 1 1 temp cntss += temp // 2 temp // 2 cntss n = len(s) len(s) n temp = 1 1 temp temp = 1 1 temp temp += 1 1 temp cntss += temp // 2 temp // 2 cntss cnts += temp // 2 temp // 2 cnts now = ss[0] ss[0] now now = s[i] s[i] now cntss = 0 0 cntss ss = s + s s + s ss
s = input()
k = int(input())
n = len(s)

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

ss = s + s
cnts = 0
now = s[0]
temp = 1
for i in range(1, n):
    if s[i] == now:
        temp += 1
    else:
        cnts += temp // 2
        temp = 1
        now = s[i]
cnts += temp // 2

cntss = 0
now = ss[0]
temp = 1
for i in range(1, 2*n):
    if ss[i] == now:
        temp += 1
    else:
        cntss += temp // 2
        temp = 1
        now = ss[i]
cntss += temp // 2

kousa = cntss - cnts
print(cnts + kousa*(k-1))