S = eval(input())

K = eval(input())



if not(1 <= len(S) and len(S) <= 100):

    exit()

if not (S.isalpha() and S.islower()):

    exit()

if not float(K).is_integer():

    exit()

if not (1 <= int(K) and int(K) <= 10 ** 9):

    exit()



L = []

tmp = []

pre = ""

for s in S:

    if len(tmp) == 0:

        pre = s

        tmp.append(s)

    elif pre == s:

        tmp.append(s)

    else:

        L.append(tmp)

        pre = s

        tmp = [s]

L.append(tmp)



count = 0

for l in L:

    count += int(len(l) / 2)

    # print(l)

count *= int(K)

if len(L) == 1:

    if len(L[0]) == 1:

        count = int(int(K) / 2)

    elif len(L[0]) % 2 == 1:

        count += int(int(K) / 2)

    

elif L[0][0] == L[len(L)-1][0]:

    if len(L[0]) % 2 == 1 and len(L[len(L)-1]) % 2 == 1:

        count = count + int(K) - 1

print(count)

S = eval(input())

K = eval(input())



L = []

tmp = []

pre = ""

for s in S:

    if len(tmp) == 0:

        pre = s

        tmp.append(s)

    elif pre == s:

        tmp.append(s)

    else:

        L.append(tmp)

        pre = s

        tmp = [s]

L.append(tmp)



count = 0

for l in L:

    count += int(len(l) / 2)

    # print(l)

count *= int(K)

if len(L) == 1:

    if len(L[0]) == 1:

        count = int(int(K) / 2)

    elif len(L[0]) % 2 == 1:

        count += int(int(K) / 2)



elif L[0][0] == L[len(L)-1][0]:

    if len(L[0]) % 2 == 1 and len(L[len(L)-1]) % 2 == 1:

        count = count + int(K) - 1

print(count)

S = eval(input())
K = eval(input())
if not (1 <= len(S) and len(S) <= 100):
    exit()
if not (S.isalpha() and S.islower()):
    exit()
if not float(K).is_integer():
    exit()
if not (1 <= int(K) and int(K) <= 10**9):
    exit()
L = []
tmp = []
pre = ""
for s in S:
    if len(tmp) == 0:
        pre = s
        tmp.append(s)
    elif pre == s:
        tmp.append(s)
    else:
        L.append(tmp)
        pre = s
        tmp = [s]
L.append(tmp)
count = 0
for l in L:
    count += int(len(l) / 2)
    # print(l)
count *= int(K)
if len(L) == 1:
    if len(L[0]) == 1:
        count = int(int(K) / 2)
    elif len(L[0]) % 2 == 1:
        count += int(int(K) / 2)
elif L[0][0] == L[len(L) - 1][0]:
    if len(L[0]) % 2 == 1 and len(L[len(L) - 1]) % 2 == 1:
        count = count + int(K) - 1
print(count)

S = eval(input())
K = eval(input())
L = []
tmp = []
pre = ""
for s in S:
    if len(tmp) == 0:
        pre = s
        tmp.append(s)
    elif pre == s:
        tmp.append(s)
    else:
        L.append(tmp)
        pre = s
        tmp = [s]
L.append(tmp)
count = 0
for l in L:
    count += int(len(l) / 2)
    # print(l)
count *= int(K)
if len(L) == 1:
    if len(L[0]) == 1:
        count = int(int(K) / 2)
    elif len(L[0]) % 2 == 1:
        count += int(int(K) / 2)
elif L[0][0] == L[len(L) - 1][0]:
    if len(L[0]) % 2 == 1 and len(L[len(L) - 1]) % 2 == 1:
        count = count + int(K) - 1
print(count)

-if not (1 <= len(S) and len(S) <= 100): -    exit() -if not (S.isalpha() and S.islower()): -    exit() -if not float(K).is_integer(): -    exit() -if not (1 <= int(K) and int(K) <= 10**9): -    exit()