def find_operation_num(word):
    count = 1
    before = word[0]
    result = 0
    for w in word[1:] + " ":
        if before == w:
            count += 1
        else:
            before = w
            result += count // 2
            count = 1
    return result


def main():
    # 等差数列を利用する
    word = input()
    repeat = int(input())
    answer = 0
    if len(set(list(word))) == 1:
        answer = len(word) * repeat // 2
    else:
        count = [find_operation_num(word * i) for i in range(1, 3)]
        answer = count[0] + (repeat - 1) * (count[1] - count[0])
    print(answer)


if __name__ == '__main__':
    main()
 def find_operation_num(word):
    count = 1
    before = word[0]
    result = 0
    for w in word[1:] + " ":
        if before == w:
            count += 1
        else:
            before = w
            result += count // 2
            count = 1
    return result find_operation_num count = 1 count 1 before = word[0] before word[0] word 0 result = 0 result 0 for w in word[1:] + " ":
        if before == w:
            count += 1
        else:
            before = w
            result += count // 2
            count = 1
     w word[1:] + " " word[1:] word 1: 1 " " if before == w:
            count += 1
        else:
            before = w
            result += count // 2
            count = 1
     before == w before w count += 1 count 1 before = w before w result += count // 2 result count // 2 count 2 count = 1 count 1 return result result word word def main():
    # 等差数列を利用する
    word = input()
    repeat = int(input())
    answer = 0
    if len(set(list(word))) == 1:
        answer = len(word) * repeat // 2
    else:
        count = [find_operation_num(word * i) for i in range(1, 3)]
        answer = count[0] + (repeat - 1) * (count[1] - count[0])
    print(answer) main word = input() word input() input repeat = int(input()) repeat int(input()) int input() input answer = 0 answer 0 if len(set(list(word))) == 1:
        answer = len(word) * repeat // 2
    else:
        count = [find_operation_num(word * i) for i in range(1, 3)]
        answer = count[0] + (repeat - 1) * (count[1] - count[0])
     len(set(list(word))) == 1 len(set(list(word))) len set(list(word)) set list(word) list word 1 answer = len(word) * repeat // 2 answer len(word) * repeat // 2 len(word) * repeat len(word) len word repeat 2 find_operation_num(word * i) for i in range(1, 3) for i in range(1, 3) i range(1, 3) range 1 3 for i in range(1, 3) find_operation_num(word * i) find_operation_num word * i word i count = [find_operation_num(word * i) for i in range(1, 3)] count [find_operation_num(word * i) for i in range(1, 3)] answer = count[0] + (repeat - 1) * (count[1] - count[0]) answer count[0] + (repeat - 1) * (count[1] - count[0]) count[0] count 0 (repeat - 1) * (count[1] - count[0]) repeat - 1 repeat 1 count[1] - count[0] count[1] count 1 count[0] count 0 print(answer) print answer if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    # 等差数列を利用する
    word = input()
    repeat = int(input())
    answer = 0
    if len(set(list(word))) == 1:
        answer = len(word) * repeat // 2
    else:
        count = [find_operation_num(word * i) for i in range(1, 3)]
        answer = count[0] + (repeat - 1) * (count[1] - count[0])
    print(answer) def main():
    # 等差数列を利用する
    word = input()
    repeat = int(input())
    answer = 0
    if len(set(list(word))) == 1:
        answer = len(word) * repeat // 2
    else:
        count = [find_operation_num(word * i) for i in range(1, 3)]
        answer = count[0] + (repeat - 1) * (count[1] - count[0])
    print(answer) main def find_operation_num(word):
    count = 1
    before = word[0]
    result = 0
    for w in word[1:] + " ":
        if before == w:
            count += 1
        else:
            before = w
            result += count // 2
            count = 1
    return result def find_operation_num(word):
    count = 1
    before = word[0]
    result = 0
    for w in word[1:] + " ":
        if before == w:
            count += 1
        else:
            before = w
            result += count // 2
            count = 1
    return result find_operation_num
def find_operation_num(word):
    count = 1
    before = word[0]
    result = 0
    for w in word[1:] + " ":
        if before == w:
            count += 1
        else:
            before = w
            result += count // 2
            count = 1
    return result


def main():
    # 等差数列を利用する
    word = input()
    repeat = int(input())
    answer = 0
    if len(set(list(word))) == 1:
        answer = len(word) * repeat // 2
    else:
        count = [find_operation_num(word * i) for i in range(1, 3)]
        answer = count[0] + (repeat - 1) * (count[1] - count[0])
    print(answer)


if __name__ == '__main__':
    main()

