s = input()
k = int(input())
n = len(s)
l = [1]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
temp = 0
for i in range(n-1):
    if s[i+1] == s[i]:
        l[chk] += 1
    else:
        chk += 1

if s[0] == s[n-1]:
        temp = 1

memo = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 1 and memo == 0 and temp == 1:
        memo += 1
        edge = i
    ans += k*(l[i]//2)

if temp == 1 and edge != 0: 
    if (l[0] + l[edge]) % 2 == 0 and l[0] % 2 == 1:
        ans += k-1
elif temp == 1:
    if l[0] % 2 == 1:
        ans += k//2
if n == 1:
    ans = k//2

print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s l = [1]*n l [1]*n [1] 1 n '''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
''' chk = 0 chk 0 temp = 0 temp 0 for i in range(n-1):
    if s[i+1] == s[i]:
        l[chk] += 1
    else:
        chk += 1 i range(n-1) range n-1 n 1 if s[i+1] == s[i]:
        l[chk] += 1
    else:
        chk += 1 s[i+1] == s[i] s[i+1] s i+1 i 1 s[i] s i l[chk] += 1 l[chk] l chk 1 chk += 1 chk 1 if s[0] == s[n-1]:
        temp = 1 s[0] == s[n-1] s[0] s 0 s[n-1] s n-1 n 1 temp = 1 temp 1 memo = 0 memo 0 edge = 0 edge 0 ans = 0 ans 0 for i in range(n-1,-1,-1):
    if l[i] != 1 and memo == 0 and temp == 1:
        memo += 1
        edge = i
    ans += k*(l[i]//2) i range(n-1,-1,-1) range n-1 n 1 -1 -1 if l[i] != 1 and memo == 0 and temp == 1:
        memo += 1
        edge = i
     l[i] != 1 and memo == 0 and temp == 1 l[i] != 1 and memo == 0 l[i] != 1 l[i] l i 1 memo == 0 memo 0 temp == 1 temp 1 memo += 1 memo 1 edge = i edge i ans += k*(l[i]//2) ans k*(l[i]//2) k l[i]//2 l[i] l i 2 if temp == 1 and edge != 0: 
    if (l[0] + l[edge]) % 2 == 0 and l[0] % 2 == 1:
        ans += k-1
elif temp == 1:
    if l[0] % 2 == 1:
        ans += k//2 temp == 1 and edge != 0 temp == 1 temp 1 edge != 0 edge 0 if (l[0] + l[edge]) % 2 == 0 and l[0] % 2 == 1:
        ans += k-1 (l[0] + l[edge]) % 2 == 0 and l[0] % 2 == 1 (l[0] + l[edge]) % 2 == 0 (l[0] + l[edge]) % 2 l[0] + l[edge] l[0] l 0 l[edge] l edge 2 0 l[0] % 2 == 1 l[0] % 2 l[0] l 0 2 1 ans += k-1 ans k-1 k 1 elif temp == 1:
    if l[0] % 2 == 1:
        ans += k//2 temp == 1 temp 1 if l[0] % 2 == 1:
        ans += k//2 l[0] % 2 == 1 l[0] % 2 l[0] l 0 2 1 ans += k//2 ans k//2 k 2 if n == 1:
    ans = k//2 n == 1 n 1 ans = k//2 ans k//2 k 2 print(ans) print ans memo = 0 0 memo memo += 1 1 memo n = len(s) len(s) n ans += k*(l[i]//2) k*(l[i]//2) ans edge = i i edge edge = 0 0 edge chk = 0 0 chk temp = 1 1 temp k = int(input()) int(input()) k ans = 0 0 ans ans += k//2 k//2 ans l = [1]*n [1]*n l ans = k//2 k//2 ans ans += k-1 k-1 ans s = input() input() s chk += 1 1 chk temp = 0 0 temp
s = input()
k = int(input())
n = len(s)
l = [1]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
temp = 0
for i in range(n-1):
    if s[i+1] == s[i]:
        l[chk] += 1
    else:
        chk += 1

if s[0] == s[n-1]:
        temp = 1

memo = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 1 and memo == 0 and temp == 1:
        memo += 1
        edge = i
    ans += k*(l[i]//2)

if temp == 1 and edge != 0: 
    if (l[0] + l[edge]) % 2 == 0 and l[0] % 2 == 1:
        ans += k-1
elif temp == 1:
    if l[0] % 2 == 1:
        ans += k//2
if n == 1:
    ans = k//2

print(ans)
