import sys, collections, copy



def solve():

    S = list(eval(input()))

    S2 = copy.deepcopy(S)

    K = int(eval(input()))

    lens = len(S)

    head_change = 0

    for i in range(1, lens):

        if S[i] == S[i - 1]:

            head_change += 1

            S[i] = "Changed"

    

    inner_change = 1

    S2[0] = "Changed"

    for i in range(1, lens):

        if S2[i] == S2[i-1]:

            inner_change += 1

            S2[i] = "Changed"



    if lens == 1: print((K // 2))

    elif S[lens-1] != "Changed" and S[0] == S[lens - 1]:

        if S2[lens-1] != "Changed":

            print((head_change + inner_change * (K - 1)))

        else:

            print(((head_change + inner_change) * (K // 2) + head_change * (K % 2)))

    else:

        print((head_change * K))

    #print(S)



    return 0



if __name__ == "__main__":

    solve()
import sys



def solve():

    input = sys.stdin.readline

    S = list(input().strip("\n"))

    K = int(eval(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, collections, copy


def solve():
    S = list(eval(input()))
    S2 = copy.deepcopy(S)
    K = int(eval(input()))
    lens = len(S)
    head_change = 0
    for i in range(1, lens):
        if S[i] == S[i - 1]:
            head_change += 1
            S[i] = "Changed"
    inner_change = 1
    S2[0] = "Changed"
    for i in range(1, lens):
        if S2[i] == S2[i - 1]:
            inner_change += 1
            S2[i] = "Changed"
    if lens == 1:
        print((K // 2))
    elif S[lens - 1] != "Changed" and S[0] == S[lens - 1]:
        if S2[lens - 1] != "Changed":
            print((head_change + inner_change * (K - 1)))
        else:
            print(((head_change + inner_change) * (K // 2) + head_change * (K % 2)))
    else:
        print((head_change * K))
    # print(S)
    return 0


if __name__ == "__main__":
    solve()

import sys


def solve():
    input = sys.stdin.readline
    S = list(input().strip("\n"))
    K = int(eval(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, collections, copy +import sys -    S = list(eval(input())) -    S2 = copy.deepcopy(S) +    input = sys.stdin.readline +    S = list(input().strip("\n")) -    lens = len(S) -    head_change = 0 -    for i in range(1, lens): -        if S[i] == S[i - 1]: -            head_change += 1 -            S[i] = "Changed" -    inner_change = 1 -    S2[0] = "Changed" -    for i in range(1, lens): -        if S2[i] == S2[i - 1]: -            inner_change += 1 -            S2[i] = "Changed" -    if lens == 1: -        print((K // 2)) -    elif S[lens - 1] != "Changed" and S[0] == S[lens - 1]: -        if S2[lens - 1] != "Changed": -            print((head_change + inner_change * (K - 1))) +    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)) -            print(((head_change + inner_change) * (K // 2) + head_change * (K % 2))) +            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)) -        print((head_change * K)) -    # print(S) +        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)