from math import floor

S = input()
K = int(input())

# Sが1文字しかない
if len(set(S)) == 1:
    print(floor(len(S) * K / 2))
    exit()

ans = 0
if S[0] != S[-1]:
    # Sの中での答え × K回数
    c = "0"
    count = 0
    for i in range(len(S)):
        if c == S[i]:
            count += 1
        else:
            # floor(連続した文字の回数 / 2)だけ書き換える
            ans += count // 2
            c = S[i] # 情報更新
            count = 1
    ans += count // 2 # 最後の分
    ans = ans * K
else:
    # 先頭と末端もある
    c1 = 1
    for i in range(1, len(S)):
        if S[i] == S[0]:
            c1 += 1
        else:
            break
    c2 = 1
    for j in reversed(range(len(S) - 1)):
        if S[j] == S[-1]:
            c2 += 1
        else:
            break
    ans = (c1 // 2) + (c2 // 2) + ((c1 + c2) // 2 * (K - 1))
    c3 = 0
    c = "0"
    for k in range(i, j + 1):
        if S[k] == c:
            c3 += 1
        else:
            ans += c3 // 2 * K
            c = S[k]
            c3 = 1
    ans += c3 // 2 * K
print(ans) from math import floor S = input() S input() input K = int(input()) K int(input()) int input() input if len(set(S)) == 1:
    print(floor(len(S) * K / 2))
    exit() len(set(S)) == 1 len(set(S)) len set(S) set S 1 print(floor(len(S) * K / 2)) print floor(len(S) * K / 2) floor len(S) * K / 2 len(S) * K len(S) len S K 2 exit() exit ans = 0 ans 0 if S[0] != S[-1]:
    # Sの中での答え × K回数
    c = "0"
    count = 0
    for i in range(len(S)):
        if c == S[i]:
            count += 1
        else:
            # floor(連続した文字の回数 / 2)だけ書き換える
            ans += count // 2
            c = S[i] # 情報更新
            count = 1
    ans += count // 2 # 最後の分
    ans = ans * K
else:
    # 先頭と末端もある
    c1 = 1
    for i in range(1, len(S)):
        if S[i] == S[0]:
            c1 += 1
        else:
            break
    c2 = 1
    for j in reversed(range(len(S) - 1)):
        if S[j] == S[-1]:
            c2 += 1
        else:
            break
    ans = (c1 // 2) + (c2 // 2) + ((c1 + c2) // 2 * (K - 1))
    c3 = 0
    c = "0"
    for k in range(i, j + 1):
        if S[k] == c:
            c3 += 1
        else:
            ans += c3 // 2 * K
            c = S[k]
            c3 = 1
    ans += c3 // 2 * K S[0] != S[-1] S[0] S 0 S[-1] S -1 c = "0" c "0" count = 0 count 0 for i in range(len(S)):
        if c == S[i]:
            count += 1
        else:
            # floor(連続した文字の回数 / 2)だけ書き換える
            ans += count // 2
            c = S[i] # 情報更新
            count = 1
     i range(len(S)) range len(S) len S if c == S[i]:
            count += 1
        else:
            # floor(連続した文字の回数 / 2)だけ書き換える
            ans += count // 2
            c = S[i] # 情報更新
            count = 1
     c == S[i] c S[i] S i count += 1 count 1 ans += count // 2 ans count // 2 count 2 c = S[i] c S[i] S i count = 1 count 1 ans += count // 2 ans count // 2 count 2 ans = ans * K ans ans * K ans K c1 = 1 c1 1 for i in range(1, len(S)):
        if S[i] == S[0]:
            c1 += 1
        else:
            break
     i range(1, len(S)) range 1 len(S) len S if S[i] == S[0]:
            c1 += 1
        else:
            break
     S[i] == S[0] S[i] S i S[0] S 0 c1 += 1 c1 1 break c2 = 1 c2 1 for j in reversed(range(len(S) - 1)):
        if S[j] == S[-1]:
            c2 += 1
        else:
            break
     j reversed(range(len(S) - 1)) reversed range(len(S) - 1) range len(S) - 1 len(S) len S 1 if S[j] == S[-1]:
            c2 += 1
        else:
            break
     S[j] == S[-1] S[j] S j S[-1] S -1 c2 += 1 c2 1 break ans = (c1 // 2) + (c2 // 2) + ((c1 + c2) // 2 * (K - 1)) ans (c1 // 2) + (c2 // 2) + ((c1 + c2) // 2 * (K - 1)) (c1 // 2) + (c2 // 2) c1 // 2 c1 2 c2 // 2 c2 2 (c1 + c2) // 2 * (K - 1) (c1 + c2) // 2 c1 + c2 c1 c2 2 K - 1 K 1 c3 = 0 c3 0 c = "0" c "0" for k in range(i, j + 1):
        if S[k] == c:
            c3 += 1
        else:
            ans += c3 // 2 * K
            c = S[k]
            c3 = 1
     k range(i, j + 1) range i j + 1 j 1 if S[k] == c:
            c3 += 1
        else:
            ans += c3 // 2 * K
            c = S[k]
            c3 = 1
     S[k] == c S[k] S k c c3 += 1 c3 1 ans += c3 // 2 * K ans c3 // 2 * K c3 // 2 c3 2 K c = S[k] c S[k] S k c3 = 1 c3 1 ans += c3 // 2 * K ans c3 // 2 * K c3 // 2 c3 2 K print(ans) print ans ans += count // 2 count // 2 ans K = int(input()) int(input()) K c = "0" "0" c count += 1 1 count S = input() input() S c1 = 1 1 c1 ans += c3 // 2 * K c3 // 2 * K ans count = 0 0 count ans = ans * K ans * K ans ans = 0 0 ans ans = (c1 // 2) + (c2 // 2) + ((c1 + c2) // 2 * (K - 1)) (c1 // 2) + (c2 // 2) + ((c1 + c2) // 2 * (K - 1)) ans c3 = 1 1 c3 c = S[i] S[i] c c3 += 1 1 c3 count = 1 1 count c1 += 1 1 c1 c2 += 1 1 c2 c3 = 0 0 c3 c = "0" "0" c ans += c3 // 2 * K c3 // 2 * K ans ans += count // 2 count // 2 ans c2 = 1 1 c2 c = S[k] S[k] c
from math import floor

S = input()
K = int(input())

# Sが1文字しかない
if len(set(S)) == 1:
    print(floor(len(S) * K / 2))
    exit()

ans = 0
if S[0] != S[-1]:
    # Sの中での答え × K回数
    c = "0"
    count = 0
    for i in range(len(S)):
        if c == S[i]:
            count += 1
        else:
            # floor(連続した文字の回数 / 2)だけ書き換える
            ans += count // 2
            c = S[i] # 情報更新
            count = 1
    ans += count // 2 # 最後の分
    ans = ans * K
else:
    # 先頭と末端もある
    c1 = 1
    for i in range(1, len(S)):
        if S[i] == S[0]:
            c1 += 1
        else:
            break
    c2 = 1
    for j in reversed(range(len(S) - 1)):
        if S[j] == S[-1]:
            c2 += 1
        else:
            break
    ans = (c1 // 2) + (c2 // 2) + ((c1 + c2) // 2 * (K - 1))
    c3 = 0
    c = "0"
    for k in range(i, j + 1):
        if S[k] == c:
            c3 += 1
        else:
            ans += c3 // 2 * K
            c = S[k]
            c3 = 1
    ans += c3 // 2 * K
print(ans)