# A - Connection and Disconnection
S = input()
K = int(input())
head = 0
head_char = S[0]
head_rec = True
tmp = 0
char = ''
ans = 0
for i in range(len(S)):
    if head_rec==True:
        if S[i]==head_char:
            head += 1
        else:
            head_rec = False
    if S[i]!=char:
        char = S[i]
        ans += tmp//2
        tmp = 0
    tmp += 1
ans += tmp//2
ans *= K
if head==len(S):
    ans = (len(S)*K)//2
elif head_char==char and (tmp*head)%2!=0:
    ans += K-1
print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input head = 0 head 0 head_char = S[0] head_char S[0] S 0 head_rec = True head_rec True tmp = 0 tmp 0 char = '' char '' ans = 0 ans 0 for i in range(len(S)):
    if head_rec==True:
        if S[i]==head_char:
            head += 1
        else:
            head_rec = False
    if S[i]!=char:
        char = S[i]
        ans += tmp//2
        tmp = 0
    tmp += 1 i range(len(S)) range len(S) len S if head_rec==True:
        if S[i]==head_char:
            head += 1
        else:
            head_rec = False
     head_rec==True head_rec True if S[i]==head_char:
            head += 1
        else:
            head_rec = False
     S[i]==head_char S[i] S i head_char head += 1 head 1 head_rec = False head_rec False if S[i]!=char:
        char = S[i]
        ans += tmp//2
        tmp = 0
     S[i]!=char S[i] S i char char = S[i] char S[i] S i ans += tmp//2 ans tmp//2 tmp 2 tmp = 0 tmp 0 tmp += 1 tmp 1 ans += tmp//2 ans tmp//2 tmp 2 ans *= K ans K if head==len(S):
    ans = (len(S)*K)//2
elif head_char==char and (tmp*head)%2!=0:
    ans += K-1 head==len(S) head len(S) len S ans = (len(S)*K)//2 ans (len(S)*K)//2 len(S)*K len(S) len S K 2 elif head_char==char and (tmp*head)%2!=0:
    ans += K-1 head_char==char and (tmp*head)%2!=0 head_char==char head_char char (tmp*head)%2!=0 (tmp*head)%2 tmp*head tmp head 2 0 ans += K-1 ans K-1 K 1 print(ans) print ans tmp = 0 0 tmp ans += tmp//2 tmp//2 ans char = '' '' char ans = 0 0 ans tmp = 0 0 tmp head_rec = False False head_rec head = 0 0 head head_rec = True True head_rec S = input() input() S ans = (len(S)*K)//2 (len(S)*K)//2 ans ans += K-1 K-1 ans head_char = S[0] S[0] head_char tmp += 1 1 tmp ans *= K K ans ans += tmp//2 tmp//2 ans K = int(input()) int(input()) K head += 1 1 head char = S[i] S[i] char
# A - Connection and Disconnection
S = input()
K = int(input())
head = 0
head_char = S[0]
head_rec = True
tmp = 0
char = ''
ans = 0
for i in range(len(S)):
    if head_rec==True:
        if S[i]==head_char:
            head += 1
        else:
            head_rec = False
    if S[i]!=char:
        char = S[i]
        ans += tmp//2
        tmp = 0
    tmp += 1
ans += tmp//2
ans *= K
if head==len(S):
    ans = (len(S)*K)//2
elif head_char==char and (tmp*head)%2!=0:
    ans += K-1
print(ans)