s = input()
K = int(input())

if s == (s[0]*len(s)):
    print((len(s)*K)//2)

elif s[0] == s[-1]:
    front = 0
    back = len(s)-1
    for i in range(len(s)-1):
        if s[i] is s[i+1]:
            front += 1
        else:
            break

    for i in range(len(s)-1, 1, -1):
        if s[i] == s[i-1]:
            back -= 1
        else:
            break
    
    s_front = s[:front+1]
    s_back = s[back:]
    s_middle = s[front+1:back]

    new_s = s_middle + s_back + s_front
            
    ans = 0
    cnt = 1
    for i in range(len(new_s)-1):
        if new_s[i] == new_s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K-1

    cnt = 1
    for i in range(len(s_middle)-1):
        if s_middle[i] == s_middle[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans += (front+1)//2 + (len(s)-back)//2
    print(ans)
    
else:
    ans = 0
    cnt = 1
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    print(ans) s = input() s input() input K = int(input()) K int(input()) int input() input if s == (s[0]*len(s)):
    print((len(s)*K)//2)

elif s[0] == s[-1]:
    front = 0
    back = len(s)-1
    for i in range(len(s)-1):
        if s[i] is s[i+1]:
            front += 1
        else:
            break

    for i in range(len(s)-1, 1, -1):
        if s[i] == s[i-1]:
            back -= 1
        else:
            break
    
    s_front = s[:front+1]
    s_back = s[back:]
    s_middle = s[front+1:back]

    new_s = s_middle + s_back + s_front
            
    ans = 0
    cnt = 1
    for i in range(len(new_s)-1):
        if new_s[i] == new_s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K-1

    cnt = 1
    for i in range(len(s_middle)-1):
        if s_middle[i] == s_middle[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans += (front+1)//2 + (len(s)-back)//2
    print(ans)
    
else:
    ans = 0
    cnt = 1
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    print(ans) s == (s[0]*len(s)) s s[0]*len(s) s[0] s 0 len(s) len s print((len(s)*K)//2) print (len(s)*K)//2 len(s)*K len(s) len s K 2 elif s[0] == s[-1]:
    front = 0
    back = len(s)-1
    for i in range(len(s)-1):
        if s[i] is s[i+1]:
            front += 1
        else:
            break

    for i in range(len(s)-1, 1, -1):
        if s[i] == s[i-1]:
            back -= 1
        else:
            break
    
    s_front = s[:front+1]
    s_back = s[back:]
    s_middle = s[front+1:back]

    new_s = s_middle + s_back + s_front
            
    ans = 0
    cnt = 1
    for i in range(len(new_s)-1):
        if new_s[i] == new_s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K-1

    cnt = 1
    for i in range(len(s_middle)-1):
        if s_middle[i] == s_middle[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans += (front+1)//2 + (len(s)-back)//2
    print(ans)
     s[0] == s[-1] s[0] s 0 s[-1] s -1 front = 0 front 0 back = len(s)-1 back len(s)-1 len(s) len s 1 for i in range(len(s)-1):
        if s[i] is s[i+1]:
            front += 1
        else:
            break

     i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i] is s[i+1]:
            front += 1
        else:
            break

     s[i] is s[i+1] s[i] s i s[i+1] s i+1 i 1 front += 1 front 1 break for i in range(len(s)-1, 1, -1):
        if s[i] == s[i-1]:
            back -= 1
        else:
            break
    
     i range(len(s)-1, 1, -1) range len(s)-1 len(s) len s 1 1 -1 if s[i] == s[i-1]:
            back -= 1
        else:
            break
    
     s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 back -= 1 back 1 break s_front = s[:front+1] s_front s[:front+1] s :front+1 front+1 front 1 s_back = s[back:] s_back s[back:] s back: back s_middle = s[front+1:back] s_middle s[front+1:back] s front+1:back front+1 front 1 back new_s = s_middle + s_back + s_front new_s s_middle + s_back + s_front s_middle + s_back s_middle s_back s_front ans = 0 ans 0 cnt = 1 cnt 1 for i in range(len(new_s)-1):
        if new_s[i] == new_s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
     i range(len(new_s)-1) range len(new_s)-1 len(new_s) len new_s 1 if new_s[i] == new_s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
     new_s[i] == new_s[i+1] new_s[i] new_s i new_s[i+1] new_s i+1 i 1 cnt += 1 cnt 1 ans += cnt//2 ans cnt//2 cnt 2 cnt = 1 cnt 1 ans += cnt//2 ans cnt//2 cnt 2 ans *= K-1 ans K-1 K 1 cnt = 1 cnt 1 for i in range(len(s_middle)-1):
        if s_middle[i] == s_middle[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
     i range(len(s_middle)-1) range len(s_middle)-1 len(s_middle) len s_middle 1 if s_middle[i] == s_middle[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
     s_middle[i] == s_middle[i+1] s_middle[i] s_middle i s_middle[i+1] s_middle i+1 i 1 cnt += 1 cnt 1 ans += cnt//2 ans cnt//2 cnt 2 cnt = 1 cnt 1 ans += cnt//2 ans cnt//2 cnt 2 ans += (front+1)//2 + (len(s)-back)//2 ans (front+1)//2 + (len(s)-back)//2 (front+1)//2 front+1 front 1 2 (len(s)-back)//2 len(s)-back len(s) len s back 2 print(ans) print ans ans = 0 ans 0 cnt = 1 cnt 1 for i in range(len(s)-1):
        if s[i] == s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
     i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i] == s[i+1]:
            cnt += 1
        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 ans += cnt//2 ans cnt//2 cnt 2 cnt = 1 cnt 1 ans += cnt//2 ans cnt//2 cnt 2 ans *= K ans K print(ans) print ans ans = 0 0 ans ans += cnt//2 cnt//2 ans front = 0 0 front cnt = 1 1 cnt cnt = 1 1 cnt ans *= K-1 K-1 ans cnt = 1 1 cnt cnt += 1 1 cnt s_back = s[back:] s[back:] s_back front += 1 1 front ans += cnt//2 cnt//2 ans back = len(s)-1 len(s)-1 back K = int(input()) int(input()) K cnt += 1 1 cnt ans *= K K ans cnt += 1 1 cnt s = input() input() s s_front = s[:front+1] s[:front+1] s_front ans += (front+1)//2 + (len(s)-back)//2 (front+1)//2 + (len(s)-back)//2 ans ans += cnt//2 cnt//2 ans back -= 1 1 back ans += cnt//2 cnt//2 ans s_middle = s[front+1:back] s[front+1:back] s_middle ans += cnt//2 cnt//2 ans cnt = 1 1 cnt ans = 0 0 ans ans += cnt//2 cnt//2 ans new_s = s_middle + s_back + s_front s_middle + s_back + s_front new_s cnt = 1 1 cnt cnt = 1 1 cnt
s = input()
K = int(input())

if s == (s[0]*len(s)):
    print((len(s)*K)//2)

elif s[0] == s[-1]:
    front = 0
    back = len(s)-1
    for i in range(len(s)-1):
        if s[i] is s[i+1]:
            front += 1
        else:
            break

    for i in range(len(s)-1, 1, -1):
        if s[i] == s[i-1]:
            back -= 1
        else:
            break
    
    s_front = s[:front+1]
    s_back = s[back:]
    s_middle = s[front+1:back]

    new_s = s_middle + s_back + s_front
            
    ans = 0
    cnt = 1
    for i in range(len(new_s)-1):
        if new_s[i] == new_s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K-1

    cnt = 1
    for i in range(len(s_middle)-1):
        if s_middle[i] == s_middle[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans += (front+1)//2 + (len(s)-back)//2
    print(ans)
    
else:
    ans = 0
    cnt = 1
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    print(ans)