def calc(s):
    n = len(s)
    seq_cnt = []
    cnt, before_c = 0, s[0]
    for c in s:
        if c != before_c:
            seq_cnt.append(cnt)
            cnt = 0
            before_c = c
        cnt += 1
    seq_cnt.append(cnt)
    ret = 0
    for cnt in seq_cnt:
        ret += cnt // 2
    return ret


def main():
    S = input()
    K = int(input())
    N = len(S)
    index = N
    for i, c in enumerate(S):
        if c != S[0]:
            index = i
            break
    if index == N:
        # S consists of single kind of characters
        print(N * K // 2)
    else:
        # S consists of multiple kinds of characters
        print(calc(S[:index]) + (K - 1) * (calc(S[index:] + S[:index])) + calc(S[index:]))


if __name__ == '__main__':
    main() def calc(s):
    n = len(s)
    seq_cnt = []
    cnt, before_c = 0, s[0]
    for c in s:
        if c != before_c:
            seq_cnt.append(cnt)
            cnt = 0
            before_c = c
        cnt += 1
    seq_cnt.append(cnt)
    ret = 0
    for cnt in seq_cnt:
        ret += cnt // 2
    return ret calc n = len(s) n len(s) len s seq_cnt = [] seq_cnt [] cnt, before_c = 0, s[0] cnt 0 before_c s[0] s 0 for c in s:
        if c != before_c:
            seq_cnt.append(cnt)
            cnt = 0
            before_c = c
        cnt += 1
     c s if c != before_c:
            seq_cnt.append(cnt)
            cnt = 0
            before_c = c
         c != before_c c before_c seq_cnt.append(cnt) seq_cnt.append seq_cnt append cnt cnt = 0 cnt 0 before_c = c before_c c cnt += 1 cnt 1 seq_cnt.append(cnt) seq_cnt.append seq_cnt append cnt ret = 0 ret 0 for cnt in seq_cnt:
        ret += cnt // 2
     cnt seq_cnt ret += cnt // 2 ret cnt // 2 cnt 2 return ret ret s s def main():
    S = input()
    K = int(input())
    N = len(S)
    index = N
    for i, c in enumerate(S):
        if c != S[0]:
            index = i
            break
    if index == N:
        # S consists of single kind of characters
        print(N * K // 2)
    else:
        # S consists of multiple kinds of characters
        print(calc(S[:index]) + (K - 1) * (calc(S[index:] + S[:index])) + calc(S[index:])) main S = input() S input() input K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S index = N index N for i, c in enumerate(S):
        if c != S[0]:
            index = i
            break
     i c enumerate(S) enumerate S if c != S[0]:
            index = i
            break
     c != S[0] c S[0] S 0 index = i index i break if index == N:
        # S consists of single kind of characters
        print(N * K // 2)
    else:
        # S consists of multiple kinds of characters
        print(calc(S[:index]) + (K - 1) * (calc(S[index:] + S[:index])) + calc(S[index:])) index == N index N print(N * K // 2) print N * K // 2 N * K N K 2 print(calc(S[:index]) + (K - 1) * (calc(S[index:] + S[:index])) + calc(S[index:])) print calc(S[:index]) + (K - 1) * (calc(S[index:] + S[:index])) + calc(S[index:]) calc(S[:index]) + (K - 1) * (calc(S[index:] + S[:index])) calc(S[:index]) calc S[:index] S :index index (K - 1) * (calc(S[index:] + S[:index])) K - 1 K 1 calc(S[index:] + S[:index]) calc S[index:] + S[:index] S[index:] S index: index S[:index] S :index index calc(S[index:]) calc S[index:] S index: index if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    S = input()
    K = int(input())
    N = len(S)
    index = N
    for i, c in enumerate(S):
        if c != S[0]:
            index = i
            break
    if index == N:
        # S consists of single kind of characters
        print(N * K // 2)
    else:
        # S consists of multiple kinds of characters
        print(calc(S[:index]) + (K - 1) * (calc(S[index:] + S[:index])) + calc(S[index:])) def main():
    S = input()
    K = int(input())
    N = len(S)
    index = N
    for i, c in enumerate(S):
        if c != S[0]:
            index = i
            break
    if index == N:
        # S consists of single kind of characters
        print(N * K // 2)
    else:
        # S consists of multiple kinds of characters
        print(calc(S[:index]) + (K - 1) * (calc(S[index:] + S[:index])) + calc(S[index:])) main def calc(s):
    n = len(s)
    seq_cnt = []
    cnt, before_c = 0, s[0]
    for c in s:
        if c != before_c:
            seq_cnt.append(cnt)
            cnt = 0
            before_c = c
        cnt += 1
    seq_cnt.append(cnt)
    ret = 0
    for cnt in seq_cnt:
        ret += cnt // 2
    return ret def calc(s):
    n = len(s)
    seq_cnt = []
    cnt, before_c = 0, s[0]
    for c in s:
        if c != before_c:
            seq_cnt.append(cnt)
            cnt = 0
            before_c = c
        cnt += 1
    seq_cnt.append(cnt)
    ret = 0
    for cnt in seq_cnt:
        ret += cnt // 2
    return ret calc
def calc(s):
    n = len(s)
    seq_cnt = []
    cnt, before_c = 0, s[0]
    for c in s:
        if c != before_c:
            seq_cnt.append(cnt)
            cnt = 0
            before_c = c
        cnt += 1
    seq_cnt.append(cnt)
    ret = 0
    for cnt in seq_cnt:
        ret += cnt // 2
    return ret


def main():
    S = input()
    K = int(input())
    N = len(S)
    index = N
    for i, c in enumerate(S):
        if c != S[0]:
            index = i
            break
    if index == N:
        # S consists of single kind of characters
        print(N * K // 2)
    else:
        # S consists of multiple kinds of characters
        print(calc(S[:index]) + (K - 1) * (calc(S[index:] + S[:index])) + calc(S[index:]))


if __name__ == '__main__':
    main()