import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy

# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    if len(set(s))==1:
        print((len(s)*k)//2)
        exit(0)

    def changer(sss):
        ts = sss.copy()
        cnt = 0
        for i in range(1, len(ts)):
            if ts[i] == ts[i - 1]:
                ts[i] = "@"
                cnt += 1

        return cnt

    print(changer(s) + (k - 1) * (changer(s + s) - changer(s)))


if __name__ == '__main__':
    main() import sys sys import re re import math math import collections collections import decimal decimal import bisect bisect import itertools itertools import copy copy INF = sys.maxsize INF sys.maxsize sys maxsize ni = lambda: int(sys.stdin.readline()) ni lambda: int(sys.stdin.readline()) int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline ns = lambda: map(int, sys.stdin.readline().split()) ns lambda: map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split na = lambda: list(map(int, sys.stdin.readline().split())) na lambda: list(map(int, sys.stdin.readline().split())) list(map(int, sys.stdin.readline().split())) list map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split def main():
    s = list(input())
    k = ni()

    if len(set(s))==1:
        print((len(s)*k)//2)
        exit(0)

    def changer(sss):
        ts = sss.copy()
        cnt = 0
        for i in range(1, len(ts)):
            if ts[i] == ts[i - 1]:
                ts[i] = "@"
                cnt += 1

        return cnt

    print(changer(s) + (k - 1) * (changer(s + s) - changer(s))) main s = list(input()) s list(input()) list input() input k = ni() k ni() ni if len(set(s))==1:
        print((len(s)*k)//2)
        exit(0)

     len(set(s))==1 len(set(s)) len set(s) set s 1 print((len(s)*k)//2) print (len(s)*k)//2 len(s)*k len(s) len s k 2 exit(0) exit 0 def changer(sss):
        ts = sss.copy()
        cnt = 0
        for i in range(1, len(ts)):
            if ts[i] == ts[i - 1]:
                ts[i] = "@"
                cnt += 1

        return cnt

     changer ts = sss.copy() ts sss.copy() sss.copy sss copy cnt = 0 cnt 0 for i in range(1, len(ts)):
            if ts[i] == ts[i - 1]:
                ts[i] = "@"
                cnt += 1

         i range(1, len(ts)) range 1 len(ts) len ts if ts[i] == ts[i - 1]:
                ts[i] = "@"
                cnt += 1

         ts[i] == ts[i - 1] ts[i] ts i ts[i - 1] ts i - 1 i 1 ts[i] = "@" ts[i] ts i "@" cnt += 1 cnt 1 return cnt cnt sss sss print(changer(s) + (k - 1) * (changer(s + s) - changer(s))) print changer(s) + (k - 1) * (changer(s + s) - changer(s)) changer(s) changer s (k - 1) * (changer(s + s) - changer(s)) k - 1 k 1 changer(s + s) - changer(s) changer(s + s) changer s + s s s changer(s) changer s if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main na = lambda: list(map(int, sys.stdin.readline().split())) lambda: list(map(int, sys.stdin.readline().split())) na INF = sys.maxsize sys.maxsize INF ns = lambda: map(int, sys.stdin.readline().split()) lambda: map(int, sys.stdin.readline().split()) ns def main():
    s = list(input())
    k = ni()

    if len(set(s))==1:
        print((len(s)*k)//2)
        exit(0)

    def changer(sss):
        ts = sss.copy()
        cnt = 0
        for i in range(1, len(ts)):
            if ts[i] == ts[i - 1]:
                ts[i] = "@"
                cnt += 1

        return cnt

    print(changer(s) + (k - 1) * (changer(s + s) - changer(s))) def main():
    s = list(input())
    k = ni()

    if len(set(s))==1:
        print((len(s)*k)//2)
        exit(0)

    def changer(sss):
        ts = sss.copy()
        cnt = 0
        for i in range(1, len(ts)):
            if ts[i] == ts[i - 1]:
                ts[i] = "@"
                cnt += 1

        return cnt

    print(changer(s) + (k - 1) * (changer(s + s) - changer(s))) main ni = lambda: int(sys.stdin.readline()) lambda: int(sys.stdin.readline()) ni
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy

# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    k = ni()

    if len(set(s))==1:
        print((len(s)*k)//2)
        exit(0)

    def changer(sss):
        ts = sss.copy()
        cnt = 0
        for i in range(1, len(ts)):
            if ts[i] == ts[i - 1]:
                ts[i] = "@"
                cnt += 1

        return cnt

    print(changer(s) + (k - 1) * (changer(s + s) - changer(s)))


if __name__ == '__main__':
    main()
