def main():
    S = input()
    K = int(input())
    
    lengths = []
    s = S[0]
    prev = S[0]
    length = 1
    for s in S[1:]:
        if s == prev:
            length += 1
        else:
            lengths.append([prev, length])
            length = 1
        prev = s
    lengths.append([s, length])

    if len(lengths) == 1:
        ans = lengths[0][1] * K // 2
    else:
        if lengths[0][0] == lengths[-1][0]:
            joint_len = lengths[0][1] + lengths[-1][1]
            ans = lengths[0][1] // 2
            ans += sum([i[1]//2 for i in lengths[1:-1]]) * K
            ans += joint_len // 2 * (K-1)
            ans += lengths[-1][1] // 2
        else:
            ans = sum([i[1]//2 for i in lengths]) * K
    print(ans)
main() def main():
    S = input()
    K = int(input())
    
    lengths = []
    s = S[0]
    prev = S[0]
    length = 1
    for s in S[1:]:
        if s == prev:
            length += 1
        else:
            lengths.append([prev, length])
            length = 1
        prev = s
    lengths.append([s, length])

    if len(lengths) == 1:
        ans = lengths[0][1] * K // 2
    else:
        if lengths[0][0] == lengths[-1][0]:
            joint_len = lengths[0][1] + lengths[-1][1]
            ans = lengths[0][1] // 2
            ans += sum([i[1]//2 for i in lengths[1:-1]]) * K
            ans += joint_len // 2 * (K-1)
            ans += lengths[-1][1] // 2
        else:
            ans = sum([i[1]//2 for i in lengths]) * K
    print(ans) main S = input() S input() input K = int(input()) K int(input()) int input() input lengths = [] lengths [] s = S[0] s S[0] S 0 prev = S[0] prev S[0] S 0 length = 1 length 1 for s in S[1:]:
        if s == prev:
            length += 1
        else:
            lengths.append([prev, length])
            length = 1
        prev = s
     s S[1:] S 1: 1 if s == prev:
            length += 1
        else:
            lengths.append([prev, length])
            length = 1
         s == prev s prev length += 1 length 1 lengths.append([prev, length]) lengths.append lengths append [prev, length] prev length length = 1 length 1 prev = s prev s lengths.append([s, length]) lengths.append lengths append [s, length] s length if len(lengths) == 1:
        ans = lengths[0][1] * K // 2
    else:
        if lengths[0][0] == lengths[-1][0]:
            joint_len = lengths[0][1] + lengths[-1][1]
            ans = lengths[0][1] // 2
            ans += sum([i[1]//2 for i in lengths[1:-1]]) * K
            ans += joint_len // 2 * (K-1)
            ans += lengths[-1][1] // 2
        else:
            ans = sum([i[1]//2 for i in lengths]) * K
     len(lengths) == 1 len(lengths) len lengths 1 ans = lengths[0][1] * K // 2 ans lengths[0][1] * K // 2 lengths[0][1] * K lengths[0][1] [0] lengths 0 1 K 2 if lengths[0][0] == lengths[-1][0]:
            joint_len = lengths[0][1] + lengths[-1][1]
            ans = lengths[0][1] // 2
            ans += sum([i[1]//2 for i in lengths[1:-1]]) * K
            ans += joint_len // 2 * (K-1)
            ans += lengths[-1][1] // 2
        else:
            ans = sum([i[1]//2 for i in lengths]) * K
     lengths[0][0] == lengths[-1][0] lengths[0][0] [0] lengths 0 0 lengths[-1][0] [-1] lengths -1 0 joint_len = lengths[0][1] + lengths[-1][1] joint_len lengths[0][1] + lengths[-1][1] lengths[0][1] [0] lengths 0 1 lengths[-1][1] [-1] lengths -1 1 ans = lengths[0][1] // 2 ans lengths[0][1] // 2 lengths[0][1] [0] lengths 0 1 2 i[1]//2 for i in lengths[1:-1] for i in lengths[1:-1] i lengths[1:-1] lengths 1:-1 1 -1 for i in lengths[1:-1] i[1]//2 i[1] i 1 2 ans += sum([i[1]//2 for i in lengths[1:-1]]) * K ans sum([i[1]//2 for i in lengths[1:-1]]) * K sum([i[1]//2 for i in lengths[1:-1]]) sum [i[1]//2 for i in lengths[1:-1]] K ans += joint_len // 2 * (K-1) ans joint_len // 2 * (K-1) joint_len // 2 joint_len 2 K-1 K 1 ans += lengths[-1][1] // 2 ans lengths[-1][1] // 2 lengths[-1][1] [-1] lengths -1 1 2 i[1]//2 for i in lengths for i in lengths i lengths for i in lengths i[1]//2 i[1] i 1 2 ans = sum([i[1]//2 for i in lengths]) * K ans sum([i[1]//2 for i in lengths]) * K sum([i[1]//2 for i in lengths]) sum [i[1]//2 for i in lengths] K print(ans) print ans main() main def main():
    S = input()
    K = int(input())
    
    lengths = []
    s = S[0]
    prev = S[0]
    length = 1
    for s in S[1:]:
        if s == prev:
            length += 1
        else:
            lengths.append([prev, length])
            length = 1
        prev = s
    lengths.append([s, length])

    if len(lengths) == 1:
        ans = lengths[0][1] * K // 2
    else:
        if lengths[0][0] == lengths[-1][0]:
            joint_len = lengths[0][1] + lengths[-1][1]
            ans = lengths[0][1] // 2
            ans += sum([i[1]//2 for i in lengths[1:-1]]) * K
            ans += joint_len // 2 * (K-1)
            ans += lengths[-1][1] // 2
        else:
            ans = sum([i[1]//2 for i in lengths]) * K
    print(ans) def main():
    S = input()
    K = int(input())
    
    lengths = []
    s = S[0]
    prev = S[0]
    length = 1
    for s in S[1:]:
        if s == prev:
            length += 1
        else:
            lengths.append([prev, length])
            length = 1
        prev = s
    lengths.append([s, length])

    if len(lengths) == 1:
        ans = lengths[0][1] * K // 2
    else:
        if lengths[0][0] == lengths[-1][0]:
            joint_len = lengths[0][1] + lengths[-1][1]
            ans = lengths[0][1] // 2
            ans += sum([i[1]//2 for i in lengths[1:-1]]) * K
            ans += joint_len // 2 * (K-1)
            ans += lengths[-1][1] // 2
        else:
            ans = sum([i[1]//2 for i in lengths]) * K
    print(ans) main
def main():
    S = input()
    K = int(input())
    
    lengths = []
    s = S[0]
    prev = S[0]
    length = 1
    for s in S[1:]:
        if s == prev:
            length += 1
        else:
            lengths.append([prev, length])
            length = 1
        prev = s
    lengths.append([s, length])

    if len(lengths) == 1:
        ans = lengths[0][1] * K // 2
    else:
        if lengths[0][0] == lengths[-1][0]:
            joint_len = lengths[0][1] + lengths[-1][1]
            ans = lengths[0][1] // 2
            ans += sum([i[1]//2 for i in lengths[1:-1]]) * K
            ans += joint_len // 2 * (K-1)
            ans += lengths[-1][1] // 2
        else:
            ans = sum([i[1]//2 for i in lengths]) * K
    print(ans)
main()