import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = list(readline().rstrip().decode())
k = int(read())
if len(set(s)) == 1:
    print(len(s) * k // 2)
    exit()
ans = 0
memo = 0
flag = True
for i, (bf, af) in enumerate(zip(s, s[1:])):
    if s[0] == af and flag:
        memo += 1
    else:
        flag = False
    if bf == af:
        ans += 1
        s[i + 1] = '?'
ans *= k
if s[-1] == s[0] and memo % 2 == 0:
    ans += k - 1
print(ans) import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 s = list(readline().rstrip().decode()) s list(readline().rstrip().decode()) list readline().rstrip().decode() ().rstrip().decode ().rstrip() ().rstrip () readline rstrip decode k = int(read()) k int(read()) int read() read if len(set(s)) == 1:
    print(len(s) * k // 2)
    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 exit() exit ans = 0 ans 0 memo = 0 memo 0 flag = True flag True for i, (bf, af) in enumerate(zip(s, s[1:])):
    if s[0] == af and flag:
        memo += 1
    else:
        flag = False
    if bf == af:
        ans += 1
        s[i + 1] = '?' i (bf, af) bf af enumerate(zip(s, s[1:])) enumerate zip(s, s[1:]) zip s s[1:] s 1: 1 if s[0] == af and flag:
        memo += 1
    else:
        flag = False
     s[0] == af and flag s[0] == af s[0] s 0 af flag memo += 1 memo 1 flag = False flag False if bf == af:
        ans += 1
        s[i + 1] = '?' bf == af bf af ans += 1 ans 1 s[i + 1] = '?' s[i + 1] s i + 1 i 1 '?' ans *= k ans k if s[-1] == s[0] and memo % 2 == 0:
    ans += k - 1 s[-1] == s[0] and memo % 2 == 0 s[-1] == s[0] s[-1] s -1 s[0] s 0 memo % 2 == 0 memo % 2 memo 2 0 ans += k - 1 ans k - 1 k 1 print(ans) print ans ans += k - 1 k - 1 ans read = sys.stdin.buffer.read sys.stdin.buffer.read read flag = True True flag memo += 1 1 memo readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines k = int(read()) int(read()) k ans += 1 1 ans flag = False False flag ans *= k k ans readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline ans = 0 0 ans memo = 0 0 memo s = list(readline().rstrip().decode()) list(readline().rstrip().decode()) s
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = list(readline().rstrip().decode())
k = int(read())
if len(set(s)) == 1:
    print(len(s) * k // 2)
    exit()
ans = 0
memo = 0
flag = True
for i, (bf, af) in enumerate(zip(s, s[1:])):
    if s[0] == af and flag:
        memo += 1
    else:
        flag = False
    if bf == af:
        ans += 1
        s[i + 1] = '?'
ans *= k
if s[-1] == s[0] and memo % 2 == 0:
    ans += k - 1
print(ans)
