s = eval(input())

k = int(eval(input()))



if len(set(s)) == 1:

    print(((len(s)*k)//2))

    exit()



ss = s + s



shoko = 0

prev = ''

cnt = 0

for i in range(len(s)):

    if s[i] == prev:

        cnt += 1

    else:

        shoko += cnt // 2

        cnt = 1

    prev = s[i]

shoko += cnt // 2



kosa = 0

prev = ''

cnt = 0

for i in range(len(ss)):

    if ss[i] == prev:

        cnt += 1

    else:

        kosa += cnt // 2

        cnt = 1

    prev = ss[i]

kosa += cnt // 2

kosa -= shoko



print((shoko + (k-1)*kosa))
s = eval(input())

k = int(eval(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 = eval(input())
k = int(eval(input()))
if len(set(s)) == 1:
    print(((len(s) * k) // 2))
    exit()
ss = s + s
shoko = 0
prev = ""
cnt = 0
for i in range(len(s)):
    if s[i] == prev:
        cnt += 1
    else:
        shoko += cnt // 2
        cnt = 1
    prev = s[i]
shoko += cnt // 2
kosa = 0
prev = ""
cnt = 0
for i in range(len(ss)):
    if ss[i] == prev:
        cnt += 1
    else:
        kosa += cnt // 2
        cnt = 1
    prev = ss[i]
kosa += cnt // 2
kosa -= shoko
print((shoko + (k - 1) * kosa))

s = eval(input())
k = int(eval(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)))

+n = len(s) -    print(((len(s) * k) // 2)) +    print((n * k // 2)) -shoko = 0 -prev = "" -cnt = 0 -for i in range(len(s)): -    if s[i] == prev: -        cnt += 1 +cnts = 0 +now = s[0] +temp = 1 +for i in range(1, n): +    if s[i] == now: +        temp += 1 -        shoko += cnt // 2 -        cnt = 1 -    prev = s[i] -shoko += cnt // 2 -kosa = 0 -prev = "" -cnt = 0 -for i in range(len(ss)): -    if ss[i] == prev: -        cnt += 1 +        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 -        kosa += cnt // 2 -        cnt = 1 -    prev = ss[i] -kosa += cnt // 2 -kosa -= shoko -print((shoko + (k - 1) * kosa)) +        cntss += temp // 2 +        temp = 1 +        now = ss[i] +cntss += temp // 2 +kousa = cntss - cnts +print((cnts + kousa * (k - 1)))