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

N = len(S)

m= 1
for m in range(1, N):
    if S[m] != S[m-1]:break
    else: m += 1

def calc(s):
    ans = 0
    pre = s[0]
    for ss in s[1:]:
        if ss == pre:
            ans += 1
            pre = '0'
        else: pre = ss
    return ans

if m == N:
    print((N * K) // 2)
else:
    if K == 1:
        print(calc(S))
    elif K == 2:
        print(calc(S + S[0:m]) + calc(S[m:N]))
    else:
        print(calc(S + S[0:m]) + calc(S[m:N]) + (K - 2) * calc(S[m:N] + S[0:m])) S = input() S input() input K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S m= 1 m 1 for m in range(1, N):
    if S[m] != S[m-1]:break
    else: m += 1 m range(1, N) range 1 N if S[m] != S[m-1]:break
    else: m += 1 S[m] != S[m-1] S[m] S m S[m-1] S m-1 m 1 def calc(s):
    ans = 0
    pre = s[0]
    for ss in s[1:]:
        if ss == pre:
            ans += 1
            pre = '0'
        else: pre = ss
    return ans calc ans = 0 ans 0 pre = s[0] pre s[0] s 0 for ss in s[1:]:
        if ss == pre:
            ans += 1
            pre = '0'
        else: pre = ss
     ss s[1:] s 1: 1 if ss == pre:
            ans += 1
            pre = '0'
        else: pre = ss
     ss == pre ss pre ans += 1 ans 1 pre = '0' pre '0' return ans ans s s if m == N:
    print((N * K) // 2)
else:
    if K == 1:
        print(calc(S))
    elif K == 2:
        print(calc(S + S[0:m]) + calc(S[m:N]))
    else:
        print(calc(S + S[0:m]) + calc(S[m:N]) + (K - 2) * calc(S[m:N] + S[0:m])) m == N m N print((N * K) // 2) print (N * K) // 2 N * K N K 2 if K == 1:
        print(calc(S))
    elif K == 2:
        print(calc(S + S[0:m]) + calc(S[m:N]))
    else:
        print(calc(S + S[0:m]) + calc(S[m:N]) + (K - 2) * calc(S[m:N] + S[0:m])) K == 1 K 1 print(calc(S)) print calc(S) calc S elif K == 2:
        print(calc(S + S[0:m]) + calc(S[m:N]))
     K == 2 K 2 print(calc(S + S[0:m]) + calc(S[m:N])) print calc(S + S[0:m]) + calc(S[m:N]) calc(S + S[0:m]) calc S + S[0:m] S S[0:m] S 0:m 0 m calc(S[m:N]) calc S[m:N] S m:N m N print(calc(S + S[0:m]) + calc(S[m:N]) + (K - 2) * calc(S[m:N] + S[0:m])) print calc(S + S[0:m]) + calc(S[m:N]) + (K - 2) * calc(S[m:N] + S[0:m]) calc(S + S[0:m]) + calc(S[m:N]) calc(S + S[0:m]) calc S + S[0:m] S S[0:m] S 0:m 0 m calc(S[m:N]) calc S[m:N] S m:N m N (K - 2) * calc(S[m:N] + S[0:m]) K - 2 K 2 calc(S[m:N] + S[0:m]) calc S[m:N] + S[0:m] S[m:N] S m:N m N S[0:m] S 0:m 0 m K = int(input()) int(input()) K S = input() input() S def calc(s):
    ans = 0
    pre = s[0]
    for ss in s[1:]:
        if ss == pre:
            ans += 1
            pre = '0'
        else: pre = ss
    return ans def calc(s):
    ans = 0
    pre = s[0]
    for ss in s[1:]:
        if ss == pre:
            ans += 1
            pre = '0'
        else: pre = ss
    return ans calc N = len(S) len(S) N m= 1 1 m
S = input()
K = int(input())

N = len(S)

m= 1
for m in range(1, N):
    if S[m] != S[m-1]:break
    else: m += 1

def calc(s):
    ans = 0
    pre = s[0]
    for ss in s[1:]:
        if ss == pre:
            ans += 1
            pre = '0'
        else: pre = ss
    return ans

if m == N:
    print((N * K) // 2)
else:
    if K == 1:
        print(calc(S))
    elif K == 2:
        print(calc(S + S[0:m]) + calc(S[m:N]))
    else:
        print(calc(S + S[0:m]) + calc(S[m:N]) + (K - 2) * calc(S[m:N] + S[0:m]))
