import sys
s = input()
k = int(input())
data = []
start = s[0]
seq = 1
if len(set(list(s))) == 1:
    print(len(s)*k//2)
    sys.exit()
for i in s[1:]:
    if start == i:
        seq += 1
    else:
        data.append(seq)
        start = i
        seq = 1
else:
    data.append(seq)
#print(data)
if s[0] != s[-1]:
    ans = 0
    for i in data:
        ans += i//2
    else:
        print(ans*k)
else:
    pati = data[0] + data[-1]
    ans = pati//2*(k-1)
    for i in range(1,len(data)-1):
        ans += data[i]//2*k
    else:
        print(ans+data[0]//2+data[-1]//2) import sys sys s = input() s input() input k = int(input()) k int(input()) int input() input data = [] data [] start = s[0] start s[0] s 0 seq = 1 seq 1 if len(set(list(s))) == 1:
    print(len(s)*k//2)
    sys.exit() len(set(list(s))) == 1 len(set(list(s))) len set(list(s)) set list(s) list s 1 print(len(s)*k//2) print len(s)*k//2 len(s)*k len(s) len s k 2 sys.exit() sys.exit sys exit for i in s[1:]:
    if start == i:
        seq += 1
    else:
        data.append(seq)
        start = i
        seq = 1
else:
    data.append(seq)
#print(data) i s[1:] s 1: 1 if start == i:
        seq += 1
    else:
        data.append(seq)
        start = i
        seq = 1 start == i start i seq += 1 seq 1 data.append(seq) data.append data append seq start = i start i seq = 1 seq 1 data.append(seq) data.append data append seq if s[0] != s[-1]:
    ans = 0
    for i in data:
        ans += i//2
    else:
        print(ans*k)
else:
    pati = data[0] + data[-1]
    ans = pati//2*(k-1)
    for i in range(1,len(data)-1):
        ans += data[i]//2*k
    else:
        print(ans+data[0]//2+data[-1]//2) s[0] != s[-1] s[0] s 0 s[-1] s -1 ans = 0 ans 0 for i in data:
        ans += i//2
    else:
        print(ans*k) i data ans += i//2 ans i//2 i 2 print(ans*k) print ans*k ans k pati = data[0] + data[-1] pati data[0] + data[-1] data[0] data 0 data[-1] data -1 ans = pati//2*(k-1) ans pati//2*(k-1) pati//2 pati 2 k-1 k 1 for i in range(1,len(data)-1):
        ans += data[i]//2*k
    else:
        print(ans+data[0]//2+data[-1]//2) i range(1,len(data)-1) range 1 len(data)-1 len(data) len data 1 ans += data[i]//2*k ans data[i]//2*k data[i]//2 data[i] data i 2 k print(ans+data[0]//2+data[-1]//2) print ans+data[0]//2+data[-1]//2 ans+data[0]//2 ans data[0]//2 data[0] data 0 2 data[-1]//2 data[-1] data -1 2 ans += i//2 i//2 ans s = input() input() s k = int(input()) int(input()) k seq += 1 1 seq pati = data[0] + data[-1] data[0] + data[-1] pati start = s[0] s[0] start ans = pati//2*(k-1) pati//2*(k-1) ans ans += data[i]//2*k data[i]//2*k ans ans = 0 0 ans start = i i start data = [] [] data seq = 1 1 seq seq = 1 1 seq
import sys
s = input()
k = int(input())
data = []
start = s[0]
seq = 1
if len(set(list(s))) == 1:
    print(len(s)*k//2)
    sys.exit()
for i in s[1:]:
    if start == i:
        seq += 1
    else:
        data.append(seq)
        start = i
        seq = 1
else:
    data.append(seq)
#print(data)
if s[0] != s[-1]:
    ans = 0
    for i in data:
        ans += i//2
    else:
        print(ans*k)
else:
    pati = data[0] + data[-1]
    ans = pati//2*(k-1)
    for i in range(1,len(data)-1):
        ans += data[i]//2*k
    else:
        print(ans+data[0]//2+data[-1]//2)