S = input()
# A = [int(i) for i in input().split()]
K = int(input())

count_list = []
count = 0
for i in range(len(S)):
    count += 1
    if i == len(S) - 1:
        count_list.append([S[i], count])
        break
    if S[i] != S[i+1]:
        count_list.append([S[i], count])
        count = 0

if len(count_list) == 1:
    print(len(S) * K // 2)
else:
    count = 0
    for _, c in count_list:
        count += c//2
    if count_list[0][0] != count_list[-1][0]:
        print(count * K)
    else:
        head_count = count_list[0][1]
        tail_count = count_list[-1][1]
        mid_change = count - head_count // 2 - tail_count // 2
        con_change = (head_count + tail_count) // 2
        print(head_count // 2 + tail_count // 2 + mid_change * K + con_change * (K-1)) S = input() S input() input K = int(input()) K int(input()) int input() input count_list = [] count_list [] count = 0 count 0 for i in range(len(S)):
    count += 1
    if i == len(S) - 1:
        count_list.append([S[i], count])
        break
    if S[i] != S[i+1]:
        count_list.append([S[i], count])
        count = 0 i range(len(S)) range len(S) len S count += 1 count 1 if i == len(S) - 1:
        count_list.append([S[i], count])
        break
     i == len(S) - 1 i len(S) - 1 len(S) len S 1 count_list.append([S[i], count]) count_list.append count_list append [S[i], count] S[i] S i count break if S[i] != S[i+1]:
        count_list.append([S[i], count])
        count = 0 S[i] != S[i+1] S[i] S i S[i+1] S i+1 i 1 count_list.append([S[i], count]) count_list.append count_list append [S[i], count] S[i] S i count count = 0 count 0 if len(count_list) == 1:
    print(len(S) * K // 2)
else:
    count = 0
    for _, c in count_list:
        count += c//2
    if count_list[0][0] != count_list[-1][0]:
        print(count * K)
    else:
        head_count = count_list[0][1]
        tail_count = count_list[-1][1]
        mid_change = count - head_count // 2 - tail_count // 2
        con_change = (head_count + tail_count) // 2
        print(head_count // 2 + tail_count // 2 + mid_change * K + con_change * (K-1)) len(count_list) == 1 len(count_list) len count_list 1 print(len(S) * K // 2) print len(S) * K // 2 len(S) * K len(S) len S K 2 count = 0 count 0 for _, c in count_list:
        count += c//2
     _ c count_list count += c//2 count c//2 c 2 if count_list[0][0] != count_list[-1][0]:
        print(count * K)
    else:
        head_count = count_list[0][1]
        tail_count = count_list[-1][1]
        mid_change = count - head_count // 2 - tail_count // 2
        con_change = (head_count + tail_count) // 2
        print(head_count // 2 + tail_count // 2 + mid_change * K + con_change * (K-1)) count_list[0][0] != count_list[-1][0] count_list[0][0] [0] count_list 0 0 count_list[-1][0] [-1] count_list -1 0 print(count * K) print count * K count K head_count = count_list[0][1] head_count count_list[0][1] [0] count_list 0 1 tail_count = count_list[-1][1] tail_count count_list[-1][1] [-1] count_list -1 1 mid_change = count - head_count // 2 - tail_count // 2 mid_change count - head_count // 2 - tail_count // 2 count - head_count // 2 count head_count // 2 head_count 2 tail_count // 2 tail_count 2 con_change = (head_count + tail_count) // 2 con_change (head_count + tail_count) // 2 head_count + tail_count head_count tail_count 2 print(head_count // 2 + tail_count // 2 + mid_change * K + con_change * (K-1)) print head_count // 2 + tail_count // 2 + mid_change * K + con_change * (K-1) head_count // 2 + tail_count // 2 + mid_change * K head_count // 2 + tail_count // 2 head_count // 2 head_count 2 tail_count // 2 tail_count 2 mid_change * K mid_change K con_change * (K-1) con_change K-1 K 1 count = 0 0 count con_change = (head_count + tail_count) // 2 (head_count + tail_count) // 2 con_change count_list = [] [] count_list S = input() input() S mid_change = count - head_count // 2 - tail_count // 2 count - head_count // 2 - tail_count // 2 mid_change count = 0 0 count tail_count = count_list[-1][1] count_list[-1][1] tail_count count += 1 1 count count += c//2 c//2 count K = int(input()) int(input()) K count = 0 0 count head_count = count_list[0][1] count_list[0][1] head_count
S = input()
# A = [int(i) for i in input().split()]
K = int(input())

count_list = []
count = 0
for i in range(len(S)):
    count += 1
    if i == len(S) - 1:
        count_list.append([S[i], count])
        break
    if S[i] != S[i+1]:
        count_list.append([S[i], count])
        count = 0

if len(count_list) == 1:
    print(len(S) * K // 2)
else:
    count = 0
    for _, c in count_list:
        count += c//2
    if count_list[0][0] != count_list[-1][0]:
        print(count * K)
    else:
        head_count = count_list[0][1]
        tail_count = count_list[-1][1]
        mid_change = count - head_count // 2 - tail_count // 2
        con_change = (head_count + tail_count) // 2
        print(head_count // 2 + tail_count // 2 + mid_change * K + con_change * (K-1))
