s = list(input())
k = int(input())
ans = 0
count = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        ans += count//2
        count = 1
ans += count//2
if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()
if s[0] != s[-1]:
    ans *= k
else:
    left = 0
    right = 0
    index = 0
    while index < len(s) and s[0] == s[index]:
        left += 1
        index += 1
    index = len(s)-1
    while index >= 0 and s[-1] == s[index]:
        right += 1
        index -= 1
    ans *= k
    ans -= ((right//2) + (left//2) - (right + left)//2) * (k-1)
print(ans) s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input ans = 0 ans 0 count = 1 count 1 for i in range(len(s)-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        ans += count//2
        count = 1 i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i] == s[i+1]:
        count += 1
    else:
        ans += count//2
        count = 1 s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 count += 1 count 1 ans += count//2 ans count//2 count 2 count = 1 count 1 ans += count//2 ans count//2 count 2 if len(set(s)) == 1:
    print(len(s)*k//2)
    exit() len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(len(s)*k//2) print len(s)*k//2 len(s)*k len(s) len s k 2 exit() exit if s[0] != s[-1]:
    ans *= k
else:
    left = 0
    right = 0
    index = 0
    while index < len(s) and s[0] == s[index]:
        left += 1
        index += 1
    index = len(s)-1
    while index >= 0 and s[-1] == s[index]:
        right += 1
        index -= 1
    ans *= k
    ans -= ((right//2) + (left//2) - (right + left)//2) * (k-1) s[0] != s[-1] s[0] s 0 s[-1] s -1 ans *= k ans k left = 0 left 0 right = 0 right 0 index = 0 index 0 while index < len(s) and s[0] == s[index]:
        left += 1
        index += 1
     index < len(s) and s[0] == s[index] index < len(s) index len(s) len s s[0] == s[index] s[0] s 0 s[index] s index left += 1 left 1 index += 1 index 1 index = len(s)-1 index len(s)-1 len(s) len s 1 while index >= 0 and s[-1] == s[index]:
        right += 1
        index -= 1
     index >= 0 and s[-1] == s[index] index >= 0 index 0 s[-1] == s[index] s[-1] s -1 s[index] s index right += 1 right 1 index -= 1 index 1 ans *= k ans k ans -= ((right//2) + (left//2) - (right + left)//2) * (k-1) ans ((right//2) + (left//2) - (right + left)//2) * (k-1) (right//2) + (left//2) - (right + left)//2 (right//2) + (left//2) right//2 right 2 left//2 left 2 (right + left)//2 right + left right left 2 k-1 k 1 print(ans) print ans ans = 0 0 ans ans -= ((right//2) + (left//2) - (right + left)//2) * (k-1) ((right//2) + (left//2) - (right + left)//2) * (k-1) ans count = 1 1 count count = 1 1 count right += 1 1 right s = list(input()) list(input()) s index -= 1 1 index index += 1 1 index ans += count//2 count//2 ans k = int(input()) int(input()) k left = 0 0 left right = 0 0 right ans *= k k ans index = len(s)-1 len(s)-1 index ans *= k k ans index = 0 0 index ans += count//2 count//2 ans left += 1 1 left count += 1 1 count
s = list(input())
k = int(input())
ans = 0
count = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        ans += count//2
        count = 1
ans += count//2
if len(set(s)) == 1:
    print(len(s)*k//2)
    exit()
if s[0] != s[-1]:
    ans *= k
else:
    left = 0
    right = 0
    index = 0
    while index < len(s) and s[0] == s[index]:
        left += 1
        index += 1
    index = len(s)-1
    while index >= 0 and s[-1] == s[index]:
        right += 1
        index -= 1
    ans *= k
    ans -= ((right//2) + (left//2) - (right + left)//2) * (k-1)
print(ans)