S = list(input())
K = int(input())
S.extend(S)

prev = ''
cnt = 0
for s in S:
    if s == prev:
        cnt += 1
        prev = ''
    else:
        prev = s

b = 0
if K % 2 == 0:
    b += 1
if K > 2 and S[0] == S[-1]:
    mae = 1
    while mae < len(S) and S[mae] == S[0]:
        mae += 1
    if mae % 2 == 1 and mae != len(S):
        usiro = 1
        i = len(S) - 2
        while S[i] == S[-1]:
            usiro += 1
            i -= 1
        if usiro % 2 == 1:
            b = K // 2

if K % 2 == 0:
    res = cnt * (K // 2) + (b - 1)
else:
    res = cnt * (K // 2) + cnt // 2 + b
print(res) S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input S.extend(S) S.extend S extend S prev = '' prev '' cnt = 0 cnt 0 for s in S:
    if s == prev:
        cnt += 1
        prev = ''
    else:
        prev = s s S if s == prev:
        cnt += 1
        prev = ''
    else:
        prev = s s == prev s prev cnt += 1 cnt 1 prev = '' prev '' prev = s prev s b = 0 b 0 if K % 2 == 0:
    b += 1 K % 2 == 0 K % 2 K 2 0 b += 1 b 1 if K > 2 and S[0] == S[-1]:
    mae = 1
    while mae < len(S) and S[mae] == S[0]:
        mae += 1
    if mae % 2 == 1 and mae != len(S):
        usiro = 1
        i = len(S) - 2
        while S[i] == S[-1]:
            usiro += 1
            i -= 1
        if usiro % 2 == 1:
            b = K // 2 K > 2 and S[0] == S[-1] K > 2 K 2 S[0] == S[-1] S[0] S 0 S[-1] S -1 mae = 1 mae 1 while mae < len(S) and S[mae] == S[0]:
        mae += 1
     mae < len(S) and S[mae] == S[0] mae < len(S) mae len(S) len S S[mae] == S[0] S[mae] S mae S[0] S 0 mae += 1 mae 1 if mae % 2 == 1 and mae != len(S):
        usiro = 1
        i = len(S) - 2
        while S[i] == S[-1]:
            usiro += 1
            i -= 1
        if usiro % 2 == 1:
            b = K // 2 mae % 2 == 1 and mae != len(S) mae % 2 == 1 mae % 2 mae 2 1 mae != len(S) mae len(S) len S usiro = 1 usiro 1 i = len(S) - 2 i len(S) - 2 len(S) len S 2 while S[i] == S[-1]:
            usiro += 1
            i -= 1
         S[i] == S[-1] S[i] S i S[-1] S -1 usiro += 1 usiro 1 i -= 1 i 1 if usiro % 2 == 1:
            b = K // 2 usiro % 2 == 1 usiro % 2 usiro 2 1 b = K // 2 b K // 2 K 2 if K % 2 == 0:
    res = cnt * (K // 2) + (b - 1)
else:
    res = cnt * (K // 2) + cnt // 2 + b K % 2 == 0 K % 2 K 2 0 res = cnt * (K // 2) + (b - 1) res cnt * (K // 2) + (b - 1) cnt * (K // 2) cnt K // 2 K 2 b - 1 b 1 res = cnt * (K // 2) + cnt // 2 + b res cnt * (K // 2) + cnt // 2 + b cnt * (K // 2) + cnt // 2 cnt * (K // 2) cnt K // 2 K 2 cnt // 2 cnt 2 b print(res) print res cnt = 0 0 cnt b = 0 0 b res = cnt * (K // 2) + cnt // 2 + b cnt * (K // 2) + cnt // 2 + b res K = int(input()) int(input()) K cnt += 1 1 cnt i -= 1 1 i usiro += 1 1 usiro usiro = 1 1 usiro i = len(S) - 2 len(S) - 2 i mae += 1 1 mae b += 1 1 b S = list(input()) list(input()) S b = K // 2 K // 2 b prev = '' '' prev prev = '' '' prev res = cnt * (K // 2) + (b - 1) cnt * (K // 2) + (b - 1) res mae = 1 1 mae prev = s s prev
S = list(input())
K = int(input())
S.extend(S)

prev = ''
cnt = 0
for s in S:
    if s == prev:
        cnt += 1
        prev = ''
    else:
        prev = s

b = 0
if K % 2 == 0:
    b += 1
if K > 2 and S[0] == S[-1]:
    mae = 1
    while mae < len(S) and S[mae] == S[0]:
        mae += 1
    if mae % 2 == 1 and mae != len(S):
        usiro = 1
        i = len(S) - 2
        while S[i] == S[-1]:
            usiro += 1
            i -= 1
        if usiro % 2 == 1:
            b = K // 2

if K % 2 == 0:
    res = cnt * (K // 2) + (b - 1)
else:
    res = cnt * (K // 2) + cnt // 2 + b
print(res)
