s = input()
k = int(input())


first = 0

for i in range(1, len(s)):
    if s[i] != s[0]:
        first = i
        break

if first == 0:
    if len(s) % 2 == 0:
        print((len(s) // 2) * k)
    else:
        print(len(s) * k // 2)
    exit()

ans = 0
cnt = 1
i = 0

while i < len(s) - 1:
    if s[i] == s[i+1]:
        cnt += 1
        if i == len(s) - 2:
            ans += cnt // 2
    else:
        ans += cnt // 2
        cnt = 1
    i += 1

ans *= k

if s[0] == s[-1] and first % 2 == 1 and cnt % 2 == 1:
    ans += k - 1

print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input first = 0 first 0 for i in range(1, len(s)):
    if s[i] != s[0]:
        first = i
        break i range(1, len(s)) range 1 len(s) len s if s[i] != s[0]:
        first = i
        break s[i] != s[0] s[i] s i s[0] s 0 first = i first i break if first == 0:
    if len(s) % 2 == 0:
        print((len(s) // 2) * k)
    else:
        print(len(s) * k // 2)
    exit() first == 0 first 0 if len(s) % 2 == 0:
        print((len(s) // 2) * k)
    else:
        print(len(s) * k // 2)
     len(s) % 2 == 0 len(s) % 2 len(s) len s 2 0 print((len(s) // 2) * k) print (len(s) // 2) * k len(s) // 2 len(s) len s 2 k print(len(s) * k // 2) print len(s) * k // 2 len(s) * k len(s) len s k 2 exit() exit ans = 0 ans 0 cnt = 1 cnt 1 i = 0 i 0 while i < len(s) - 1:
    if s[i] == s[i+1]:
        cnt += 1
        if i == len(s) - 2:
            ans += cnt // 2
    else:
        ans += cnt // 2
        cnt = 1
    i += 1 i < len(s) - 1 i len(s) - 1 len(s) len s 1 if s[i] == s[i+1]:
        cnt += 1
        if i == len(s) - 2:
            ans += cnt // 2
    else:
        ans += cnt // 2
        cnt = 1
     s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 cnt += 1 cnt 1 if i == len(s) - 2:
            ans += cnt // 2
     i == len(s) - 2 i len(s) - 2 len(s) len s 2 ans += cnt // 2 ans cnt // 2 cnt 2 ans += cnt // 2 ans cnt // 2 cnt 2 cnt = 1 cnt 1 i += 1 i 1 ans *= k ans k if s[0] == s[-1] and first % 2 == 1 and cnt % 2 == 1:
    ans += k - 1 s[0] == s[-1] and first % 2 == 1 and cnt % 2 == 1 s[0] == s[-1] and first % 2 == 1 s[0] == s[-1] s[0] s 0 s[-1] s -1 first % 2 == 1 first % 2 first 2 1 cnt % 2 == 1 cnt % 2 cnt 2 1 ans += k - 1 ans k - 1 k 1 print(ans) print ans i += 1 1 i ans += k - 1 k - 1 ans ans = 0 0 ans first = 0 0 first cnt = 1 1 cnt ans += cnt // 2 cnt // 2 ans ans *= k k ans first = i i first cnt = 1 1 cnt i = 0 0 i cnt += 1 1 cnt k = int(input()) int(input()) k ans += cnt // 2 cnt // 2 ans s = input() input() s
s = input()
k = int(input())


first = 0

for i in range(1, len(s)):
    if s[i] != s[0]:
        first = i
        break

if first == 0:
    if len(s) % 2 == 0:
        print((len(s) // 2) * k)
    else:
        print(len(s) * k // 2)
    exit()

ans = 0
cnt = 1
i = 0

while i < len(s) - 1:
    if s[i] == s[i+1]:
        cnt += 1
        if i == len(s) - 2:
            ans += cnt // 2
    else:
        ans += cnt // 2
        cnt = 1
    i += 1

ans *= k

if s[0] == s[-1] and first % 2 == 1 and cnt % 2 == 1:
    ans += k - 1

print(ans)
