s = input()
k = int(input())
if len(s) == 1:
    print(k // 2)
    exit()

press = []
temp = s[0]
cnt = 0
for i in range(len(s)):
    if temp == s[i]:cnt += 1
    else:
        press.append((temp, cnt))
        cnt = 1
        temp = s[i]
press.append((temp, cnt))

if len(press) == 1:
    print(len(s) * k // 2)
    exit()

count = 0
for str, num in press:
    if num > 1:
        count += num // 2

count *= k
if s[0] == s[-1]:
    count -= (press[0][1] // 2 + press[-1][1] // 2 - (press[0][1] + press[-1][1]) // 2) * (k - 1)
print(count) s = input() s input() input k = int(input()) k int(input()) int input() input if len(s) == 1:
    print(k // 2)
    exit() len(s) == 1 len(s) len s 1 print(k // 2) print k // 2 k 2 exit() exit press = [] press [] temp = s[0] temp s[0] s 0 cnt = 0 cnt 0 for i in range(len(s)):
    if temp == s[i]:cnt += 1
    else:
        press.append((temp, cnt))
        cnt = 1
        temp = s[i] i range(len(s)) range len(s) len s if temp == s[i]:cnt += 1
    else:
        press.append((temp, cnt))
        cnt = 1
        temp = s[i] temp == s[i] temp s[i] s i press.append((temp, cnt)) press.append press append (temp, cnt) temp cnt cnt = 1 cnt 1 temp = s[i] temp s[i] s i press.append((temp, cnt)) press.append press append (temp, cnt) temp cnt if len(press) == 1:
    print(len(s) * k // 2)
    exit() len(press) == 1 len(press) len press 1 print(len(s) * k // 2) print len(s) * k // 2 len(s) * k len(s) len s k 2 exit() exit count = 0 count 0 for str, num in press:
    if num > 1:
        count += num // 2 str num press if num > 1:
        count += num // 2 num > 1 num 1 count += num // 2 count num // 2 num 2 count *= k count k if s[0] == s[-1]:
    count -= (press[0][1] // 2 + press[-1][1] // 2 - (press[0][1] + press[-1][1]) // 2) * (k - 1) s[0] == s[-1] s[0] s 0 s[-1] s -1 count -= (press[0][1] // 2 + press[-1][1] // 2 - (press[0][1] + press[-1][1]) // 2) * (k - 1) count (press[0][1] // 2 + press[-1][1] // 2 - (press[0][1] + press[-1][1]) // 2) * (k - 1) press[0][1] // 2 + press[-1][1] // 2 - (press[0][1] + press[-1][1]) // 2 press[0][1] // 2 + press[-1][1] // 2 press[0][1] // 2 press[0][1] [0] press 0 1 2 press[-1][1] // 2 press[-1][1] [-1] press -1 1 2 (press[0][1] + press[-1][1]) // 2 press[0][1] + press[-1][1] press[0][1] [0] press 0 1 press[-1][1] [-1] press -1 1 2 k - 1 k 1 print(count) print count count += num // 2 num // 2 count count -= (press[0][1] // 2 + press[-1][1] // 2 - (press[0][1] + press[-1][1]) // 2) * (k - 1) (press[0][1] // 2 + press[-1][1] // 2 - (press[0][1] + press[-1][1]) // 2) * (k - 1) count cnt = 1 1 cnt cnt = 0 0 cnt count = 0 0 count count *= k k count s = input() input() s temp = s[0] s[0] temp temp = s[i] s[i] temp press = [] [] press k = int(input()) int(input()) k
s = input()
k = int(input())
if len(s) == 1:
    print(k // 2)
    exit()

press = []
temp = s[0]
cnt = 0
for i in range(len(s)):
    if temp == s[i]:cnt += 1
    else:
        press.append((temp, cnt))
        cnt = 1
        temp = s[i]
press.append((temp, cnt))

if len(press) == 1:
    print(len(s) * k // 2)
    exit()

count = 0
for str, num in press:
    if num > 1:
        count += num // 2

count *= k
if s[0] == s[-1]:
    count -= (press[0][1] // 2 + press[-1][1] // 2 - (press[0][1] + press[-1][1]) // 2) * (k - 1)
print(count)