def main():
    word = input()
    repeat = int(input())
    count_succession = 1
    before = word[0]
    base = 0
    for w in word[1:] + " ":
        if before == w:
            count_succession += 1
        else:
            before = w
            base += count_succession // 2
            count_succession = 1
    answer = repeat * base
    if len(set(list(word))) == 1:
        answer = repeat * len(word) // 2
    elif word[-1] == word[0]:
        succession_begin = 0
        succession_end = 0
        for i in range(1, len(word)):
            if word[i] != word[0]:
                succession_begin = i
                break
        for i in range(-2, -len(word) - 1, -1):
            if word[i] != word[-1]:
                succession_end = -i - 1
                break
        answer -= (succession_begin // 2 + succession_end // 2 - (succession_begin + succession_end) // 2) * (repeat - 1)
    print(answer)


if __name__ == '__main__':
    main()
 def main():
    word = input()
    repeat = int(input())
    count_succession = 1
    before = word[0]
    base = 0
    for w in word[1:] + " ":
        if before == w:
            count_succession += 1
        else:
            before = w
            base += count_succession // 2
            count_succession = 1
    answer = repeat * base
    if len(set(list(word))) == 1:
        answer = repeat * len(word) // 2
    elif word[-1] == word[0]:
        succession_begin = 0
        succession_end = 0
        for i in range(1, len(word)):
            if word[i] != word[0]:
                succession_begin = i
                break
        for i in range(-2, -len(word) - 1, -1):
            if word[i] != word[-1]:
                succession_end = -i - 1
                break
        answer -= (succession_begin // 2 + succession_end // 2 - (succession_begin + succession_end) // 2) * (repeat - 1)
    print(answer) main word = input() word input() input repeat = int(input()) repeat int(input()) int input() input count_succession = 1 count_succession 1 before = word[0] before word[0] word 0 base = 0 base 0 for w in word[1:] + " ":
        if before == w:
            count_succession += 1
        else:
            before = w
            base += count_succession // 2
            count_succession = 1
     w word[1:] + " " word[1:] word 1: 1 " " if before == w:
            count_succession += 1
        else:
            before = w
            base += count_succession // 2
            count_succession = 1
     before == w before w count_succession += 1 count_succession 1 before = w before w base += count_succession // 2 base count_succession // 2 count_succession 2 count_succession = 1 count_succession 1 answer = repeat * base answer repeat * base repeat base if len(set(list(word))) == 1:
        answer = repeat * len(word) // 2
    elif word[-1] == word[0]:
        succession_begin = 0
        succession_end = 0
        for i in range(1, len(word)):
            if word[i] != word[0]:
                succession_begin = i
                break
        for i in range(-2, -len(word) - 1, -1):
            if word[i] != word[-1]:
                succession_end = -i - 1
                break
        answer -= (succession_begin // 2 + succession_end // 2 - (succession_begin + succession_end) // 2) * (repeat - 1)
     len(set(list(word))) == 1 len(set(list(word))) len set(list(word)) set list(word) list word 1 answer = repeat * len(word) // 2 answer repeat * len(word) // 2 repeat * len(word) repeat len(word) len word 2 elif word[-1] == word[0]:
        succession_begin = 0
        succession_end = 0
        for i in range(1, len(word)):
            if word[i] != word[0]:
                succession_begin = i
                break
        for i in range(-2, -len(word) - 1, -1):
            if word[i] != word[-1]:
                succession_end = -i - 1
                break
        answer -= (succession_begin // 2 + succession_end // 2 - (succession_begin + succession_end) // 2) * (repeat - 1)
     word[-1] == word[0] word[-1] word -1 word[0] word 0 succession_begin = 0 succession_begin 0 succession_end = 0 succession_end 0 for i in range(1, len(word)):
            if word[i] != word[0]:
                succession_begin = i
                break
         i range(1, len(word)) range 1 len(word) len word if word[i] != word[0]:
                succession_begin = i
                break
         word[i] != word[0] word[i] word i word[0] word 0 succession_begin = i succession_begin i break for i in range(-2, -len(word) - 1, -1):
            if word[i] != word[-1]:
                succession_end = -i - 1
                break
         i range(-2, -len(word) - 1, -1) range -2 -len(word) - 1 -len(word) len(word) len word 1 -1 if word[i] != word[-1]:
                succession_end = -i - 1
                break
         word[i] != word[-1] word[i] word i word[-1] word -1 succession_end = -i - 1 succession_end -i - 1 -i i 1 break answer -= (succession_begin // 2 + succession_end // 2 - (succession_begin + succession_end) // 2) * (repeat - 1) answer (succession_begin // 2 + succession_end // 2 - (succession_begin + succession_end) // 2) * (repeat - 1) succession_begin // 2 + succession_end // 2 - (succession_begin + succession_end) // 2 succession_begin // 2 + succession_end // 2 succession_begin // 2 succession_begin 2 succession_end // 2 succession_end 2 (succession_begin + succession_end) // 2 succession_begin + succession_end succession_begin succession_end 2 repeat - 1 repeat 1 print(answer) print answer if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    word = input()
    repeat = int(input())
    count_succession = 1
    before = word[0]
    base = 0
    for w in word[1:] + " ":
        if before == w:
            count_succession += 1
        else:
            before = w
            base += count_succession // 2
            count_succession = 1
    answer = repeat * base
    if len(set(list(word))) == 1:
        answer = repeat * len(word) // 2
    elif word[-1] == word[0]:
        succession_begin = 0
        succession_end = 0
        for i in range(1, len(word)):
            if word[i] != word[0]:
                succession_begin = i
                break
        for i in range(-2, -len(word) - 1, -1):
            if word[i] != word[-1]:
                succession_end = -i - 1
                break
        answer -= (succession_begin // 2 + succession_end // 2 - (succession_begin + succession_end) // 2) * (repeat - 1)
    print(answer) def main():
    word = input()
    repeat = int(input())
    count_succession = 1
    before = word[0]
    base = 0
    for w in word[1:] + " ":
        if before == w:
            count_succession += 1
        else:
            before = w
            base += count_succession // 2
            count_succession = 1
    answer = repeat * base
    if len(set(list(word))) == 1:
        answer = repeat * len(word) // 2
    elif word[-1] == word[0]:
        succession_begin = 0
        succession_end = 0
        for i in range(1, len(word)):
            if word[i] != word[0]:
                succession_begin = i
                break
        for i in range(-2, -len(word) - 1, -1):
            if word[i] != word[-1]:
                succession_end = -i - 1
                break
        answer -= (succession_begin // 2 + succession_end // 2 - (succession_begin + succession_end) // 2) * (repeat - 1)
    print(answer) main
def main():
    word = input()
    repeat = int(input())
    count_succession = 1
    before = word[0]
    base = 0
    for w in word[1:] + " ":
        if before == w:
            count_succession += 1
        else:
            before = w
            base += count_succession // 2
            count_succession = 1
    answer = repeat * base
    if len(set(list(word))) == 1:
        answer = repeat * len(word) // 2
    elif word[-1] == word[0]:
        succession_begin = 0
        succession_end = 0
        for i in range(1, len(word)):
            if word[i] != word[0]:
                succession_begin = i
                break
        for i in range(-2, -len(word) - 1, -1):
            if word[i] != word[-1]:
                succession_end = -i - 1
                break
        answer -= (succession_begin // 2 + succession_end // 2 - (succession_begin + succession_end) // 2) * (repeat - 1)
    print(answer)


if __name__ == '__main__':
    main()

