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

#ランレングス圧縮
rle = []
pre = 'A'
chain = 1
for c in S:
    if c == pre:
        chain += 1
    else:
        if pre != 'A':
            rle.append([pre,chain])
        
        pre = c
        chain = 1
rle.append([pre,chain])

ans = 0

#1種類の文字列の場合
if len(rle) == 1:
    ans = (rle[0][1] * K) // 2

#2種類以上の文字列の場合
else:
    #先頭と末尾が同じ文字
    if rle[0][0] == rle[-1][0]:
        #先頭、末尾、つなぎ目の対応
        ans += rle[0][1]//2
        ans += rle[-1][1]//2
        rle[0][1] += rle[-1][1]
        rle[-1][1] = 0
        ans += rle[0][1]//2 * (K-1)

        #Sの中での連続文字の対応
        mid_chains = 0
        for i in range(1,len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * K

    #先頭と末尾が異なる文字
    else:
        mid_chains = 0
        for i in range(len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * K


#print(rle)
print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input rle = [] rle [] pre = 'A' pre 'A' chain = 1 chain 1 for c in S:
    if c == pre:
        chain += 1
    else:
        if pre != 'A':
            rle.append([pre,chain])
        
        pre = c
        chain = 1 c S if c == pre:
        chain += 1
    else:
        if pre != 'A':
            rle.append([pre,chain])
        
        pre = c
        chain = 1 c == pre c pre chain += 1 chain 1 if pre != 'A':
            rle.append([pre,chain])
        
         pre != 'A' pre 'A' rle.append([pre,chain]) rle.append rle append [pre,chain] pre chain pre = c pre c chain = 1 chain 1 rle.append([pre,chain]) rle.append rle append [pre,chain] pre chain ans = 0 ans 0 if len(rle) == 1:
    ans = (rle[0][1] * K) // 2

#2種類以上の文字列の場合
else:
    #先頭と末尾が同じ文字
    if rle[0][0] == rle[-1][0]:
        #先頭、末尾、つなぎ目の対応
        ans += rle[0][1]//2
        ans += rle[-1][1]//2
        rle[0][1] += rle[-1][1]
        rle[-1][1] = 0
        ans += rle[0][1]//2 * (K-1)

        #Sの中での連続文字の対応
        mid_chains = 0
        for i in range(1,len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * K

    #先頭と末尾が異なる文字
    else:
        mid_chains = 0
        for i in range(len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * K


#print(rle) len(rle) == 1 len(rle) len rle 1 ans = (rle[0][1] * K) // 2 ans (rle[0][1] * K) // 2 rle[0][1] * K rle[0][1] [0] rle 0 1 K 2 if rle[0][0] == rle[-1][0]:
        #先頭、末尾、つなぎ目の対応
        ans += rle[0][1]//2
        ans += rle[-1][1]//2
        rle[0][1] += rle[-1][1]
        rle[-1][1] = 0
        ans += rle[0][1]//2 * (K-1)

        #Sの中での連続文字の対応
        mid_chains = 0
        for i in range(1,len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * K

    #先頭と末尾が異なる文字
    else:
        mid_chains = 0
        for i in range(len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * K


#print(rle) rle[0][0] == rle[-1][0] rle[0][0] [0] rle 0 0 rle[-1][0] [-1] rle -1 0 ans += rle[0][1]//2 ans rle[0][1]//2 rle[0][1] [0] rle 0 1 2 ans += rle[-1][1]//2 ans rle[-1][1]//2 rle[-1][1] [-1] rle -1 1 2 rle[0][1] += rle[-1][1] rle[0][1] [0] rle 0 1 rle[-1][1] [-1] rle -1 1 rle[-1][1] = 0 rle[-1][1] [-1] rle -1 1 0 ans += rle[0][1]//2 * (K-1) ans rle[0][1]//2 * (K-1) rle[0][1]//2 rle[0][1] [0] rle 0 1 2 K-1 K 1 mid_chains = 0 mid_chains 0 for i in range(1,len(rle)):
            mid_chains += rle[i][1]//2
         i range(1,len(rle)) range 1 len(rle) len rle mid_chains += rle[i][1]//2 mid_chains rle[i][1]//2 rle[i][1] [i] rle i 1 2 ans += mid_chains * K ans mid_chains * K mid_chains K mid_chains = 0 mid_chains 0 for i in range(len(rle)):
            mid_chains += rle[i][1]//2
         i range(len(rle)) range len(rle) len rle mid_chains += rle[i][1]//2 mid_chains rle[i][1]//2 rle[i][1] [i] rle i 1 2 ans += mid_chains * K ans mid_chains * K mid_chains K print(ans) print ans mid_chains = 0 0 mid_chains ans += rle[0][1]//2 rle[0][1]//2 ans ans = 0 0 ans pre = c c pre chain = 1 1 chain ans += rle[0][1]//2 * (K-1) rle[0][1]//2 * (K-1) ans K = int(input()) int(input()) K pre = 'A' 'A' pre mid_chains += rle[i][1]//2 rle[i][1]//2 mid_chains rle = [] [] rle chain += 1 1 chain chain = 1 1 chain ans += rle[-1][1]//2 rle[-1][1]//2 ans mid_chains += rle[i][1]//2 rle[i][1]//2 mid_chains mid_chains = 0 0 mid_chains ans += mid_chains * K mid_chains * K ans ans = (rle[0][1] * K) // 2 (rle[0][1] * K) // 2 ans ans += mid_chains * K mid_chains * K ans S = input() input() S
S = input()
K = int(input())

#ランレングス圧縮
rle = []
pre = 'A'
chain = 1
for c in S:
    if c == pre:
        chain += 1
    else:
        if pre != 'A':
            rle.append([pre,chain])
        
        pre = c
        chain = 1
rle.append([pre,chain])

ans = 0

#1種類の文字列の場合
if len(rle) == 1:
    ans = (rle[0][1] * K) // 2

#2種類以上の文字列の場合
else:
    #先頭と末尾が同じ文字
    if rle[0][0] == rle[-1][0]:
        #先頭、末尾、つなぎ目の対応
        ans += rle[0][1]//2
        ans += rle[-1][1]//2
        rle[0][1] += rle[-1][1]
        rle[-1][1] = 0
        ans += rle[0][1]//2 * (K-1)

        #Sの中での連続文字の対応
        mid_chains = 0
        for i in range(1,len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * K

    #先頭と末尾が異なる文字
    else:
        mid_chains = 0
        for i in range(len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * K


#print(rle)
print(ans)