s = input()
k = int(input())
import collections
co = collections.Counter(list(s))
n = len(s)
if len(co.values())==1:
    print(n*k//2)
    exit()
prev = ""
cnt = 0
for i in range(n):
    if s[i] == prev:
        cnt+=1
        prev=""
    else:
        prev=s[i]
bf = 0
af = 0
if s[0] == s[-1]:
    for i in range(n):
        if s[i] ==s[0]:
            bf+=1
        else:break
    for i in range(n):
        if s[-i-1] ==s[-1]:
            af+=1
        else:break
cnt = cnt - (bf//2 + af//2)
print(cnt*k + (bf+af)//2 *(k-1) +bf//2 + af//2) s = input() s input() input k = int(input()) k int(input()) int input() input import collections collections co = collections.Counter(list(s)) co collections.Counter(list(s)) collections.Counter collections Counter list(s) list s n = len(s) n len(s) len s if len(co.values())==1:
    print(n*k//2)
    exit() len(co.values())==1 len(co.values()) len co.values() co.values co values 1 print(n*k//2) print n*k//2 n*k n k 2 exit() exit prev = "" prev "" cnt = 0 cnt 0 for i in range(n):
    if s[i] == prev:
        cnt+=1
        prev=""
    else:
        prev=s[i] i range(n) range n if s[i] == prev:
        cnt+=1
        prev=""
    else:
        prev=s[i] s[i] == prev s[i] s i prev cnt+=1 cnt 1 prev="" prev "" prev=s[i] prev s[i] s i bf = 0 bf 0 af = 0 af 0 if s[0] == s[-1]:
    for i in range(n):
        if s[i] ==s[0]:
            bf+=1
        else:break
    for i in range(n):
        if s[-i-1] ==s[-1]:
            af+=1
        else:break s[0] == s[-1] s[0] s 0 s[-1] s -1 for i in range(n):
        if s[i] ==s[0]:
            bf+=1
        else:break
     i range(n) range n if s[i] ==s[0]:
            bf+=1
        else:break
     s[i] ==s[0] s[i] s i s[0] s 0 bf+=1 bf 1 for i in range(n):
        if s[-i-1] ==s[-1]:
            af+=1
        else:break i range(n) range n if s[-i-1] ==s[-1]:
            af+=1
        else:break s[-i-1] ==s[-1] s[-i-1] s -i-1 -i i 1 s[-1] s -1 af+=1 af 1 cnt = cnt - (bf//2 + af//2) cnt cnt - (bf//2 + af//2) cnt bf//2 + af//2 bf//2 bf 2 af//2 af 2 print(cnt*k + (bf+af)//2 *(k-1) +bf//2 + af//2) print cnt*k + (bf+af)//2 *(k-1) +bf//2 + af//2 cnt*k + (bf+af)//2 *(k-1) +bf//2 cnt*k + (bf+af)//2 *(k-1) cnt*k cnt k (bf+af)//2 *(k-1) (bf+af)//2 bf+af bf af 2 k-1 k 1 bf//2 bf 2 af//2 af 2 prev = "" "" prev s = input() input() s k = int(input()) int(input()) k bf = 0 0 bf cnt = cnt - (bf//2 + af//2) cnt - (bf//2 + af//2) cnt cnt+=1 1 cnt prev=s[i] s[i] prev prev="" "" prev cnt = 0 0 cnt bf+=1 1 bf n = len(s) len(s) n co = collections.Counter(list(s)) collections.Counter(list(s)) co af = 0 0 af af+=1 1 af
s = input()
k = int(input())
import collections
co = collections.Counter(list(s))
n = len(s)
if len(co.values())==1:
    print(n*k//2)
    exit()
prev = ""
cnt = 0
for i in range(n):
    if s[i] == prev:
        cnt+=1
        prev=""
    else:
        prev=s[i]
bf = 0
af = 0
if s[0] == s[-1]:
    for i in range(n):
        if s[i] ==s[0]:
            bf+=1
        else:break
    for i in range(n):
        if s[-i-1] ==s[-1]:
            af+=1
        else:break
cnt = cnt - (bf//2 + af//2)
print(cnt*k + (bf+af)//2 *(k-1) +bf//2 + af//2)
