import math
import sys

s = list(sys.stdin.readline().rstrip())
k = int(sys.stdin.readline().rstrip())

if len(set(s)) == 1:
    print(len(s) * k // 2)
    sys.exit()
ss = s * 2
tmp, tmp2 = 0, 0
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tmp += 1
        s[i + 1] = '-1'
for i in range(len(s) * 2 - 1):
    if ss[i] == ss[i + 1]:
        tmp2 += 1
        ss[i + 1] = '-1'
print(tmp + (tmp2 - tmp) * (k - 1)) import math math import sys sys s = list(sys.stdin.readline().rstrip()) s list(sys.stdin.readline().rstrip()) list sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip k = int(sys.stdin.readline().rstrip()) k int(sys.stdin.readline().rstrip()) int sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip if len(set(s)) == 1:
    print(len(s) * k // 2)
    sys.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 sys.exit() sys.exit sys exit ss = s * 2 ss s * 2 s 2 tmp, tmp2 = 0, 0 tmp 0 tmp2 0 for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tmp += 1
        s[i + 1] = '-1' i range(len(s) - 1) range len(s) - 1 len(s) len s 1 if s[i] == s[i + 1]:
        tmp += 1
        s[i + 1] = '-1' s[i] == s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 tmp += 1 tmp 1 s[i + 1] = '-1' s[i + 1] s i + 1 i 1 '-1' for i in range(len(s) * 2 - 1):
    if ss[i] == ss[i + 1]:
        tmp2 += 1
        ss[i + 1] = '-1' i range(len(s) * 2 - 1) range len(s) * 2 - 1 len(s) * 2 len(s) len s 2 1 if ss[i] == ss[i + 1]:
        tmp2 += 1
        ss[i + 1] = '-1' ss[i] == ss[i + 1] ss[i] ss i ss[i + 1] ss i + 1 i 1 tmp2 += 1 tmp2 1 ss[i + 1] = '-1' ss[i + 1] ss i + 1 i 1 '-1' print(tmp + (tmp2 - tmp) * (k - 1)) print tmp + (tmp2 - tmp) * (k - 1) tmp (tmp2 - tmp) * (k - 1) tmp2 - tmp tmp2 tmp k - 1 k 1 tmp2 = 0, 0 0 tmp2 tmp += 1 1 tmp k = int(sys.stdin.readline().rstrip()) int(sys.stdin.readline().rstrip()) k tmp2 += 1 1 tmp2 tmp, tmp2 = 0, 0 0 tmp s = list(sys.stdin.readline().rstrip()) list(sys.stdin.readline().rstrip()) s ss = s * 2 s * 2 ss
import math
import sys

s = list(sys.stdin.readline().rstrip())
k = int(sys.stdin.readline().rstrip())

if len(set(s)) == 1:
    print(len(s) * k // 2)
    sys.exit()
ss = s * 2
tmp, tmp2 = 0, 0
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tmp += 1
        s[i + 1] = '-1'
for i in range(len(s) * 2 - 1):
    if ss[i] == ss[i + 1]:
        tmp2 += 1
        ss[i + 1] = '-1'
print(tmp + (tmp2 - tmp) * (k - 1))