import sys

def solve():
    input = sys.stdin.readline
    S = list(input().strip("\n"))
    K = int(input())
    N = len(S)
    head, tail, joint = 0, 0, 0
    inside = 0
    if S[0] == S[N-1]: #ジョイント部を考える必要がある場合
        isInitial = True
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                if isInitial: 
                    head = currentLength // 2
                    isInitial = False
                else: inside += currentLength // 2
                current = S[i]
                currentLength = 1
        if isInitial: #全て同じ文字の場合
            totalLength = N * K
            print(totalLength // 2)
        else:
            tail = currentLength // 2
            for i in range(N):
                if S[i] == current: currentLength += 1
                else: 
                    joint = currentLength // 2
                    break
            print(head + tail + joint * (K - 1) + inside * K)
    else:
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                inside += currentLength // 2
                current = S[i]
                currentLength = 1
        inside += currentLength // 2
        print(inside * K)   
    #print(head, tail, joint, inside)        
    return 0

if __name__ == "__main__":
    solve() import sys sys def solve():
    input = sys.stdin.readline
    S = list(input().strip("\n"))
    K = int(input())
    N = len(S)
    head, tail, joint = 0, 0, 0
    inside = 0
    if S[0] == S[N-1]: #ジョイント部を考える必要がある場合
        isInitial = True
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                if isInitial: 
                    head = currentLength // 2
                    isInitial = False
                else: inside += currentLength // 2
                current = S[i]
                currentLength = 1
        if isInitial: #全て同じ文字の場合
            totalLength = N * K
            print(totalLength // 2)
        else:
            tail = currentLength // 2
            for i in range(N):
                if S[i] == current: currentLength += 1
                else: 
                    joint = currentLength // 2
                    break
            print(head + tail + joint * (K - 1) + inside * K)
    else:
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                inside += currentLength // 2
                current = S[i]
                currentLength = 1
        inside += currentLength // 2
        print(inside * K)   
    #print(head, tail, joint, inside)        
    return 0 solve input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline S = list(input().strip("\n")) S list(input().strip("\n")) list input().strip("\n") ().strip () input strip "\n" K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S head, tail, joint = 0, 0, 0 head 0 tail 0 joint 0 inside = 0 inside 0 if S[0] == S[N-1]: #ジョイント部を考える必要がある場合
        isInitial = True
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                if isInitial: 
                    head = currentLength // 2
                    isInitial = False
                else: inside += currentLength // 2
                current = S[i]
                currentLength = 1
        if isInitial: #全て同じ文字の場合
            totalLength = N * K
            print(totalLength // 2)
        else:
            tail = currentLength // 2
            for i in range(N):
                if S[i] == current: currentLength += 1
                else: 
                    joint = currentLength // 2
                    break
            print(head + tail + joint * (K - 1) + inside * K)
    else:
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                inside += currentLength // 2
                current = S[i]
                currentLength = 1
        inside += currentLength // 2
        print(inside * K)   
    #print(head, tail, joint, inside)        
     S[0] == S[N-1] S[0] S 0 S[N-1] S N-1 N 1 isInitial = True isInitial True current = S[0] current S[0] S 0 currentLength = 1 currentLength 1 for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                if isInitial: 
                    head = currentLength // 2
                    isInitial = False
                else: inside += currentLength // 2
                current = S[i]
                currentLength = 1
         i range(1, N) range 1 N if S[i] == current: currentLength += 1
            else:
                if isInitial: 
                    head = currentLength // 2
                    isInitial = False
                else: inside += currentLength // 2
                current = S[i]
                currentLength = 1
         S[i] == current S[i] S i current if isInitial: 
                    head = currentLength // 2
                    isInitial = False
                else: inside += currentLength // 2
                 isInitial head = currentLength // 2 head currentLength // 2 currentLength 2 isInitial = False isInitial False current = S[i] current S[i] S i currentLength = 1 currentLength 1 if isInitial: #全て同じ文字の場合
            totalLength = N * K
            print(totalLength // 2)
        else:
            tail = currentLength // 2
            for i in range(N):
                if S[i] == current: currentLength += 1
                else: 
                    joint = currentLength // 2
                    break
            print(head + tail + joint * (K - 1) + inside * K)
     isInitial totalLength = N * K totalLength N * K N K print(totalLength // 2) print totalLength // 2 totalLength 2 tail = currentLength // 2 tail currentLength // 2 currentLength 2 for i in range(N):
                if S[i] == current: currentLength += 1
                else: 
                    joint = currentLength // 2
                    break
             i range(N) range N if S[i] == current: currentLength += 1
                else: 
                    joint = currentLength // 2
                    break
             S[i] == current S[i] S i current joint = currentLength // 2 joint currentLength // 2 currentLength 2 break print(head + tail + joint * (K - 1) + inside * K) print head + tail + joint * (K - 1) + inside * K head + tail + joint * (K - 1) head + tail head tail joint * (K - 1) joint K - 1 K 1 inside * K inside K current = S[0] current S[0] S 0 currentLength = 1 currentLength 1 for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                inside += currentLength // 2
                current = S[i]
                currentLength = 1
         i range(1, N) range 1 N if S[i] == current: currentLength += 1
            else:
                inside += currentLength // 2
                current = S[i]
                currentLength = 1
         S[i] == current S[i] S i current inside += currentLength // 2 inside currentLength // 2 currentLength 2 current = S[i] current S[i] S i currentLength = 1 currentLength 1 inside += currentLength // 2 inside currentLength // 2 currentLength 2 print(inside * K) print inside * K inside K return 0 0 if __name__ == "__main__":
    solve() __name__ == "__main__" __name__ "__main__" solve() solve def solve():
    input = sys.stdin.readline
    S = list(input().strip("\n"))
    K = int(input())
    N = len(S)
    head, tail, joint = 0, 0, 0
    inside = 0
    if S[0] == S[N-1]: #ジョイント部を考える必要がある場合
        isInitial = True
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                if isInitial: 
                    head = currentLength // 2
                    isInitial = False
                else: inside += currentLength // 2
                current = S[i]
                currentLength = 1
        if isInitial: #全て同じ文字の場合
            totalLength = N * K
            print(totalLength // 2)
        else:
            tail = currentLength // 2
            for i in range(N):
                if S[i] == current: currentLength += 1
                else: 
                    joint = currentLength // 2
                    break
            print(head + tail + joint * (K - 1) + inside * K)
    else:
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                inside += currentLength // 2
                current = S[i]
                currentLength = 1
        inside += currentLength // 2
        print(inside * K)   
    #print(head, tail, joint, inside)        
    return 0 def solve():
    input = sys.stdin.readline
    S = list(input().strip("\n"))
    K = int(input())
    N = len(S)
    head, tail, joint = 0, 0, 0
    inside = 0
    if S[0] == S[N-1]: #ジョイント部を考える必要がある場合
        isInitial = True
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                if isInitial: 
                    head = currentLength // 2
                    isInitial = False
                else: inside += currentLength // 2
                current = S[i]
                currentLength = 1
        if isInitial: #全て同じ文字の場合
            totalLength = N * K
            print(totalLength // 2)
        else:
            tail = currentLength // 2
            for i in range(N):
                if S[i] == current: currentLength += 1
                else: 
                    joint = currentLength // 2
                    break
            print(head + tail + joint * (K - 1) + inside * K)
    else:
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                inside += currentLength // 2
                current = S[i]
                currentLength = 1
        inside += currentLength // 2
        print(inside * K)   
    #print(head, tail, joint, inside)        
    return 0 solve
import sys

def solve():
    input = sys.stdin.readline
    S = list(input().strip("\n"))
    K = int(input())
    N = len(S)
    head, tail, joint = 0, 0, 0
    inside = 0
    if S[0] == S[N-1]: #ジョイント部を考える必要がある場合
        isInitial = True
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                if isInitial: 
                    head = currentLength // 2
                    isInitial = False
                else: inside += currentLength // 2
                current = S[i]
                currentLength = 1
        if isInitial: #全て同じ文字の場合
            totalLength = N * K
            print(totalLength // 2)
        else:
            tail = currentLength // 2
            for i in range(N):
                if S[i] == current: currentLength += 1
                else: 
                    joint = currentLength // 2
                    break
            print(head + tail + joint * (K - 1) + inside * K)
    else:
        current = S[0]
        currentLength = 1
        for i in range(1, N):
            if S[i] == current: currentLength += 1
            else:
                inside += currentLength // 2
                current = S[i]
                currentLength = 1
        inside += currentLength // 2
        print(inside * K)   
    #print(head, tail, joint, inside)        
    return 0

if __name__ == "__main__":
    solve()