from collections import Counter

S1 = input()
K = int(input())
S1C = Counter(S1)
if len(S1C) == 1:
    print(len(S1) * K // 2)
    exit()

start = S1[0]
end = S1[-1]
now = S1[0]
a1 = 0
flag = False
for s in S1[1:]:
    if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a1 += 1
            flag = True
        now = s
S2 = S1 + S1

start = S2[0]
end = S2[-1]
now = S2[0]
a2 = 0
flag = False
for s in S2[1:]:
    if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a2 += 1
            flag = True
        now = s
b = a2 - 2 * a1

print(a1 * K + b * (K-1)) from collections import Counter S1 = input() S1 input() input K = int(input()) K int(input()) int input() input S1C = Counter(S1) S1C Counter(S1) Counter S1 if len(S1C) == 1:
    print(len(S1) * K // 2)
    exit() len(S1C) == 1 len(S1C) len S1C 1 print(len(S1) * K // 2) print len(S1) * K // 2 len(S1) * K len(S1) len S1 K 2 exit() exit start = S1[0] start S1[0] S1 0 end = S1[-1] end S1[-1] S1 -1 now = S1[0] now S1[0] S1 0 a1 = 0 a1 0 flag = False flag False for s in S1[1:]:
    if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a1 += 1
            flag = True
        now = s s S1[1:] S1 1: 1 if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a1 += 1
            flag = True
        now = s flag flag = False flag False now = s now s continue if s == now:
            a1 += 1
            flag = True
         s == now s now a1 += 1 a1 1 flag = True flag True now = s now s S2 = S1 + S1 S2 S1 + S1 S1 S1 start = S2[0] start S2[0] S2 0 end = S2[-1] end S2[-1] S2 -1 now = S2[0] now S2[0] S2 0 a2 = 0 a2 0 flag = False flag False for s in S2[1:]:
    if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a2 += 1
            flag = True
        now = s s S2[1:] S2 1: 1 if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a2 += 1
            flag = True
        now = s flag flag = False flag False now = s now s continue if s == now:
            a2 += 1
            flag = True
         s == now s now a2 += 1 a2 1 flag = True flag True now = s now s b = a2 - 2 * a1 b a2 - 2 * a1 a2 2 * a1 2 a1 print(a1 * K + b * (K-1)) print a1 * K + b * (K-1) a1 * K a1 K b * (K-1) b K-1 K 1 S2 = S1 + S1 S1 + S1 S2 start = S2[0] S2[0] start now = s s now a2 = 0 0 a2 S1 = input() input() S1 flag = False False flag now = S1[0] S1[0] now flag = False False flag K = int(input()) int(input()) K flag = True True flag a1 += 1 1 a1 start = S1[0] S1[0] start now = s s now now = S2[0] S2[0] now a1 = 0 0 a1 end = S1[-1] S1[-1] end end = S2[-1] S2[-1] end S1C = Counter(S1) Counter(S1) S1C flag = False False flag now = s s now a2 += 1 1 a2 flag = True True flag flag = False False flag now = s s now b = a2 - 2 * a1 a2 - 2 * a1 b
from collections import Counter

S1 = input()
K = int(input())
S1C = Counter(S1)
if len(S1C) == 1:
    print(len(S1) * K // 2)
    exit()

start = S1[0]
end = S1[-1]
now = S1[0]
a1 = 0
flag = False
for s in S1[1:]:
    if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a1 += 1
            flag = True
        now = s
S2 = S1 + S1

start = S2[0]
end = S2[-1]
now = S2[0]
a2 = 0
flag = False
for s in S2[1:]:
    if flag:
        flag = False
        now = s
        continue
    else:
        if s == now:
            a2 += 1
            flag = True
        now = s
b = a2 - 2 * a1

print(a1 * K + b * (K-1))