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

    if len(set(s)) == 1:
        print(len(s)*k//2)
    else:
        s1 = list(s)
        s2 = list(s + s)

        c1, c2 = 0, 0
        for i in range(len(s1) - 1):
            if s1[i] == s1[i + 1]:
                    c1 += 1
                    s1[i + 1] = "-"

        for i in range(len(s2) - 1):
            if s2[i] == s2[i + 1]:
                    c2 += 1
                    s2[i + 1] = "-"

        d = c2 - c1
        print(c1 + (k - 1) * d)

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

    if len(set(s)) == 1:
        print(len(s)*k//2)
    else:
        s1 = list(s)
        s2 = list(s + s)

        c1, c2 = 0, 0
        for i in range(len(s1) - 1):
            if s1[i] == s1[i + 1]:
                    c1 += 1
                    s1[i + 1] = "-"

        for i in range(len(s2) - 1):
            if s2[i] == s2[i + 1]:
                    c2 += 1
                    s2[i + 1] = "-"

        d = c2 - c1
        print(c1 + (k - 1) * d) main3 s = input() s input() input k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
        print(len(s)*k//2)
    else:
        s1 = list(s)
        s2 = list(s + s)

        c1, c2 = 0, 0
        for i in range(len(s1) - 1):
            if s1[i] == s1[i + 1]:
                    c1 += 1
                    s1[i + 1] = "-"

        for i in range(len(s2) - 1):
            if s2[i] == s2[i + 1]:
                    c2 += 1
                    s2[i + 1] = "-"

        d = c2 - c1
        print(c1 + (k - 1) * d) len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(len(s)*k//2) print len(s)*k//2 len(s)*k len(s) len s k 2 s1 = list(s) s1 list(s) list s s2 = list(s + s) s2 list(s + s) list s + s s s c1, c2 = 0, 0 c1 0 c2 0 for i in range(len(s1) - 1):
            if s1[i] == s1[i + 1]:
                    c1 += 1
                    s1[i + 1] = "-"

         i range(len(s1) - 1) range len(s1) - 1 len(s1) len s1 1 if s1[i] == s1[i + 1]:
                    c1 += 1
                    s1[i + 1] = "-"

         s1[i] == s1[i + 1] s1[i] s1 i s1[i + 1] s1 i + 1 i 1 c1 += 1 c1 1 s1[i + 1] = "-" s1[i + 1] s1 i + 1 i 1 "-" for i in range(len(s2) - 1):
            if s2[i] == s2[i + 1]:
                    c2 += 1
                    s2[i + 1] = "-"

         i range(len(s2) - 1) range len(s2) - 1 len(s2) len s2 1 if s2[i] == s2[i + 1]:
                    c2 += 1
                    s2[i + 1] = "-"

         s2[i] == s2[i + 1] s2[i] s2 i s2[i + 1] s2 i + 1 i 1 c2 += 1 c2 1 s2[i + 1] = "-" s2[i + 1] s2 i + 1 i 1 "-" d = c2 - c1 d c2 - c1 c2 c1 print(c1 + (k - 1) * d) print c1 + (k - 1) * d c1 (k - 1) * d k - 1 k 1 d if __name__ == "__main__":
    main3() __name__ == "__main__" __name__ "__main__" main3() main3 def main3():
    s = input()
    k = int(input())

    if len(set(s)) == 1:
        print(len(s)*k//2)
    else:
        s1 = list(s)
        s2 = list(s + s)

        c1, c2 = 0, 0
        for i in range(len(s1) - 1):
            if s1[i] == s1[i + 1]:
                    c1 += 1
                    s1[i + 1] = "-"

        for i in range(len(s2) - 1):
            if s2[i] == s2[i + 1]:
                    c2 += 1
                    s2[i + 1] = "-"

        d = c2 - c1
        print(c1 + (k - 1) * d) def main3():
    s = input()
    k = int(input())

    if len(set(s)) == 1:
        print(len(s)*k//2)
    else:
        s1 = list(s)
        s2 = list(s + s)

        c1, c2 = 0, 0
        for i in range(len(s1) - 1):
            if s1[i] == s1[i + 1]:
                    c1 += 1
                    s1[i + 1] = "-"

        for i in range(len(s2) - 1):
            if s2[i] == s2[i + 1]:
                    c2 += 1
                    s2[i + 1] = "-"

        d = c2 - c1
        print(c1 + (k - 1) * d) main3
def main3():
    s = input()
    k = int(input())

    if len(set(s)) == 1:
        print(len(s)*k//2)
    else:
        s1 = list(s)
        s2 = list(s + s)

        c1, c2 = 0, 0
        for i in range(len(s1) - 1):
            if s1[i] == s1[i + 1]:
                    c1 += 1
                    s1[i + 1] = "-"

        for i in range(len(s2) - 1):
            if s2[i] == s2[i + 1]:
                    c2 += 1
                    s2[i + 1] = "-"

        d = c2 - c1
        print(c1 + (k - 1) * d)

if __name__ == "__main__":
    main3()