import sys

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

flg = True
for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        flg = False
        break

if flg:
    print(len(s) * k // 2)
    sys.exit()

ans = 0
skip = -1
for i in range(len(s) - 1):
    if i == skip:
        continue
    
    if s[i] == s[i + 1]:
        ans += 1
        skip = i + 1
        
#print(ans)
ans *= k


if s[0] == s[-1]:
    cnt_h = 1
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt_h += 1
        else:
            break
    
    cnt_t = 1
    for i in reversed(range(1, len(s))):
        if s[i] == s[i - 1]:
            cnt_t += 1
        else:
            break
    #print(cnt_h, cnt_t)
    cnt = cnt_h // 2 + cnt_t // 2
    cnt -= (cnt_h + cnt_t) // 2
    cnt *= k - 1
    ans -= cnt

print(ans) import sys sys s = input() s input() input k = int(input()) k int(input()) int input() input flg = True flg True for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        flg = False
        break i range(len(s) - 1) range len(s) - 1 len(s) len s 1 if s[i] != s[i + 1]:
        flg = False
        break s[i] != s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 flg = False flg False break if flg:
    print(len(s) * k // 2)
    sys.exit() flg 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 ans = 0 ans 0 skip = -1 skip -1 for i in range(len(s) - 1):
    if i == skip:
        continue
    
    if s[i] == s[i + 1]:
        ans += 1
        skip = i + 1
        
#print(ans) i range(len(s) - 1) range len(s) - 1 len(s) len s 1 if i == skip:
        continue
    
     i == skip i skip continue if s[i] == s[i + 1]:
        ans += 1
        skip = i + 1
        
#print(ans) s[i] == s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 ans += 1 ans 1 skip = i + 1 skip i + 1 i 1 ans *= k ans k if s[0] == s[-1]:
    cnt_h = 1
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt_h += 1
        else:
            break
    
    cnt_t = 1
    for i in reversed(range(1, len(s))):
        if s[i] == s[i - 1]:
            cnt_t += 1
        else:
            break
    #print(cnt_h, cnt_t)
    cnt = cnt_h // 2 + cnt_t // 2
    cnt -= (cnt_h + cnt_t) // 2
    cnt *= k - 1
    ans -= cnt s[0] == s[-1] s[0] s 0 s[-1] s -1 cnt_h = 1 cnt_h 1 for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt_h += 1
        else:
            break
    
     i range(len(s) - 1) range len(s) - 1 len(s) len s 1 if s[i] == s[i + 1]:
            cnt_h += 1
        else:
            break
    
     s[i] == s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 cnt_h += 1 cnt_h 1 break cnt_t = 1 cnt_t 1 for i in reversed(range(1, len(s))):
        if s[i] == s[i - 1]:
            cnt_t += 1
        else:
            break
    #print(cnt_h, cnt_t)
     i reversed(range(1, len(s))) reversed range(1, len(s)) range 1 len(s) len s if s[i] == s[i - 1]:
            cnt_t += 1
        else:
            break
    #print(cnt_h, cnt_t)
     s[i] == s[i - 1] s[i] s i s[i - 1] s i - 1 i 1 cnt_t += 1 cnt_t 1 break cnt = cnt_h // 2 + cnt_t // 2 cnt cnt_h // 2 + cnt_t // 2 cnt_h // 2 cnt_h 2 cnt_t // 2 cnt_t 2 cnt -= (cnt_h + cnt_t) // 2 cnt (cnt_h + cnt_t) // 2 cnt_h + cnt_t cnt_h cnt_t 2 cnt *= k - 1 cnt k - 1 k 1 ans -= cnt ans cnt print(ans) print ans cnt_h += 1 1 cnt_h cnt *= k - 1 k - 1 cnt ans = 0 0 ans s = input() input() s skip = -1 -1 skip skip = i + 1 i + 1 skip cnt_t += 1 1 cnt_t flg = False False flg ans += 1 1 ans ans -= cnt cnt ans cnt = cnt_h // 2 + cnt_t // 2 cnt_h // 2 + cnt_t // 2 cnt flg = True True flg cnt_t = 1 1 cnt_t cnt_h = 1 1 cnt_h k = int(input()) int(input()) k ans *= k k ans cnt -= (cnt_h + cnt_t) // 2 (cnt_h + cnt_t) // 2 cnt
import sys

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

flg = True
for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        flg = False
        break

if flg:
    print(len(s) * k // 2)
    sys.exit()

ans = 0
skip = -1
for i in range(len(s) - 1):
    if i == skip:
        continue
    
    if s[i] == s[i + 1]:
        ans += 1
        skip = i + 1
        
#print(ans)
ans *= k


if s[0] == s[-1]:
    cnt_h = 1
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt_h += 1
        else:
            break
    
    cnt_t = 1
    for i in reversed(range(1, len(s))):
        if s[i] == s[i - 1]:
            cnt_t += 1
        else:
            break
    #print(cnt_h, cnt_t)
    cnt = cnt_h // 2 + cnt_t // 2
    cnt -= (cnt_h + cnt_t) // 2
    cnt *= k - 1
    ans -= cnt

print(ans)