import math

s = input()
k = int(input())
cnt = 0
memo = 0
flg = True
if len(s) == 1:
    cnt = math.floor(k / 2)
elif len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    for i in range(1, len(s)):
        if s[0] == s[i] and flg:
            memo += 1
        else:
            flg = False
        if s[i] == s[i - 1]:
            s = s[:i] + '#' + s[i + 1:]
            cnt += 1
    cnt *= k
    if s[0] == s[-1] and memo % 2 == 0:
        cnt += (k - 1)
print(cnt) import math math s = input() s input() input k = int(input()) k int(input()) int input() input cnt = 0 cnt 0 memo = 0 memo 0 flg = True flg True if len(s) == 1:
    cnt = math.floor(k / 2)
elif len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    for i in range(1, len(s)):
        if s[0] == s[i] and flg:
            memo += 1
        else:
            flg = False
        if s[i] == s[i - 1]:
            s = s[:i] + '#' + s[i + 1:]
            cnt += 1
    cnt *= k
    if s[0] == s[-1] and memo % 2 == 0:
        cnt += (k - 1) len(s) == 1 len(s) len s 1 cnt = math.floor(k / 2) cnt math.floor(k / 2) math.floor math floor k / 2 k 2 elif len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2) len(set(s)) == 1 len(set(s)) len set(s) set s 1 cnt = math.floor(len(s) * k / 2) cnt math.floor(len(s) * k / 2) math.floor math floor len(s) * k / 2 len(s) * k len(s) len s k 2 for i in range(1, len(s)):
        if s[0] == s[i] and flg:
            memo += 1
        else:
            flg = False
        if s[i] == s[i - 1]:
            s = s[:i] + '#' + s[i + 1:]
            cnt += 1
     i range(1, len(s)) range 1 len(s) len s if s[0] == s[i] and flg:
            memo += 1
        else:
            flg = False
         s[0] == s[i] and flg s[0] == s[i] s[0] s 0 s[i] s i flg memo += 1 memo 1 flg = False flg False if s[i] == s[i - 1]:
            s = s[:i] + '#' + s[i + 1:]
            cnt += 1
     s[i] == s[i - 1] s[i] s i s[i - 1] s i - 1 i 1 s = s[:i] + '#' + s[i + 1:] s s[:i] + '#' + s[i + 1:] s[:i] + '#' s[:i] s :i i '#' s[i + 1:] s i + 1: i + 1 i 1 cnt += 1 cnt 1 cnt *= k cnt k if s[0] == s[-1] and memo % 2 == 0:
        cnt += (k - 1) s[0] == s[-1] and memo % 2 == 0 s[0] == s[-1] s[0] s 0 s[-1] s -1 memo % 2 == 0 memo % 2 memo 2 0 cnt += (k - 1) cnt k - 1 k 1 print(cnt) print cnt s = s[:i] + '#' + s[i + 1:] s[:i] + '#' + s[i + 1:] s cnt = math.floor(k / 2) math.floor(k / 2) cnt cnt = math.floor(len(s) * k / 2) math.floor(len(s) * k / 2) cnt k = int(input()) int(input()) k cnt += 1 1 cnt flg = True True flg flg = False False flg s = input() input() s cnt = 0 0 cnt memo += 1 1 memo cnt *= k k cnt cnt += (k - 1) k - 1 cnt memo = 0 0 memo
import math

s = input()
k = int(input())
cnt = 0
memo = 0
flg = True
if len(s) == 1:
    cnt = math.floor(k / 2)
elif len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    for i in range(1, len(s)):
        if s[0] == s[i] and flg:
            memo += 1
        else:
            flg = False
        if s[i] == s[i - 1]:
            s = s[:i] + '#' + s[i + 1:]
            cnt += 1
    cnt *= k
    if s[0] == s[-1] and memo % 2 == 0:
        cnt += (k - 1)
print(cnt)
