import sys

input = sys.stdin.readline

 

s = input().rstrip()

k = int(eval(input()))

    

def check_count(s):

    cnt_list = [1]

    cnt = 1

    for i in range(1, len(s)):

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

            cnt_list[-1] += 1

        else:

            cnt_list.append(1)

    return cnt_list



def calc_ans(cnt_list, k):

    _ans = 0

    for c in cnt_list:

        _ans += c//2

    return(_ans * k)



if len(s)==1:

    ans = k//2

else:

    cnt_list = check_count(s)

    if len(cnt_list)==1:

        ans = (len(s)*k)//2

    else:

        ans = calc_ans(cnt_list, k)

        if s[0]==s[-1]:

            if cnt_list[0]%2==1 and cnt_list[-1]%2==1:

                ans += k - 1



print(ans)
import sys

input = sys.stdin.readline

 

s = input().rstrip()

k = int(eval(input()))



def check_count(s):

    cnt_list = []

    cnt = 1

    for i in range(1, len(s)):

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

            cnt += 1

        else:

            cnt_list.append(cnt)

            cnt = 1

    if cnt>1:

        cnt_list.append(cnt)

    return cnt_list



def calc_ans(cnt_list, k):

    _ans = 0

    for c in cnt_list:

        _ans += c//2

    return(_ans * k)



if len(s)==1:

    ans = k//2

else:

    cnt_list = check_count(s)

    if len(cnt_list)==1:

        ans = (len(s)*k)//2

    else:

        ans = calc_ans(cnt_list, k)

        if s[0]==s[-1]:

            if cnt_list[0]%2==1 and cnt_list[-1]%2==1:

                ans += k - 1



print(ans)
import sys

input = sys.stdin.readline
s = input().rstrip()
k = int(eval(input()))


def check_count(s):
    cnt_list = [1]
    cnt = 1
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            cnt_list[-1] += 1
        else:
            cnt_list.append(1)
    return cnt_list


def calc_ans(cnt_list, k):
    _ans = 0
    for c in cnt_list:
        _ans += c // 2
    return _ans * k


if len(s) == 1:
    ans = k // 2
else:
    cnt_list = check_count(s)
    if len(cnt_list) == 1:
        ans = (len(s) * k) // 2
    else:
        ans = calc_ans(cnt_list, k)
        if s[0] == s[-1]:
            if cnt_list[0] % 2 == 1 and cnt_list[-1] % 2 == 1:
                ans += k - 1
print(ans)

import sys

input = sys.stdin.readline
s = input().rstrip()
k = int(eval(input()))


def check_count(s):
    cnt_list = []
    cnt = 1
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            cnt += 1
        else:
            cnt_list.append(cnt)
            cnt = 1
    if cnt > 1:
        cnt_list.append(cnt)
    return cnt_list


def calc_ans(cnt_list, k):
    _ans = 0
    for c in cnt_list:
        _ans += c // 2
    return _ans * k


if len(s) == 1:
    ans = k // 2
else:
    cnt_list = check_count(s)
    if len(cnt_list) == 1:
        ans = (len(s) * k) // 2
    else:
        ans = calc_ans(cnt_list, k)
        if s[0] == s[-1]:
            if cnt_list[0] % 2 == 1 and cnt_list[-1] % 2 == 1:
                ans += k - 1
print(ans)

-    cnt_list = [1] +    cnt_list = [] -            cnt_list[-1] += 1 +            cnt += 1 -            cnt_list.append(1) +            cnt_list.append(cnt) +            cnt = 1 +    if cnt > 1: +        cnt_list.append(cnt)