from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    S = list(input())
    K = int(input())
    l = []
    cnt = 0
    if len(S)==1:
        print(K//2)
    else:
        gr = groupby(S)
        for key, group in gr:
            l.append(list(group))
        if len(l)==1:
            print(len(S)*K//2)
        else:
            for i in range(len(l)):
                cnt += len(l[i]) // 2
                
            if l[0][0] == l[-1][0]:
                dev = len(l[0]) // 2 + len(l[-1]) // 2 - (len(l[-1]) + len(l[0])) // 2
            else:
                dev = 0
            print(cnt * K - dev * (K - 1))


resolve() from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product import sys sys sys.setrecursionlimit(10 ** 5 + 10) sys.setrecursionlimit sys setrecursionlimit 10 ** 5 + 10 10 ** 5 10 5 10 def input(): return sys.stdin.readline().strip() input def resolve():
    S = list(input())
    K = int(input())
    l = []
    cnt = 0
    if len(S)==1:
        print(K//2)
    else:
        gr = groupby(S)
        for key, group in gr:
            l.append(list(group))
        if len(l)==1:
            print(len(S)*K//2)
        else:
            for i in range(len(l)):
                cnt += len(l[i]) // 2
                
            if l[0][0] == l[-1][0]:
                dev = len(l[0]) // 2 + len(l[-1]) // 2 - (len(l[-1]) + len(l[0])) // 2
            else:
                dev = 0
            print(cnt * K - dev * (K - 1)) resolve S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input l = [] l [] cnt = 0 cnt 0 if len(S)==1:
        print(K//2)
    else:
        gr = groupby(S)
        for key, group in gr:
            l.append(list(group))
        if len(l)==1:
            print(len(S)*K//2)
        else:
            for i in range(len(l)):
                cnt += len(l[i]) // 2
                
            if l[0][0] == l[-1][0]:
                dev = len(l[0]) // 2 + len(l[-1]) // 2 - (len(l[-1]) + len(l[0])) // 2
            else:
                dev = 0
            print(cnt * K - dev * (K - 1)) len(S)==1 len(S) len S 1 print(K//2) print K//2 K 2 gr = groupby(S) gr groupby(S) groupby S for key, group in gr:
            l.append(list(group))
         key group gr l.append(list(group)) l.append l append list(group) list group if len(l)==1:
            print(len(S)*K//2)
        else:
            for i in range(len(l)):
                cnt += len(l[i]) // 2
                
            if l[0][0] == l[-1][0]:
                dev = len(l[0]) // 2 + len(l[-1]) // 2 - (len(l[-1]) + len(l[0])) // 2
            else:
                dev = 0
            print(cnt * K - dev * (K - 1)) len(l)==1 len(l) len l 1 print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 for i in range(len(l)):
                cnt += len(l[i]) // 2
                
             i range(len(l)) range len(l) len l cnt += len(l[i]) // 2 cnt len(l[i]) // 2 len(l[i]) len l[i] l i 2 if l[0][0] == l[-1][0]:
                dev = len(l[0]) // 2 + len(l[-1]) // 2 - (len(l[-1]) + len(l[0])) // 2
            else:
                dev = 0
             l[0][0] == l[-1][0] l[0][0] [0] l 0 0 l[-1][0] [-1] l -1 0 dev = len(l[0]) // 2 + len(l[-1]) // 2 - (len(l[-1]) + len(l[0])) // 2 dev len(l[0]) // 2 + len(l[-1]) // 2 - (len(l[-1]) + len(l[0])) // 2 len(l[0]) // 2 + len(l[-1]) // 2 len(l[0]) // 2 len(l[0]) len l[0] l 0 2 len(l[-1]) // 2 len(l[-1]) len l[-1] l -1 2 (len(l[-1]) + len(l[0])) // 2 len(l[-1]) + len(l[0]) len(l[-1]) len l[-1] l -1 len(l[0]) len l[0] l 0 2 dev = 0 dev 0 print(cnt * K - dev * (K - 1)) print cnt * K - dev * (K - 1) cnt * K cnt K dev * (K - 1) dev K - 1 K 1 resolve() resolve def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input def resolve():
    S = list(input())
    K = int(input())
    l = []
    cnt = 0
    if len(S)==1:
        print(K//2)
    else:
        gr = groupby(S)
        for key, group in gr:
            l.append(list(group))
        if len(l)==1:
            print(len(S)*K//2)
        else:
            for i in range(len(l)):
                cnt += len(l[i]) // 2
                
            if l[0][0] == l[-1][0]:
                dev = len(l[0]) // 2 + len(l[-1]) // 2 - (len(l[-1]) + len(l[0])) // 2
            else:
                dev = 0
            print(cnt * K - dev * (K - 1)) def resolve():
    S = list(input())
    K = int(input())
    l = []
    cnt = 0
    if len(S)==1:
        print(K//2)
    else:
        gr = groupby(S)
        for key, group in gr:
            l.append(list(group))
        if len(l)==1:
            print(len(S)*K//2)
        else:
            for i in range(len(l)):
                cnt += len(l[i]) // 2
                
            if l[0][0] == l[-1][0]:
                dev = len(l[0]) // 2 + len(l[-1]) // 2 - (len(l[-1]) + len(l[0])) // 2
            else:
                dev = 0
            print(cnt * K - dev * (K - 1)) resolve
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    S = list(input())
    K = int(input())
    l = []
    cnt = 0
    if len(S)==1:
        print(K//2)
    else:
        gr = groupby(S)
        for key, group in gr:
            l.append(list(group))
        if len(l)==1:
            print(len(S)*K//2)
        else:
            for i in range(len(l)):
                cnt += len(l[i]) // 2
                
            if l[0][0] == l[-1][0]:
                dev = len(l[0]) // 2 + len(l[-1]) // 2 - (len(l[-1]) + len(l[0])) // 2
            else:
                dev = 0
            print(cnt * K - dev * (K - 1))


resolve()