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

N = len(S)

if len(set(S)) == 1: #種類が１つ
    tmp = K * N // 2
    print (tmp)
    exit()

if S[0] != S[-1]:
    count = 0
    for i in range(N - 1):
        if S[i] == S[i + 1]:
            S[i + 1] = '*'
            count += 1
    print (count * K)
else:
    i = 1
    while i < N:
        if S[i - 1] != S[i]:
            break
        i += 1
    
    j = 1
    while j < N:
        if S[N - j] != S[N - j - 1]:
            break
        j += 1
    
    ans = 0
    tmp = 1
    for k in range(i, N - j):
        if S[k] != S[k + 1]:
            ans += K * (tmp // 2)
            tmp = 1
        else:
            tmp += 1
    ans += K * (tmp // 2)
    ans += (K - 1) * ((i + j) // 2)
    ans += i // 2
    ans += j // 2
    print (ans) S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S if len(set(S)) == 1: #種類が１つ
    tmp = K * N // 2
    print (tmp)
    exit() len(set(S)) == 1 len(set(S)) len set(S) set S 1 tmp = K * N // 2 tmp K * N // 2 K * N K N 2 print (tmp) print tmp exit() exit if S[0] != S[-1]:
    count = 0
    for i in range(N - 1):
        if S[i] == S[i + 1]:
            S[i + 1] = '*'
            count += 1
    print (count * K)
else:
    i = 1
    while i < N:
        if S[i - 1] != S[i]:
            break
        i += 1
    
    j = 1
    while j < N:
        if S[N - j] != S[N - j - 1]:
            break
        j += 1
    
    ans = 0
    tmp = 1
    for k in range(i, N - j):
        if S[k] != S[k + 1]:
            ans += K * (tmp // 2)
            tmp = 1
        else:
            tmp += 1
    ans += K * (tmp // 2)
    ans += (K - 1) * ((i + j) // 2)
    ans += i // 2
    ans += j // 2
    print (ans) S[0] != S[-1] S[0] S 0 S[-1] S -1 count = 0 count 0 for i in range(N - 1):
        if S[i] == S[i + 1]:
            S[i + 1] = '*'
            count += 1
     i range(N - 1) range N - 1 N 1 if S[i] == S[i + 1]:
            S[i + 1] = '*'
            count += 1
     S[i] == S[i + 1] S[i] S i S[i + 1] S i + 1 i 1 S[i + 1] = '*' S[i + 1] S i + 1 i 1 '*' count += 1 count 1 print (count * K) print count * K count K i = 1 i 1 while i < N:
        if S[i - 1] != S[i]:
            break
        i += 1
    
     i < N i N if S[i - 1] != S[i]:
            break
         S[i - 1] != S[i] S[i - 1] S i - 1 i 1 S[i] S i break i += 1 i 1 j = 1 j 1 while j < N:
        if S[N - j] != S[N - j - 1]:
            break
        j += 1
    
     j < N j N if S[N - j] != S[N - j - 1]:
            break
         S[N - j] != S[N - j - 1] S[N - j] S N - j N j S[N - j - 1] S N - j - 1 N - j N j 1 break j += 1 j 1 ans = 0 ans 0 tmp = 1 tmp 1 for k in range(i, N - j):
        if S[k] != S[k + 1]:
            ans += K * (tmp // 2)
            tmp = 1
        else:
            tmp += 1
     k range(i, N - j) range i N - j N j if S[k] != S[k + 1]:
            ans += K * (tmp // 2)
            tmp = 1
        else:
            tmp += 1
     S[k] != S[k + 1] S[k] S k S[k + 1] S k + 1 k 1 ans += K * (tmp // 2) ans K * (tmp // 2) K tmp // 2 tmp 2 tmp = 1 tmp 1 tmp += 1 tmp 1 ans += K * (tmp // 2) ans K * (tmp // 2) K tmp // 2 tmp 2 ans += (K - 1) * ((i + j) // 2) ans (K - 1) * ((i + j) // 2) K - 1 K 1 (i + j) // 2 i + j i j 2 ans += i // 2 ans i // 2 i 2 ans += j // 2 ans j // 2 j 2 print (ans) print ans K = int(input()) int(input()) K ans += K * (tmp // 2) K * (tmp // 2) ans tmp = 1 1 tmp ans += j // 2 j // 2 ans count = 0 0 count ans += (K - 1) * ((i + j) // 2) (K - 1) * ((i + j) // 2) ans j = 1 1 j tmp += 1 1 tmp ans += K * (tmp // 2) K * (tmp // 2) ans i += 1 1 i tmp = K * N // 2 K * N // 2 tmp tmp = 1 1 tmp j += 1 1 j N = len(S) len(S) N count += 1 1 count i = 1 1 i S = list(input()) list(input()) S ans = 0 0 ans ans += i // 2 i // 2 ans
S = list(input())
K = int(input())

N = len(S)

if len(set(S)) == 1: #種類が１つ
    tmp = K * N // 2
    print (tmp)
    exit()

if S[0] != S[-1]:
    count = 0
    for i in range(N - 1):
        if S[i] == S[i + 1]:
            S[i + 1] = '*'
            count += 1
    print (count * K)
else:
    i = 1
    while i < N:
        if S[i - 1] != S[i]:
            break
        i += 1
    
    j = 1
    while j < N:
        if S[N - j] != S[N - j - 1]:
            break
        j += 1
    
    ans = 0
    tmp = 1
    for k in range(i, N - j):
        if S[k] != S[k + 1]:
            ans += K * (tmp // 2)
            tmp = 1
        else:
            tmp += 1
    ans += K * (tmp // 2)
    ans += (K - 1) * ((i + j) // 2)
    ans += i // 2
    ans += j // 2
    print (ans)