def f(s,n):
    res = 0
    flg = False
    for i in range(1,n):
        if flg:
            flg = False
            continue
        if S[i] == S[i-1]:
            flg = True
            res += 1
    return res
S = input()
K = int(input())
if len(set(list(S))) == 1:
    print(len(S)*K//2)
    exit()
ans = f(S,len(S))
S = S * 2
print(ans + (f(S,len(S)) - ans) * (K-1)) def f(s,n):
    res = 0
    flg = False
    for i in range(1,n):
        if flg:
            flg = False
            continue
        if S[i] == S[i-1]:
            flg = True
            res += 1
    return res f res = 0 res 0 flg = False flg False for i in range(1,n):
        if flg:
            flg = False
            continue
        if S[i] == S[i-1]:
            flg = True
            res += 1
     i range(1,n) range 1 n if flg:
            flg = False
            continue
         flg flg = False flg False continue if S[i] == S[i-1]:
            flg = True
            res += 1
     S[i] == S[i-1] S[i] S i S[i-1] S i-1 i 1 flg = True flg True res += 1 res 1 return res res s s n n S = input() S input() input K = int(input()) K int(input()) int input() input if len(set(list(S))) == 1:
    print(len(S)*K//2)
    exit() len(set(list(S))) == 1 len(set(list(S))) len set(list(S)) set list(S) list S 1 print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 exit() exit ans = f(S,len(S)) ans f(S,len(S)) f S len(S) len S S = S * 2 S S * 2 S 2 print(ans + (f(S,len(S)) - ans) * (K-1)) print ans + (f(S,len(S)) - ans) * (K-1) ans (f(S,len(S)) - ans) * (K-1) f(S,len(S)) - ans f(S,len(S)) f S len(S) len S ans K-1 K 1 S = input() input() S def f(s,n):
    res = 0
    flg = False
    for i in range(1,n):
        if flg:
            flg = False
            continue
        if S[i] == S[i-1]:
            flg = True
            res += 1
    return res def f(s,n):
    res = 0
    flg = False
    for i in range(1,n):
        if flg:
            flg = False
            continue
        if S[i] == S[i-1]:
            flg = True
            res += 1
    return res f ans = f(S,len(S)) f(S,len(S)) ans K = int(input()) int(input()) K S = S * 2 S * 2 S
def f(s,n):
    res = 0
    flg = False
    for i in range(1,n):
        if flg:
            flg = False
            continue
        if S[i] == S[i-1]:
            flg = True
            res += 1
    return res
S = input()
K = int(input())
if len(set(list(S))) == 1:
    print(len(S)*K//2)
    exit()
ans = f(S,len(S))
S = S * 2
print(ans + (f(S,len(S)) - ans) * (K-1))