import collections
s = str(input())
k = int(input())

ans = 0
#if s[0] == s[-1]:
#    ans += k

tmp = ''
tmp_num = 0

check = ''
check_num = 0

if len(collections.Counter(s).keys()) == 1:
    ans = len(s)*k//2

else:
    for i, w in enumerate(s):
        if i == 0:
            tmp += w
            tmp_num += 1
            continue
        
        if tmp[-1] == w:
            tmp += w
            tmp_num += 1
        
        elif tmp[-1] != w:
            if check_num == 0:
                check = tmp
                check_num = 1

            ans += (tmp_num // 2) * k
            #print('ans', ans)
            tmp = w
            tmp_num = 1
        
        if i == len(s)-1:
            if len(tmp) == 1:
                if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1
            else:
                #print(check, tmp)
                if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1

            ans += (tmp_num // 2) * k
            #print('last', ans)

print(ans)
 import collections collections s = str(input()) s str(input()) str input() input k = int(input()) k int(input()) int input() input ans = 0 ans 0 tmp = '' tmp '' tmp_num = 0 tmp_num 0 check = '' check '' check_num = 0 check_num 0 if len(collections.Counter(s).keys()) == 1:
    ans = len(s)*k//2

else:
    for i, w in enumerate(s):
        if i == 0:
            tmp += w
            tmp_num += 1
            continue
        
        if tmp[-1] == w:
            tmp += w
            tmp_num += 1
        
        elif tmp[-1] != w:
            if check_num == 0:
                check = tmp
                check_num = 1

            ans += (tmp_num // 2) * k
            #print('ans', ans)
            tmp = w
            tmp_num = 1
        
        if i == len(s)-1:
            if len(tmp) == 1:
                if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1
            else:
                #print(check, tmp)
                if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1

            ans += (tmp_num // 2) * k
            #print('last', ans) len(collections.Counter(s).keys()) == 1 len(collections.Counter(s).keys()) len collections.Counter(s).keys() collections.Counter(s).keys collections.Counter(s) collections.Counter collections Counter s keys 1 ans = len(s)*k//2 ans len(s)*k//2 len(s)*k len(s) len s k 2 for i, w in enumerate(s):
        if i == 0:
            tmp += w
            tmp_num += 1
            continue
        
        if tmp[-1] == w:
            tmp += w
            tmp_num += 1
        
        elif tmp[-1] != w:
            if check_num == 0:
                check = tmp
                check_num = 1

            ans += (tmp_num // 2) * k
            #print('ans', ans)
            tmp = w
            tmp_num = 1
        
        if i == len(s)-1:
            if len(tmp) == 1:
                if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1
            else:
                #print(check, tmp)
                if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1

            ans += (tmp_num // 2) * k
            #print('last', ans) i w enumerate(s) enumerate s if i == 0:
            tmp += w
            tmp_num += 1
            continue
        
         i == 0 i 0 tmp += w tmp w tmp_num += 1 tmp_num 1 continue if tmp[-1] == w:
            tmp += w
            tmp_num += 1
        
        elif tmp[-1] != w:
            if check_num == 0:
                check = tmp
                check_num = 1

            ans += (tmp_num // 2) * k
            #print('ans', ans)
            tmp = w
            tmp_num = 1
        
         tmp[-1] == w tmp[-1] tmp -1 w tmp += w tmp w tmp_num += 1 tmp_num 1 elif tmp[-1] != w:
            if check_num == 0:
                check = tmp
                check_num = 1

            ans += (tmp_num // 2) * k
            #print('ans', ans)
            tmp = w
            tmp_num = 1
        
         tmp[-1] != w tmp[-1] tmp -1 w if check_num == 0:
                check = tmp
                check_num = 1

             check_num == 0 check_num 0 check = tmp check tmp check_num = 1 check_num 1 ans += (tmp_num // 2) * k ans (tmp_num // 2) * k tmp_num // 2 tmp_num 2 k tmp = w tmp w tmp_num = 1 tmp_num 1 if i == len(s)-1:
            if len(tmp) == 1:
                if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1
            else:
                #print(check, tmp)
                if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1

            ans += (tmp_num // 2) * k
            #print('last', ans) i == len(s)-1 i len(s)-1 len(s) len s 1 if len(tmp) == 1:
                if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1
            else:
                #print(check, tmp)
                if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1

             len(tmp) == 1 len(tmp) len tmp 1 if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1
             check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1) check[0] == tmp check[0] check 0 tmp len(tmp)%2 == 1 and len(check)%2 == 1 len(tmp)%2 == 1 len(tmp)%2 len(tmp) len tmp 2 1 len(check)%2 == 1 len(check)%2 len(check) len check 2 1 ans += k-1 ans k-1 k 1 if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1

             check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1) check[0] == tmp[-1] check[0] check 0 tmp[-1] tmp -1 len(tmp)%2 == 1 and len(check)%2 == 1 len(tmp)%2 == 1 len(tmp)%2 len(tmp) len tmp 2 1 len(check)%2 == 1 len(check)%2 len(check) len check 2 1 ans += k-1 ans k-1 k 1 ans += (tmp_num // 2) * k ans (tmp_num // 2) * k tmp_num // 2 tmp_num 2 k print(ans) print ans tmp += w w tmp k = int(input()) int(input()) k check_num = 0 0 check_num tmp_num += 1 1 tmp_num ans += k-1 k-1 ans tmp = '' '' tmp ans += k-1 k-1 ans ans += (tmp_num // 2) * k (tmp_num // 2) * k ans check_num = 1 1 check_num s = str(input()) str(input()) s ans = 0 0 ans tmp_num = 0 0 tmp_num tmp += w w tmp ans += (tmp_num // 2) * k (tmp_num // 2) * k ans ans = len(s)*k//2 len(s)*k//2 ans tmp_num = 1 1 tmp_num tmp_num += 1 1 tmp_num check = tmp tmp check tmp = w w tmp check = '' '' check
import collections
s = str(input())
k = int(input())

ans = 0
#if s[0] == s[-1]:
#    ans += k

tmp = ''
tmp_num = 0

check = ''
check_num = 0

if len(collections.Counter(s).keys()) == 1:
    ans = len(s)*k//2

else:
    for i, w in enumerate(s):
        if i == 0:
            tmp += w
            tmp_num += 1
            continue
        
        if tmp[-1] == w:
            tmp += w
            tmp_num += 1
        
        elif tmp[-1] != w:
            if check_num == 0:
                check = tmp
                check_num = 1

            ans += (tmp_num // 2) * k
            #print('ans', ans)
            tmp = w
            tmp_num = 1
        
        if i == len(s)-1:
            if len(tmp) == 1:
                if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1
            else:
                #print(check, tmp)
                if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1

            ans += (tmp_num // 2) * k
            #print('last', ans)

print(ans)

