def main():
    s = input()
    k = int(input())

    count_l = []
    i = 0
    counter = 1
    while True:
        if len(s) == 1:
            count_l.append(counter)
            break
        elif s[i] == s[i+1]:
            counter += 1
        else:
            count_l.append(counter)
            counter = 1
        i += 1
        if i == len(s)-1:
            if counter == 1:
                break
            else:
                count_l.append(counter)
                break

    answer = 0
    if len(count_l) >= 3 and s[0] == s[-1] and k >= 2:
        sub_l = [count_l[0] + count_l[-1]] + count_l[1:-1]
        for i in range(len(sub_l)):
            answer += (sub_l[i] // 2) * (k - 1)
        for j in range(len(count_l[:-1])):
            answer += count_l[j] // 2
        answer += count_l[-1] // 2
    elif len(count_l) == 1:
        answer += (count_l[0] * k) // 2
    else:
        for i in range(len(count_l)):
            answer += (count_l[i] // 2) * k

    print(answer)


if __name__ == "__main__":
    main() def main():
    s = input()
    k = int(input())

    count_l = []
    i = 0
    counter = 1
    while True:
        if len(s) == 1:
            count_l.append(counter)
            break
        elif s[i] == s[i+1]:
            counter += 1
        else:
            count_l.append(counter)
            counter = 1
        i += 1
        if i == len(s)-1:
            if counter == 1:
                break
            else:
                count_l.append(counter)
                break

    answer = 0
    if len(count_l) >= 3 and s[0] == s[-1] and k >= 2:
        sub_l = [count_l[0] + count_l[-1]] + count_l[1:-1]
        for i in range(len(sub_l)):
            answer += (sub_l[i] // 2) * (k - 1)
        for j in range(len(count_l[:-1])):
            answer += count_l[j] // 2
        answer += count_l[-1] // 2
    elif len(count_l) == 1:
        answer += (count_l[0] * k) // 2
    else:
        for i in range(len(count_l)):
            answer += (count_l[i] // 2) * k

    print(answer) main s = input() s input() input k = int(input()) k int(input()) int input() input count_l = [] count_l [] i = 0 i 0 counter = 1 counter 1 while True:
        if len(s) == 1:
            count_l.append(counter)
            break
        elif s[i] == s[i+1]:
            counter += 1
        else:
            count_l.append(counter)
            counter = 1
        i += 1
        if i == len(s)-1:
            if counter == 1:
                break
            else:
                count_l.append(counter)
                break

     True if len(s) == 1:
            count_l.append(counter)
            break
        elif s[i] == s[i+1]:
            counter += 1
        else:
            count_l.append(counter)
            counter = 1
         len(s) == 1 len(s) len s 1 count_l.append(counter) count_l.append count_l append counter break elif s[i] == s[i+1]:
            counter += 1
         s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 counter += 1 counter 1 count_l.append(counter) count_l.append count_l append counter counter = 1 counter 1 i += 1 i 1 if i == len(s)-1:
            if counter == 1:
                break
            else:
                count_l.append(counter)
                break

     i == len(s)-1 i len(s)-1 len(s) len s 1 if counter == 1:
                break
            else:
                count_l.append(counter)
                break

     counter == 1 counter 1 break count_l.append(counter) count_l.append count_l append counter break answer = 0 answer 0 if len(count_l) >= 3 and s[0] == s[-1] and k >= 2:
        sub_l = [count_l[0] + count_l[-1]] + count_l[1:-1]
        for i in range(len(sub_l)):
            answer += (sub_l[i] // 2) * (k - 1)
        for j in range(len(count_l[:-1])):
            answer += count_l[j] // 2
        answer += count_l[-1] // 2
    elif len(count_l) == 1:
        answer += (count_l[0] * k) // 2
    else:
        for i in range(len(count_l)):
            answer += (count_l[i] // 2) * k

     len(count_l) >= 3 and s[0] == s[-1] and k >= 2 len(count_l) >= 3 and s[0] == s[-1] len(count_l) >= 3 len(count_l) len count_l 3 s[0] == s[-1] s[0] s 0 s[-1] s -1 k >= 2 k 2 sub_l = [count_l[0] + count_l[-1]] + count_l[1:-1] sub_l [count_l[0] + count_l[-1]] + count_l[1:-1] [count_l[0] + count_l[-1]] count_l[0] + count_l[-1] count_l[0] count_l 0 count_l[-1] count_l -1 count_l[1:-1] count_l 1:-1 1 -1 for i in range(len(sub_l)):
            answer += (sub_l[i] // 2) * (k - 1)
         i range(len(sub_l)) range len(sub_l) len sub_l answer += (sub_l[i] // 2) * (k - 1) answer (sub_l[i] // 2) * (k - 1) sub_l[i] // 2 sub_l[i] sub_l i 2 k - 1 k 1 for j in range(len(count_l[:-1])):
            answer += count_l[j] // 2
         j range(len(count_l[:-1])) range len(count_l[:-1]) len count_l[:-1] count_l :-1 -1 answer += count_l[j] // 2 answer count_l[j] // 2 count_l[j] count_l j 2 answer += count_l[-1] // 2 answer count_l[-1] // 2 count_l[-1] count_l -1 2 elif len(count_l) == 1:
        answer += (count_l[0] * k) // 2
     len(count_l) == 1 len(count_l) len count_l 1 answer += (count_l[0] * k) // 2 answer (count_l[0] * k) // 2 count_l[0] * k count_l[0] count_l 0 k 2 for i in range(len(count_l)):
            answer += (count_l[i] // 2) * k

     i range(len(count_l)) range len(count_l) len count_l answer += (count_l[i] // 2) * k answer (count_l[i] // 2) * k count_l[i] // 2 count_l[i] count_l i 2 k print(answer) print answer if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    s = input()
    k = int(input())

    count_l = []
    i = 0
    counter = 1
    while True:
        if len(s) == 1:
            count_l.append(counter)
            break
        elif s[i] == s[i+1]:
            counter += 1
        else:
            count_l.append(counter)
            counter = 1
        i += 1
        if i == len(s)-1:
            if counter == 1:
                break
            else:
                count_l.append(counter)
                break

    answer = 0
    if len(count_l) >= 3 and s[0] == s[-1] and k >= 2:
        sub_l = [count_l[0] + count_l[-1]] + count_l[1:-1]
        for i in range(len(sub_l)):
            answer += (sub_l[i] // 2) * (k - 1)
        for j in range(len(count_l[:-1])):
            answer += count_l[j] // 2
        answer += count_l[-1] // 2
    elif len(count_l) == 1:
        answer += (count_l[0] * k) // 2
    else:
        for i in range(len(count_l)):
            answer += (count_l[i] // 2) * k

    print(answer) def main():
    s = input()
    k = int(input())

    count_l = []
    i = 0
    counter = 1
    while True:
        if len(s) == 1:
            count_l.append(counter)
            break
        elif s[i] == s[i+1]:
            counter += 1
        else:
            count_l.append(counter)
            counter = 1
        i += 1
        if i == len(s)-1:
            if counter == 1:
                break
            else:
                count_l.append(counter)
                break

    answer = 0
    if len(count_l) >= 3 and s[0] == s[-1] and k >= 2:
        sub_l = [count_l[0] + count_l[-1]] + count_l[1:-1]
        for i in range(len(sub_l)):
            answer += (sub_l[i] // 2) * (k - 1)
        for j in range(len(count_l[:-1])):
            answer += count_l[j] // 2
        answer += count_l[-1] // 2
    elif len(count_l) == 1:
        answer += (count_l[0] * k) // 2
    else:
        for i in range(len(count_l)):
            answer += (count_l[i] // 2) * k

    print(answer) main
def main():
    s = input()
    k = int(input())

    count_l = []
    i = 0
    counter = 1
    while True:
        if len(s) == 1:
            count_l.append(counter)
            break
        elif s[i] == s[i+1]:
            counter += 1
        else:
            count_l.append(counter)
            counter = 1
        i += 1
        if i == len(s)-1:
            if counter == 1:
                break
            else:
                count_l.append(counter)
                break

    answer = 0
    if len(count_l) >= 3 and s[0] == s[-1] and k >= 2:
        sub_l = [count_l[0] + count_l[-1]] + count_l[1:-1]
        for i in range(len(sub_l)):
            answer += (sub_l[i] // 2) * (k - 1)
        for j in range(len(count_l[:-1])):
            answer += count_l[j] // 2
        answer += count_l[-1] // 2
    elif len(count_l) == 1:
        answer += (count_l[0] * k) // 2
    else:
        for i in range(len(count_l)):
            answer += (count_l[i] // 2) * k

    print(answer)


if __name__ == "__main__":
    main()
