import math
S = input()
K = int(input())
s = list(S)
c1 = 0
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        c1 += 1
        s[i+1] = 0
s = list(S*2)
c2 = 0
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        c2 += 1
        s[i+1] = 0
c = S[0]
for s in S:
    if s != c:
        print(c1+(c2-c1)*(K-1))
        exit()
print(math.floor(len(S)*K/2)) import math math S = input() S input() input K = int(input()) K int(input()) int input() input s = list(S) s list(S) list S c1 = 0 c1 0 for i in range(len(s)-1):
    if s[i+1] == s[i]:
        c1 += 1
        s[i+1] = 0 i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i+1] == s[i]:
        c1 += 1
        s[i+1] = 0 s[i+1] == s[i] s[i+1] s i+1 i 1 s[i] s i c1 += 1 c1 1 s[i+1] = 0 s[i+1] s i+1 i 1 0 s = list(S*2) s list(S*2) list S*2 S 2 c2 = 0 c2 0 for i in range(len(s)-1):
    if s[i+1] == s[i]:
        c2 += 1
        s[i+1] = 0 i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i+1] == s[i]:
        c2 += 1
        s[i+1] = 0 s[i+1] == s[i] s[i+1] s i+1 i 1 s[i] s i c2 += 1 c2 1 s[i+1] = 0 s[i+1] s i+1 i 1 0 c = S[0] c S[0] S 0 for s in S:
    if s != c:
        print(c1+(c2-c1)*(K-1))
        exit() s S if s != c:
        print(c1+(c2-c1)*(K-1))
        exit() s != c s c print(c1+(c2-c1)*(K-1)) print c1+(c2-c1)*(K-1) c1 (c2-c1)*(K-1) c2-c1 c2 c1 K-1 K 1 exit() exit print(math.floor(len(S)*K/2)) print math.floor(len(S)*K/2) math.floor math floor len(S)*K/2 len(S)*K len(S) len S K 2 K = int(input()) int(input()) K c = S[0] S[0] c c1 += 1 1 c1 s = list(S) list(S) s c2 = 0 0 c2 S = input() input() S c1 = 0 0 c1 s = list(S*2) list(S*2) s c2 += 1 1 c2
import math
S = input()
K = int(input())
s = list(S)
c1 = 0
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        c1 += 1
        s[i+1] = 0
s = list(S*2)
c2 = 0
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        c2 += 1
        s[i+1] = 0
c = S[0]
for s in S:
    if s != c:
        print(c1+(c2-c1)*(K-1))
        exit()
print(math.floor(len(S)*K/2))
