from itertools import groupby

def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
    
print(solve()) from itertools import groupby def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
     solve S = input() S input() input K = int(input()) K int(input()) int input() input len(tuple(s)) for _, s in groupby(S) for _, s in groupby(S) _ s groupby(S) groupby S for _, s in groupby(S) len(tuple(s)) len tuple(s) tuple s a = [len(tuple(s)) for _, s in groupby(S)] a [len(tuple(s)) for _, s in groupby(S)] if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
     S[0] == S[-1] and K > 1 S[0] == S[-1] S[0] S 0 S[-1] S -1 K > 1 K 1 if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
     len(a) == 1 len(a) len a 1 return a[0] * K // 2 a[0] * K // 2 a[0] * K a[0] a 0 K 2 ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1) ans a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1) a[0] // 2 + a[-1] // 2 a[0] // 2 a[0] a 0 2 a[-1] // 2 a[-1] a -1 2 (a[0]+a[-1]) // 2 * (K-1) (a[0]+a[-1]) // 2 a[0]+a[-1] a[0] a 0 a[-1] a -1 2 K-1 K 1 ans += sum(n // 2 for n in a[1:-1]) * K ans sum(n // 2 for n in a[1:-1]) * K sum(n // 2 for n in a[1:-1]) sum n // 2 n 2 K return ans ans return sum(n // 2 for n in a) * K sum(n // 2 for n in a) * K sum(n // 2 for n in a) sum n // 2 n 2 K print(solve()) print solve() solve def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
     def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
     solve
from itertools import groupby

def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
    
print(solve())