import sys
input = sys.stdin.readline

SS = input().rstrip()
ls = len(SS)
Ki = int(input())
lis= []

for K in range(1,4):
    S = list(SS*K)
    N = len(S)
    cnt = 0
    for i in range(1,N-1):
        if S[i-1] == S[i] == S[i+1]:
            S[i] = '5'
            cnt += 1
    for i in range(N-1):
        if S[i]==S[i+1]:
            S[i] = '5'
            cnt += 1
    lis.append(cnt)    
a = lis[0]
d1 = lis[1]-lis[0]
d2 = lis[2]-lis[1]

print(a + d1 *(Ki//2) + d2*((Ki-1)//2)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline SS = input().rstrip() SS input().rstrip() ().rstrip () input rstrip ls = len(SS) ls len(SS) len SS Ki = int(input()) Ki int(input()) int input() input lis= [] lis [] for K in range(1,4):
    S = list(SS*K)
    N = len(S)
    cnt = 0
    for i in range(1,N-1):
        if S[i-1] == S[i] == S[i+1]:
            S[i] = '5'
            cnt += 1
    for i in range(N-1):
        if S[i]==S[i+1]:
            S[i] = '5'
            cnt += 1
    lis.append(cnt)     K range(1,4) range 1 4 S = list(SS*K) S list(SS*K) list SS*K SS K N = len(S) N len(S) len S cnt = 0 cnt 0 for i in range(1,N-1):
        if S[i-1] == S[i] == S[i+1]:
            S[i] = '5'
            cnt += 1
     i range(1,N-1) range 1 N-1 N 1 if S[i-1] == S[i] == S[i+1]:
            S[i] = '5'
            cnt += 1
     S[i-1] == S[i] == S[i+1] S[i-1] == S[i] S[i-1] S i-1 i 1 S[i] S i S[i+1] S i+1 i 1 S[i] = '5' S[i] S i '5' cnt += 1 cnt 1 for i in range(N-1):
        if S[i]==S[i+1]:
            S[i] = '5'
            cnt += 1
     i range(N-1) range N-1 N 1 if S[i]==S[i+1]:
            S[i] = '5'
            cnt += 1
     S[i]==S[i+1] S[i] S i S[i+1] S i+1 i 1 S[i] = '5' S[i] S i '5' cnt += 1 cnt 1 lis.append(cnt) lis.append lis append cnt a = lis[0] a lis[0] lis 0 d1 = lis[1]-lis[0] d1 lis[1]-lis[0] lis[1] lis 1 lis[0] lis 0 d2 = lis[2]-lis[1] d2 lis[2]-lis[1] lis[2] lis 2 lis[1] lis 1 print(a + d1 *(Ki//2) + d2*((Ki-1)//2)) print a + d1 *(Ki//2) + d2*((Ki-1)//2) a + d1 *(Ki//2) a d1 *(Ki//2) d1 Ki//2 Ki 2 d2*((Ki-1)//2) d2 (Ki-1)//2 Ki-1 Ki 1 2 input = sys.stdin.readline sys.stdin.readline input a = lis[0] lis[0] a Ki = int(input()) int(input()) Ki lis= [] [] lis cnt = 0 0 cnt SS = input().rstrip() input().rstrip() SS d1 = lis[1]-lis[0] lis[1]-lis[0] d1 cnt += 1 1 cnt cnt += 1 1 cnt d2 = lis[2]-lis[1] lis[2]-lis[1] d2 ls = len(SS) len(SS) ls S = list(SS*K) list(SS*K) S N = len(S) len(S) N
import sys
input = sys.stdin.readline

SS = input().rstrip()
ls = len(SS)
Ki = int(input())
lis= []

for K in range(1,4):
    S = list(SS*K)
    N = len(S)
    cnt = 0
    for i in range(1,N-1):
        if S[i-1] == S[i] == S[i+1]:
            S[i] = '5'
            cnt += 1
    for i in range(N-1):
        if S[i]==S[i+1]:
            S[i] = '5'
            cnt += 1
    lis.append(cnt)    
a = lis[0]
d1 = lis[1]-lis[0]
d2 = lis[2]-lis[1]

print(a + d1 *(Ki//2) + d2*((Ki-1)//2))
