s = list(input())
k = int(input())
n = len(s)

ans = 0

# すべて同じ文字の場合
if s == [s[0]] * n:
    print((n*k)//2)
    exit(0)

# 先頭と末尾が異なる場合
i = 1
while i < n:
    if s[i-1] == s[i]:
        t = 2
        i+=1
        while i < n and s[i-1] == s[i]:
            t+=1
            i+=1
        ans += (t//2)*k
    i+=1
if s[0] != s[-1]:
    print(ans)
    exit(0)
# 先頭と末尾が一致する場合
# まず不一致の場合と同様に数えて、左右端の連続長さを数える
# 連結したとき、左右の1ブロックのみはそのまま数えられる
# 残りのk-1ブロックは、左右がつながった形で数えられる
i = 1
left = 1
right = 1
for i in range(n):
    if s[i] == s[i+1]:
        left += 1
    else:
        break
for i in range(n-1, -1, -1):
    if s[i] == s[i-1]:
        right += 1
    else:
        break
if s[0] == s[-1]:
    ans = ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//2)
    print(ans) s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s ans = 0 ans 0 if s == [s[0]] * n:
    print((n*k)//2)
    exit(0)

# 先頭と末尾が異なる場合 s == [s[0]] * n s [s[0]] * n [s[0]] s[0] s 0 n print((n*k)//2) print (n*k)//2 n*k n k 2 exit(0) exit 0 i = 1 i 1 while i < n:
    if s[i-1] == s[i]:
        t = 2
        i+=1
        while i < n and s[i-1] == s[i]:
            t+=1
            i+=1
        ans += (t//2)*k
    i+=1 i < n i n if s[i-1] == s[i]:
        t = 2
        i+=1
        while i < n and s[i-1] == s[i]:
            t+=1
            i+=1
        ans += (t//2)*k
     s[i-1] == s[i] s[i-1] s i-1 i 1 s[i] s i t = 2 t 2 i+=1 i 1 while i < n and s[i-1] == s[i]:
            t+=1
            i+=1
         i < n and s[i-1] == s[i] i < n i n s[i-1] == s[i] s[i-1] s i-1 i 1 s[i] s i t+=1 t 1 i+=1 i 1 ans += (t//2)*k ans (t//2)*k t//2 t 2 k i+=1 i 1 if s[0] != s[-1]:
    print(ans)
    exit(0)
# 先頭と末尾が一致する場合
# まず不一致の場合と同様に数えて、左右端の連続長さを数える
# 連結したとき、左右の1ブロックのみはそのまま数えられる
# 残りのk-1ブロックは、左右がつながった形で数えられる s[0] != s[-1] s[0] s 0 s[-1] s -1 print(ans) print ans exit(0) exit 0 i = 1 i 1 left = 1 left 1 right = 1 right 1 for i in range(n):
    if s[i] == s[i+1]:
        left += 1
    else:
        break i range(n) range n if s[i] == s[i+1]:
        left += 1
    else:
        break s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 left += 1 left 1 break for i in range(n-1, -1, -1):
    if s[i] == s[i-1]:
        right += 1
    else:
        break i range(n-1, -1, -1) range n-1 n 1 -1 -1 if s[i] == s[i-1]:
        right += 1
    else:
        break s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 right += 1 right 1 break if s[0] == s[-1]:
    ans = ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//2)
    print(ans) s[0] == s[-1] s[0] s 0 s[-1] s -1 ans = ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//2) ans ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//2) ans - (k-1) * (left//2 + right//2) ans (k-1) * (left//2 + right//2) k-1 k 1 left//2 + right//2 left//2 left 2 right//2 right 2 (k-1) * ((left+right)//2) k-1 k 1 (left+right)//2 left+right left right 2 print(ans) print ans n = len(s) len(s) n i+=1 1 i i+=1 1 i i+=1 1 i ans = 0 0 ans right += 1 1 right ans = ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//2) ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//2) ans ans += (t//2)*k (t//2)*k ans i = 1 1 i t = 2 2 t s = list(input()) list(input()) s left += 1 1 left i = 1 1 i k = int(input()) int(input()) k left = 1 1 left right = 1 1 right t+=1 1 t
s = list(input())
k = int(input())
n = len(s)

ans = 0

# すべて同じ文字の場合
if s == [s[0]] * n:
    print((n*k)//2)
    exit(0)

# 先頭と末尾が異なる場合
i = 1
while i < n:
    if s[i-1] == s[i]:
        t = 2
        i+=1
        while i < n and s[i-1] == s[i]:
            t+=1
            i+=1
        ans += (t//2)*k
    i+=1
if s[0] != s[-1]:
    print(ans)
    exit(0)
# 先頭と末尾が一致する場合
# まず不一致の場合と同様に数えて、左右端の連続長さを数える
# 連結したとき、左右の1ブロックのみはそのまま数えられる
# 残りのk-1ブロックは、左右がつながった形で数えられる
i = 1
left = 1
right = 1
for i in range(n):
    if s[i] == s[i+1]:
        left += 1
    else:
        break
for i in range(n-1, -1, -1):
    if s[i] == s[i-1]:
        right += 1
    else:
        break
if s[0] == s[-1]:
    ans = ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//2)
    print(ans)
