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

flag = []

N = len(S)
for i in range(N):
    if i == N - 1:
        flag.append(0)
        #if S[i] == S[0]:
            #flag.append(1)
        #else:
            #flag.append(0)
    else:
        if S[i]==S[i+1]:
            flag.append(1)
        else:
            flag.append(0)

flag_2 = []
for i in range(N):
    flag_2.append(0)

for i in range(N):
    if flag[i] == 1:
        k = 0
        count = 0
        while((i == 0 or flag[i-1] == 0) and (i + k) < N and flag[i + k] == 1):
            k += 1
            count += 1
        flag_2[i] = count

#print("flag",flag)
#print("flag2", flag_2)

ans = 0
cara = set()
for i in range(N):
    cara.add(S[i])
if len(cara) == 1:
    ans = N*K//2
else:

    if(S[0] != S[N-1]):
        for i in range(N-1):
            ans += (flag_2[i] + 1)//2

        ans = ans * K

    else:
        last = 0
        for i in range(N):
            if(S[0] != S[N - 1 - i]):
                last = N - i
                break
        #print("last",last)
        temp = flag_2[0] + (N - last) + 1
        ans += temp//2 * (K - 1)
        for i in range(1, last):
            ans += (flag_2[i] + 1)//2 * K
        ans += (flag_2[0] + 1)//2
        ans += (flag_2[last] + 1)//2

print(ans)

 S = str(input()) S str(input()) str input() input K = int(input()) K int(input()) int input() input flag = [] flag [] N = len(S) N len(S) len S for i in range(N):
    if i == N - 1:
        flag.append(0)
        #if S[i] == S[0]:
            #flag.append(1)
        #else:
            #flag.append(0)
    else:
        if S[i]==S[i+1]:
            flag.append(1)
        else:
            flag.append(0) i range(N) range N if i == N - 1:
        flag.append(0)
        #if S[i] == S[0]:
            #flag.append(1)
        #else:
            #flag.append(0)
    else:
        if S[i]==S[i+1]:
            flag.append(1)
        else:
            flag.append(0) i == N - 1 i N - 1 N 1 flag.append(0) flag.append flag append 0 if S[i]==S[i+1]:
            flag.append(1)
        else:
            flag.append(0) S[i]==S[i+1] S[i] S i S[i+1] S i+1 i 1 flag.append(1) flag.append flag append 1 flag.append(0) flag.append flag append 0 flag_2 = [] flag_2 [] for i in range(N):
    flag_2.append(0) i range(N) range N flag_2.append(0) flag_2.append flag_2 append 0 for i in range(N):
    if flag[i] == 1:
        k = 0
        count = 0
        while((i == 0 or flag[i-1] == 0) and (i + k) < N and flag[i + k] == 1):
            k += 1
            count += 1
        flag_2[i] = count

#print("flag",flag)
#print("flag2", flag_2) i range(N) range N if flag[i] == 1:
        k = 0
        count = 0
        while((i == 0 or flag[i-1] == 0) and (i + k) < N and flag[i + k] == 1):
            k += 1
            count += 1
        flag_2[i] = count

#print("flag",flag)
#print("flag2", flag_2) flag[i] == 1 flag[i] flag i 1 k = 0 k 0 count = 0 count 0 while((i == 0 or flag[i-1] == 0) and (i + k) < N and flag[i + k] == 1):
            k += 1
            count += 1
         (i == 0 or flag[i-1] == 0) and (i + k) < N and flag[i + k] == 1 (i == 0 or flag[i-1] == 0) and (i + k) < N i == 0 or flag[i-1] == 0 i == 0 i 0 flag[i-1] == 0 flag[i-1] flag i-1 i 1 0 (i + k) < N i + k i k N flag[i + k] == 1 flag[i + k] flag i + k i k 1 k += 1 k 1 count += 1 count 1 flag_2[i] = count flag_2[i] flag_2 i count ans = 0 ans 0 cara = set() cara set() set for i in range(N):
    cara.add(S[i]) i range(N) range N cara.add(S[i]) cara.add cara add S[i] S i if len(cara) == 1:
    ans = N*K//2
