import copy
s = list(input())
n = len(s)
s2 = copy.deepcopy(s)
la = s[-1]
for i in range(n):
    if s[i] == la:
        s2.append(la)
    else:
        break

n2 = len(s2)
k = int(input())
if n2 == 2*n:
    print(n*k//2)
    exit()
count = 0
for i in range(n2-n+1,n2):
    if s2[i] == s2[i-1]:
        s2[i] = "1"
        count += 1
ans = k*count

c = 0

for i in range(n-1,-1,-1):
    if la == s[i]:
        c += 1
    else:
        break

if n2 > n and (n2-n)%2 and c > 1 and c%2:
    ans -= 1
print(ans) import copy copy s = list(input()) s list(input()) list input() input n = len(s) n len(s) len s s2 = copy.deepcopy(s) s2 copy.deepcopy(s) copy.deepcopy copy deepcopy s la = s[-1] la s[-1] s -1 for i in range(n):
    if s[i] == la:
        s2.append(la)
    else:
        break i range(n) range n if s[i] == la:
        s2.append(la)
    else:
        break s[i] == la s[i] s i la s2.append(la) s2.append s2 append la break n2 = len(s2) n2 len(s2) len s2 k = int(input()) k int(input()) int input() input if n2 == 2*n:
    print(n*k//2)
    exit() n2 == 2*n n2 2*n 2 n print(n*k//2) print n*k//2 n*k n k 2 exit() exit count = 0 count 0 for i in range(n2-n+1,n2):
    if s2[i] == s2[i-1]:
        s2[i] = "1"
        count += 1 i range(n2-n+1,n2) range n2-n+1 n2-n n2 n 1 n2 if s2[i] == s2[i-1]:
        s2[i] = "1"
        count += 1 s2[i] == s2[i-1] s2[i] s2 i s2[i-1] s2 i-1 i 1 s2[i] = "1" s2[i] s2 i "1" count += 1 count 1 ans = k*count ans k*count k count c = 0 c 0 for i in range(n-1,-1,-1):
    if la == s[i]:
        c += 1
    else:
        break i range(n-1,-1,-1) range n-1 n 1 -1 -1 if la == s[i]:
        c += 1
    else:
        break la == s[i] la s[i] s i c += 1 c 1 break if n2 > n and (n2-n)%2 and c > 1 and c%2:
    ans -= 1 n2 > n and (n2-n)%2 and c > 1 and c%2 n2 > n and (n2-n)%2 and c > 1 n2 > n and (n2-n)%2 n2 > n n2 n (n2-n)%2 n2-n n2 n 2 c > 1 c 1 c%2 c 2 ans -= 1 ans 1 print(ans) print ans k = int(input()) int(input()) k c += 1 1 c count += 1 1 count ans -= 1 1 ans s2 = copy.deepcopy(s) copy.deepcopy(s) s2 count = 0 0 count la = s[-1] s[-1] la n2 = len(s2) len(s2) n2 ans = k*count k*count ans n = len(s) len(s) n c = 0 0 c s = list(input()) list(input()) s
import copy
s = list(input())
n = len(s)
s2 = copy.deepcopy(s)
la = s[-1]
for i in range(n):
    if s[i] == la:
        s2.append(la)
    else:
        break

n2 = len(s2)
k = int(input())
if n2 == 2*n:
    print(n*k//2)
    exit()
count = 0
for i in range(n2-n+1,n2):
    if s2[i] == s2[i-1]:
        s2[i] = "1"
        count += 1
ans = k*count

c = 0

for i in range(n-1,-1,-1):
    if la == s[i]:
        c += 1
    else:
        break

if n2 > n and (n2-n)%2 and c > 1 and c%2:
    ans -= 1
print(ans)