def main():
    S = input()
    K = int(input())
    A = []
    last = S[0]
    count = 1
    for i in range(1, len(S)):
        s = S[i]
        if last == s:
            count += 1
        else:
            A.append({'key': last, 'count': count})
            count = 1
        last = s
    A.append({'key': last, 'count': count})
    # print(A)
    if len(A) == 1:
        c = A[0]['count']
        l = c*K
        ans = l//2
        print(ans)
        return
    ans = 0
    if A[0]['key'] != A[-1]['key']:
        for a in A:
            c = a['count']
            ans += (c//2) * K
        print(ans)
        return
    for i in range(1, len(A) - 1):
        a = A[i]
        c = a['count']
        ans += (c//2) * K
    a0 = A[0]
    a1 = A[-1]
    c0 = a0['count']
    c1 = a1['count']
    ans += c0//2
    ans += c1//2
    ans += ((c0 + c1)//2) * (K - 1)
    print(ans)

if __name__ == '__main__':
    main() def main():
    S = input()
    K = int(input())
    A = []
    last = S[0]
    count = 1
    for i in range(1, len(S)):
        s = S[i]
        if last == s:
            count += 1
        else:
            A.append({'key': last, 'count': count})
            count = 1
        last = s
    A.append({'key': last, 'count': count})
    # print(A)
    if len(A) == 1:
        c = A[0]['count']
        l = c*K
        ans = l//2
        print(ans)
        return
    ans = 0
    if A[0]['key'] != A[-1]['key']:
        for a in A:
            c = a['count']
            ans += (c//2) * K
        print(ans)
        return
    for i in range(1, len(A) - 1):
        a = A[i]
        c = a['count']
        ans += (c//2) * K
    a0 = A[0]
    a1 = A[-1]
    c0 = a0['count']
    c1 = a1['count']
    ans += c0//2
    ans += c1//2
    ans += ((c0 + c1)//2) * (K - 1)
    print(ans) main S = input() S input() input K = int(input()) K int(input()) int input() input A = [] A [] last = S[0] last S[0] S 0 count = 1 count 1 for i in range(1, len(S)):
        s = S[i]
        if last == s:
            count += 1
        else:
            A.append({'key': last, 'count': count})
            count = 1
        last = s
     i range(1, len(S)) range 1 len(S) len S s = S[i] s S[i] S i if last == s:
            count += 1
        else:
            A.append({'key': last, 'count': count})
            count = 1
         last == s last s count += 1 count 1 A.append({'key': last, 'count': count}) A.append A append {'key': last, 'count': count} 'key' 'key' last 'count' 'count' count count = 1 count 1 last = s last s A.append({'key': last, 'count': count}) A.append A append {'key': last, 'count': count} 'key' 'key' last 'count' 'count' count if len(A) == 1:
        c = A[0]['count']
        l = c*K
        ans = l//2
        print(ans)
        return
     len(A) == 1 len(A) len A 1 c = A[0]['count'] c A[0]['count'] [0] A 0 'count' l = c*K l c*K c K ans = l//2 ans l//2 l 2 print(ans) print ans return ans = 0 ans 0 if A[0]['key'] != A[-1]['key']:
        for a in A:
            c = a['count']
            ans += (c//2) * K
        print(ans)
        return
     A[0]['key'] != A[-1]['key'] A[0]['key'] [0] A 0 'key' A[-1]['key'] [-1] A -1 'key' for a in A:
            c = a['count']
            ans += (c//2) * K
         a A c = a['count'] c a['count'] a 'count' ans += (c//2) * K ans (c//2) * K c//2 c 2 K print(ans) print ans return for i in range(1, len(A) - 1):
        a = A[i]
        c = a['count']
        ans += (c//2) * K
     i range(1, len(A) - 1) range 1 len(A) - 1 len(A) len A 1 a = A[i] a A[i] A i c = a['count'] c a['count'] a 'count' ans += (c//2) * K ans (c//2) * K c//2 c 2 K a0 = A[0] a0 A[0] A 0 a1 = A[-1] a1 A[-1] A -1 c0 = a0['count'] c0 a0['count'] a0 'count' c1 = a1['count'] c1 a1['count'] a1 'count' ans += c0//2 ans c0//2 c0 2 ans += c1//2 ans c1//2 c1 2 ans += ((c0 + c1)//2) * (K - 1) ans ((c0 + c1)//2) * (K - 1) (c0 + c1)//2 c0 + c1 c0 c1 2 K - 1 K 1 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    S = input()
    K = int(input())
    A = []
    last = S[0]
    count = 1
    for i in range(1, len(S)):
        s = S[i]
        if last == s:
            count += 1
        else:
            A.append({'key': last, 'count': count})
            count = 1
        last = s
    A.append({'key': last, 'count': count})
    # print(A)
    if len(A) == 1:
        c = A[0]['count']
        l = c*K
        ans = l//2
        print(ans)
        return
    ans = 0
    if A[0]['key'] != A[-1]['key']:
        for a in A:
            c = a['count']
            ans += (c//2) * K
        print(ans)
        return
    for i in range(1, len(A) - 1):
        a = A[i]
        c = a['count']
        ans += (c//2) * K
    a0 = A[0]
    a1 = A[-1]
    c0 = a0['count']
    c1 = a1['count']
    ans += c0//2
    ans += c1//2
    ans += ((c0 + c1)//2) * (K - 1)
    print(ans) def main():
    S = input()
    K = int(input())
    A = []
    last = S[0]
    count = 1
    for i in range(1, len(S)):
        s = S[i]
        if last == s:
            count += 1
        else:
            A.append({'key': last, 'count': count})
            count = 1
        last = s
    A.append({'key': last, 'count': count})
    # print(A)
    if len(A) == 1:
        c = A[0]['count']
        l = c*K
        ans = l//2
        print(ans)
        return
    ans = 0
    if A[0]['key'] != A[-1]['key']:
        for a in A:
            c = a['count']
            ans += (c//2) * K
        print(ans)
        return
    for i in range(1, len(A) - 1):
        a = A[i]
        c = a['count']
        ans += (c//2) * K
    a0 = A[0]
    a1 = A[-1]
    c0 = a0['count']
    c1 = a1['count']
    ans += c0//2
    ans += c1//2
    ans += ((c0 + c1)//2) * (K - 1)
    print(ans) main
def main():
    S = input()
    K = int(input())
    A = []
    last = S[0]
    count = 1
    for i in range(1, len(S)):
        s = S[i]
        if last == s:
            count += 1
        else:
            A.append({'key': last, 'count': count})
            count = 1
        last = s
    A.append({'key': last, 'count': count})
    # print(A)
    if len(A) == 1:
        c = A[0]['count']
        l = c*K
        ans = l//2
        print(ans)
        return
    ans = 0
    if A[0]['key'] != A[-1]['key']:
        for a in A:
            c = a['count']
            ans += (c//2) * K
        print(ans)
        return
    for i in range(1, len(A) - 1):
        a = A[i]
        c = a['count']
        ans += (c//2) * K
    a0 = A[0]
    a1 = A[-1]
    c0 = a0['count']
    c1 = a1['count']
    ans += c0//2
    ans += c1//2
    ans += ((c0 + c1)//2) * (K - 1)
    print(ans)

if __name__ == '__main__':
    main()
