s = list(str(input()))
k = int(input())

n = len(s)

cur = s[0]
L = []
cnt = 0
for i in range(n):
    if cur == s[i]:
        cnt += 1
    else:
        L.append(cnt)
        cur = s[i]
        cnt = 1
else:
    L.append(cnt)
#print(L)

if s[0] != s[-1]:
    C = 0
    for i in range(len(L)):
        if L[i] >= 2:
            C += L[i]//2
    ans = C*k
else:
    if len(L) >= 2:
        C = 0
        for i in range(1, len(L)-1):
            if L[i] >= 2:
                C += L[i]//2
        ans = C*k
        ans += L[0]//2+L[-1]//2+((L[0]+L[-1])//2)*(k-1)
    else:
        ans = (L[0]*k)//2
print(ans) s = list(str(input())) s list(str(input())) list str(input()) str input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s cur = s[0] cur s[0] s 0 L = [] L [] cnt = 0 cnt 0 for i in range(n):
    if cur == s[i]:
        cnt += 1
    else:
        L.append(cnt)
        cur = s[i]
        cnt = 1
else:
    L.append(cnt)
#print(L) i range(n) range n if cur == s[i]:
        cnt += 1
    else:
        L.append(cnt)
        cur = s[i]
        cnt = 1 cur == s[i] cur s[i] s i cnt += 1 cnt 1 L.append(cnt) L.append L append cnt cur = s[i] cur s[i] s i cnt = 1 cnt 1 L.append(cnt) L.append L append cnt if s[0] != s[-1]:
    C = 0
    for i in range(len(L)):
        if L[i] >= 2:
            C += L[i]//2
    ans = C*k
else:
    if len(L) >= 2:
        C = 0
        for i in range(1, len(L)-1):
            if L[i] >= 2:
                C += L[i]//2
        ans = C*k
        ans += L[0]//2+L[-1]//2+((L[0]+L[-1])//2)*(k-1)
    else:
        ans = (L[0]*k)//2 s[0] != s[-1] s[0] s 0 s[-1] s -1 C = 0 C 0 for i in range(len(L)):
        if L[i] >= 2:
            C += L[i]//2
     i range(len(L)) range len(L) len L if L[i] >= 2:
            C += L[i]//2
     L[i] >= 2 L[i] L i 2 C += L[i]//2 C L[i]//2 L[i] L i 2 ans = C*k ans C*k C k if len(L) >= 2:
        C = 0
        for i in range(1, len(L)-1):
            if L[i] >= 2:
                C += L[i]//2
        ans = C*k
        ans += L[0]//2+L[-1]//2+((L[0]+L[-1])//2)*(k-1)
    else:
        ans = (L[0]*k)//2 len(L) >= 2 len(L) len L 2 C = 0 C 0 for i in range(1, len(L)-1):
            if L[i] >= 2:
                C += L[i]//2
         i range(1, len(L)-1) range 1 len(L)-1 len(L) len L 1 if L[i] >= 2:
                C += L[i]//2
         L[i] >= 2 L[i] L i 2 C += L[i]//2 C L[i]//2 L[i] L i 2 ans = C*k ans C*k C k ans += L[0]//2+L[-1]//2+((L[0]+L[-1])//2)*(k-1) ans L[0]//2+L[-1]//2+((L[0]+L[-1])//2)*(k-1) L[0]//2+L[-1]//2 L[0]//2 L[0] L 0 2 L[-1]//2 L[-1] L -1 2 ((L[0]+L[-1])//2)*(k-1) (L[0]+L[-1])//2 L[0]+L[-1] L[0] L 0 L[-1] L -1 2 k-1 k 1 ans = (L[0]*k)//2 ans (L[0]*k)//2 L[0]*k L[0] L 0 k 2 print(ans) print ans k = int(input()) int(input()) k C = 0 0 C s = list(str(input())) list(str(input())) s cur = s[0] s[0] cur cur = s[i] s[i] cur C += L[i]//2 L[i]//2 C ans = C*k C*k ans C = 0 0 C cnt = 1 1 cnt ans += L[0]//2+L[-1]//2+((L[0]+L[-1])//2)*(k-1) L[0]//2+L[-1]//2+((L[0]+L[-1])//2)*(k-1) ans cnt = 0 0 cnt cnt += 1 1 cnt L = [] [] L ans = C*k C*k ans ans = (L[0]*k)//2 (L[0]*k)//2 ans C += L[i]//2 L[i]//2 C n = len(s) len(s) n
s = list(str(input()))
k = int(input())

n = len(s)

cur = s[0]
L = []
cnt = 0
for i in range(n):
    if cur == s[i]:
        cnt += 1
    else:
        L.append(cnt)
        cur = s[i]
        cnt = 1
else:
    L.append(cnt)
#print(L)

if s[0] != s[-1]:
    C = 0
    for i in range(len(L)):
        if L[i] >= 2:
            C += L[i]//2
    ans = C*k
else:
    if len(L) >= 2:
        C = 0
        for i in range(1, len(L)-1):
            if L[i] >= 2:
                C += L[i]//2
        ans = C*k
        ans += L[0]//2+L[-1]//2+((L[0]+L[-1])//2)*(k-1)
    else:
        ans = (L[0]*k)//2
print(ans)
