S = input()
K = int(input())

length = len(S)

num_fixed = 0
pre_char = ''
count = 0
for i in range(length):
    now_char = S[i]
    if pre_char != now_char:
        num_fixed += count//2
        count = 0
    count += 1
    pre_char = now_char
    # print("pre_char:{}, now_char:{}, count:{}".format(pre_char, now_char, count))
num_fixed += count//2

# print(num_fixed)

if S[0] == S[length - 1]:
    head_length = 1
    head_char = S[0]
    for i in range(1, length):
        now_char = S[i]
        if now_char != head_char:
            break
        head_length += 1
    tail_length = 1
    tail_char = S[length - 1]
    for i in range(1, length):
        now_char = S[length - 1 - i]
        if now_char != tail_char:
            break
        tail_length += 1
    if length == head_length == tail_length:
        ans = length * K // 2
    else:
        ans = K * num_fixed - (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2)
else:
    ans = num_fixed * K

print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input length = len(S) length len(S) len S num_fixed = 0 num_fixed 0 pre_char = '' pre_char '' count = 0 count 0 for i in range(length):
    now_char = S[i]
    if pre_char != now_char:
        num_fixed += count//2
        count = 0
    count += 1
    pre_char = now_char
    # print("pre_char:{}, now_char:{}, count:{}".format(pre_char, now_char, count)) i range(length) range length now_char = S[i] now_char S[i] S i if pre_char != now_char:
        num_fixed += count//2
        count = 0
     pre_char != now_char pre_char now_char num_fixed += count//2 num_fixed count//2 count 2 count = 0 count 0 count += 1 count 1 pre_char = now_char pre_char now_char num_fixed += count//2 num_fixed count//2 count 2 if S[0] == S[length - 1]:
    head_length = 1
    head_char = S[0]
    for i in range(1, length):
        now_char = S[i]
        if now_char != head_char:
            break
        head_length += 1
    tail_length = 1
    tail_char = S[length - 1]
    for i in range(1, length):
        now_char = S[length - 1 - i]
        if now_char != tail_char:
            break
        tail_length += 1
    if length == head_length == tail_length:
        ans = length * K // 2
    else:
        ans = K * num_fixed - (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2)
else:
    ans = num_fixed * K S[0] == S[length - 1] S[0] S 0 S[length - 1] S length - 1 length 1 head_length = 1 head_length 1 head_char = S[0] head_char S[0] S 0 for i in range(1, length):
        now_char = S[i]
        if now_char != head_char:
            break
        head_length += 1
     i range(1, length) range 1 length now_char = S[i] now_char S[i] S i if now_char != head_char:
            break
         now_char != head_char now_char head_char break head_length += 1 head_length 1 tail_length = 1 tail_length 1 tail_char = S[length - 1] tail_char S[length - 1] S length - 1 length 1 for i in range(1, length):
        now_char = S[length - 1 - i]
        if now_char != tail_char:
            break
        tail_length += 1
     i range(1, length) range 1 length now_char = S[length - 1 - i] now_char S[length - 1 - i] S length - 1 - i length - 1 length 1 i if now_char != tail_char:
            break
         now_char != tail_char now_char tail_char break tail_length += 1 tail_length 1 if length == head_length == tail_length:
        ans = length * K // 2
    else:
        ans = K * num_fixed - (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2) length == head_length == tail_length length == head_length length head_length tail_length ans = length * K // 2 ans length * K // 2 length * K length K 2 ans = K * num_fixed - (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2) ans K * num_fixed - (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2) K * num_fixed K num_fixed (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2) K - 1 K 1 head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2 head_length // 2 + tail_length // 2 head_length // 2 head_length 2 tail_length // 2 tail_length 2 (head_length + tail_length) // 2 head_length + tail_length head_length tail_length 2 ans = num_fixed * K ans num_fixed * K num_fixed K print(ans) print ans tail_char = S[length - 1] S[length - 1] tail_char tail_length += 1 1 tail_length now_char = S[i] S[i] now_char head_length += 1 1 head_length num_fixed += count//2 count//2 num_fixed ans = K * num_fixed - (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2) K * num_fixed - (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2) ans length = len(S) len(S) length count = 0 0 count num_fixed += count//2 count//2 num_fixed K = int(input()) int(input()) K pre_char = '' '' pre_char head_char = S[0] S[0] head_char now_char = S[length - 1 - i] S[length - 1 - i] now_char ans = num_fixed * K num_fixed * K ans S = input() input() S count = 0 0 count tail_length = 1 1 tail_length num_fixed = 0 0 num_fixed now_char = S[i] S[i] now_char ans = length * K // 2 length * K // 2 ans pre_char = now_char now_char pre_char count += 1 1 count head_length = 1 1 head_length
S = input()
K = int(input())

length = len(S)

num_fixed = 0
pre_char = ''
count = 0
for i in range(length):
    now_char = S[i]
    if pre_char != now_char:
        num_fixed += count//2
        count = 0
    count += 1
    pre_char = now_char
    # print("pre_char:{}, now_char:{}, count:{}".format(pre_char, now_char, count))
num_fixed += count//2

# print(num_fixed)

if S[0] == S[length - 1]:
    head_length = 1
    head_char = S[0]
    for i in range(1, length):
        now_char = S[i]
        if now_char != head_char:
            break
        head_length += 1
    tail_length = 1
    tail_char = S[length - 1]
    for i in range(1, length):
        now_char = S[length - 1 - i]
        if now_char != tail_char:
            break
        tail_length += 1
    if length == head_length == tail_length:
        ans = length * K // 2
    else:
        ans = K * num_fixed - (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2)
else:
    ans = num_fixed * K

print(ans)
