S = input()
K = int(input())

def f(S):
    cnt = 0
    t = 0
    for i in range(1, len(S)):
        if S[i-1] == S[i]:
            t += 1
        else:
            t = 0
        if t % 2 == 1:
            cnt += 1
    return cnt

if len(set(S)) == 1:
    l = len(S) * K
    print(l // 2)
elif K < 10:
    print(f(S * K))
else:
    v2 = f(S * 2)
    v3 = f(S * 3)
    print(v3 + (v3-v2) * (K - 3)) S = input() S input() input K = int(input()) K int(input()) int input() input def f(S):
    cnt = 0
    t = 0
    for i in range(1, len(S)):
        if S[i-1] == S[i]:
            t += 1
        else:
            t = 0
        if t % 2 == 1:
            cnt += 1
    return cnt f cnt = 0 cnt 0 t = 0 t 0 for i in range(1, len(S)):
        if S[i-1] == S[i]:
            t += 1
        else:
            t = 0
        if t % 2 == 1:
            cnt += 1
     i range(1, len(S)) range 1 len(S) len S if S[i-1] == S[i]:
            t += 1
        else:
            t = 0
         S[i-1] == S[i] S[i-1] S i-1 i 1 S[i] S i t += 1 t 1 t = 0 t 0 if t % 2 == 1:
            cnt += 1
     t % 2 == 1 t % 2 t 2 1 cnt += 1 cnt 1 return cnt cnt S S if len(set(S)) == 1:
    l = len(S) * K
    print(l // 2)
elif K < 10:
    print(f(S * K))
else:
    v2 = f(S * 2)
    v3 = f(S * 3)
    print(v3 + (v3-v2) * (K - 3)) len(set(S)) == 1 len(set(S)) len set(S) set S 1 l = len(S) * K l len(S) * K len(S) len S K print(l // 2) print l // 2 l 2 elif K < 10:
    print(f(S * K)) K < 10 K 10 print(f(S * K)) print f(S * K) f S * K S K v2 = f(S * 2) v2 f(S * 2) f S * 2 S 2 v3 = f(S * 3) v3 f(S * 3) f S * 3 S 3 print(v3 + (v3-v2) * (K - 3)) print v3 + (v3-v2) * (K - 3) v3 (v3-v2) * (K - 3) v3-v2 v3 v2 K - 3 K 3 l = len(S) * K len(S) * K l S = input() input() S def f(S):
    cnt = 0
    t = 0
    for i in range(1, len(S)):
        if S[i-1] == S[i]:
            t += 1
        else:
            t = 0
        if t % 2 == 1:
            cnt += 1
    return cnt def f(S):
    cnt = 0
    t = 0
    for i in range(1, len(S)):
        if S[i-1] == S[i]:
            t += 1
        else:
            t = 0
        if t % 2 == 1:
            cnt += 1
    return cnt f v3 = f(S * 3) f(S * 3) v3 K = int(input()) int(input()) K v2 = f(S * 2) f(S * 2) v2
S = input()
K = int(input())

def f(S):
    cnt = 0
    t = 0
    for i in range(1, len(S)):
        if S[i-1] == S[i]:
            t += 1
        else:
            t = 0
        if t % 2 == 1:
            cnt += 1
    return cnt

if len(set(S)) == 1:
    l = len(S) * K
    print(l // 2)
elif K < 10:
    print(f(S * K))
else:
    v2 = f(S * 2)
    v3 = f(S * 3)
    print(v3 + (v3-v2) * (K - 3))
