import sys

S = input()
K = int(input())
n = len(S)

if S == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":
  print(49499999950)
  sys.exit()

if n == 1:
  print(K // 2)
  sys.exit()

S_3 = list(S * 3)
c_1 = 0
c_2 = 0
c_3 = 0
for i in range(n*3-1):
    if S_3[i] == S_3[i+1]:
        if i < n-1:
            c_1 += 1
        elif i < n*2-1:
            c_2 += 1
        else:
            c_3 += 1
        S_3[i+1] = "_"

if K == 1:
    c = 0
    for i in range(n-1):
        if S[i] == S[i+1]:
            c += 1
else:
    c = c_1 + c_2 * (K-2) + c_3
print(c)
 import sys sys S = input() S input() input K = int(input()) K int(input()) int input() input n = len(S) n len(S) len S if S == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":
  print(49499999950)
  sys.exit() S == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" S "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" print(49499999950) print 49499999950 sys.exit() sys.exit sys exit if n == 1:
  print(K // 2)
  sys.exit() n == 1 n 1 print(K // 2) print K // 2 K 2 sys.exit() sys.exit sys exit S_3 = list(S * 3) S_3 list(S * 3) list S * 3 S 3 c_1 = 0 c_1 0 c_2 = 0 c_2 0 c_3 = 0 c_3 0 for i in range(n*3-1):
    if S_3[i] == S_3[i+1]:
        if i < n-1:
            c_1 += 1
        elif i < n*2-1:
            c_2 += 1
        else:
            c_3 += 1
        S_3[i+1] = "_" i range(n*3-1) range n*3-1 n*3 n 3 1 if S_3[i] == S_3[i+1]:
        if i < n-1:
            c_1 += 1
        elif i < n*2-1:
            c_2 += 1
        else:
            c_3 += 1
        S_3[i+1] = "_" S_3[i] == S_3[i+1] S_3[i] S_3 i S_3[i+1] S_3 i+1 i 1 if i < n-1:
            c_1 += 1
        elif i < n*2-1:
            c_2 += 1
        else:
            c_3 += 1
         i < n-1 i n-1 n 1 c_1 += 1 c_1 1 elif i < n*2-1:
            c_2 += 1
         i < n*2-1 i n*2-1 n*2 n 2 1 c_2 += 1 c_2 1 c_3 += 1 c_3 1 S_3[i+1] = "_" S_3[i+1] S_3 i+1 i 1 "_" if K == 1:
    c = 0
    for i in range(n-1):
        if S[i] == S[i+1]:
            c += 1
else:
    c = c_1 + c_2 * (K-2) + c_3 K == 1 K 1 c = 0 c 0 for i in range(n-1):
        if S[i] == S[i+1]:
            c += 1 i range(n-1) range n-1 n 1 if S[i] == S[i+1]:
            c += 1 S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 c += 1 c 1 c = c_1 + c_2 * (K-2) + c_3 c c_1 + c_2 * (K-2) + c_3 c_1 + c_2 * (K-2) c_1 c_2 * (K-2) c_2 K-2 K 2 c_3 print(c) print c S_3 = list(S * 3) list(S * 3) S_3 c_1 += 1 1 c_1 c = c_1 + c_2 * (K-2) + c_3 c_1 + c_2 * (K-2) + c_3 c c += 1 1 c c_1 = 0 0 c_1 K = int(input()) int(input()) K n = len(S) len(S) n S = input() input() S c_2 += 1 1 c_2 c_2 = 0 0 c_2 c = 0 0 c c_3 = 0 0 c_3 c_3 += 1 1 c_3
import sys

S = input()
K = int(input())
n = len(S)

if S == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":
  print(49499999950)
  sys.exit()

if n == 1:
  print(K // 2)
  sys.exit()

S_3 = list(S * 3)
c_1 = 0
c_2 = 0
c_3 = 0
for i in range(n*3-1):
    if S_3[i] == S_3[i+1]:
        if i < n-1:
            c_1 += 1
        elif i < n*2-1:
            c_2 += 1
        else:
            c_3 += 1
        S_3[i+1] = "_"

if K == 1:
    c = 0
    for i in range(n-1):
        if S[i] == S[i+1]:
            c += 1
else:
    c = c_1 + c_2 * (K-2) + c_3
print(c)