else:

    if(S[0] != S[N-1]):
        for i in range(N-1):
            ans += (flag_2[i] + 1)//2

        ans = ans * K

    else:
        last = 0
        for i in range(N):
            if(S[0] != S[N - 1 - i]):
                last = N - i
                break
        #print("last",last)
        temp = flag_2[0] + (N - last) + 1
        ans += temp//2 * (K - 1)
        for i in range(1, last):
            ans += (flag_2[i] + 1)//2 * K
        ans += (flag_2[0] + 1)//2
        ans += (flag_2[last] + 1)//2 len(cara) == 1 len(cara) len cara 1 ans = N*K//2 ans N*K//2 N*K N K 2 if(S[0] != S[N-1]):
        for i in range(N-1):
            ans += (flag_2[i] + 1)//2

        ans = ans * K

    else:
        last = 0
        for i in range(N):
            if(S[0] != S[N - 1 - i]):
                last = N - i
                break
        #print("last",last)
        temp = flag_2[0] + (N - last) + 1
        ans += temp//2 * (K - 1)
        for i in range(1, last):
            ans += (flag_2[i] + 1)//2 * K
        ans += (flag_2[0] + 1)//2
        ans += (flag_2[last] + 1)//2 S[0] != S[N-1] S[0] S 0 S[N-1] S N-1 N 1 for i in range(N-1):
            ans += (flag_2[i] + 1)//2

         i range(N-1) range N-1 N 1 ans += (flag_2[i] + 1)//2 ans (flag_2[i] + 1)//2 flag_2[i] + 1 flag_2[i] flag_2 i 1 2 ans = ans * K ans ans * K ans K last = 0 last 0 for i in range(N):
            if(S[0] != S[N - 1 - i]):
                last = N - i
                break
        #print("last",last)
         i range(N) range N if(S[0] != S[N - 1 - i]):
                last = N - i
                break
        #print("last",last)
         S[0] != S[N - 1 - i] S[0] S 0 S[N - 1 - i] S N - 1 - i N - 1 N 1 i last = N - i last N - i N i break temp = flag_2[0] + (N - last) + 1 temp flag_2[0] + (N - last) + 1 flag_2[0] + (N - last) flag_2[0] flag_2 0 N - last N last 1 ans += temp//2 * (K - 1) ans temp//2 * (K - 1) temp//2 temp 2 K - 1 K 1 for i in range(1, last):
            ans += (flag_2[i] + 1)//2 * K
         i range(1, last) range 1 last ans += (flag_2[i] + 1)//2 * K ans (flag_2[i] + 1)//2 * K (flag_2[i] + 1)//2 flag_2[i] + 1 flag_2[i] flag_2 i 1 2 K ans += (flag_2[0] + 1)//2 ans (flag_2[0] + 1)//2 flag_2[0] + 1 flag_2[0] flag_2 0 1 2 ans += (flag_2[last] + 1)//2 ans (flag_2[last] + 1)//2 flag_2[last] + 1 flag_2[last] flag_2 last 1 2 print(ans) print ans flag = [] [] flag ans += (flag_2[i] + 1)//2 (flag_2[i] + 1)//2 ans ans = N*K//2 N*K//2 ans ans = ans * K ans * K ans ans += (flag_2[i] + 1)//2 * K (flag_2[i] + 1)//2 * K ans count = 0 0 count ans += temp//2 * (K - 1) temp//2 * (K - 1) ans last = 0 0 last count += 1 1 count k = 0 0 k ans = 0 0 ans K = int(input()) int(input()) K N = len(S) len(S) N temp = flag_2[0] + (N - last) + 1 flag_2[0] + (N - last) + 1 temp S = str(input()) str(input()) S cara = set() set() cara ans += (flag_2[0] + 1)//2 (flag_2[0] + 1)//2 ans flag_2 = [] [] flag_2 ans += (flag_2[last] + 1)//2 (flag_2[last] + 1)//2 ans k += 1 1 k last = N - i N - i last
S = str(input())
K = int(input())

flag = []

N = len(S)
for i in range(N):
    if i == N - 1:
        flag.append(0)
        #if S[i] == S[0]:
            #flag.append(1)
        #else:
            #flag.append(0)
    else:
        if S[i]==S[i+1]:
            flag.append(1)
        else:
            flag.append(0)

flag_2 = []
for i in range(N):
    flag_2.append(0)

for i in range(N):
    if flag[i] == 1:
        k = 0
        count = 0
        while((i == 0 or flag[i-1] == 0) and (i + k) < N and flag[i + k] == 1):
            k += 1
            count += 1
        flag_2[i] = count

#print("flag",flag)
#print("flag2", flag_2)

ans = 0
cara = set()
for i in range(N):
    cara.add(S[i])
if len(cara) == 1:
    ans = N*K//2
else:

    if(S[0] != S[N-1]):
        for i in range(N-1):
            ans += (flag_2[i] + 1)//2

        ans = ans * K

    else:
        last = 0
        for i in range(N):
            if(S[0] != S[N - 1 - i]):
                last = N - i
                break
        #print("last",last)
        temp = flag_2[0] + (N - last) + 1
        ans += temp//2 * (K - 1)
        for i in range(1, last):
            ans += (flag_2[i] + 1)//2 * K
        ans += (flag_2[0] + 1)//2
        ans += (flag_2[last] + 1)//2

print(ans)


