s = eval(input())

n = len(s)

k = int(eval(input()))



lis = []

b = None

cont = -1

for c in s:

    if c != b:

        if b is not None:

            lis.append(cont)

        b = c

        cont = 1

    else:

        cont += 1

if b is not None:

    lis.append(cont)



# print(lis)



if k == 1 or s[-1] != s[0]:

    print((sum([x // 2 for x in lis]) * k))

else:

    if len(lis) == 1:

        odd = lis[0] // 2

        even = ((lis[0] % 2) + lis[0]) // 2

        # print(odd, even, k // 2)

        print((even * (k // 2) + odd * (k - k // 2)))

    else:

        top = lis[0] // 2

        mid = sum([x // 2 for x in lis[1:-1]])

        bottom = lis[-1] // 2

        joint = (lis[0] + lis[-1]) // 2

        print((top + bottom + joint * (k - 1) + mid * k))

def compress(s):

    z = []

    cont = 1

    for ca, cb in zip(s, s[1:]):

        if ca == cb:

            cont += 1

        else:

            z.append(cont)

            cont = 1

    z.append(cont)

    # print(z)

    return z





def main():

    s = eval(input())

    n = len(s)

    k = int(eval(input()))



    z1 = compress(s)

    if len(z1) == 1:

        # like 'aaa'

        return n * k // 2



    k1 = sum([x // 2 for x in z1])

    if s[0] != s[-1]:

        # like 'ab'

        return k1 * k

    else:

        # like 'aba' / 'abaa'

        z2 = compress(s * 2)

        k2 = sum([x // 2 for x in z2])

        d = k2 - k1

        return k1 + d * (k - 1)





if __name__ == '__main__':

    print((main()))

s = eval(input())
n = len(s)
k = int(eval(input()))
lis = []
b = None
cont = -1
for c in s:
    if c != b:
        if b is not None:
            lis.append(cont)
        b = c
        cont = 1
    else:
        cont += 1
if b is not None:
    lis.append(cont)
# print(lis)
if k == 1 or s[-1] != s[0]:
    print((sum([x // 2 for x in lis]) * k))
else:
    if len(lis) == 1:
        odd = lis[0] // 2
        even = ((lis[0] % 2) + lis[0]) // 2
        # print(odd, even, k // 2)
        print((even * (k // 2) + odd * (k - k // 2)))
    else:
        top = lis[0] // 2
        mid = sum([x // 2 for x in lis[1:-1]])
        bottom = lis[-1] // 2
        joint = (lis[0] + lis[-1]) // 2
        print((top + bottom + joint * (k - 1) + mid * k))

def compress(s):
    z = []
    cont = 1
    for ca, cb in zip(s, s[1:]):
        if ca == cb:
            cont += 1
        else:
            z.append(cont)
            cont = 1
    z.append(cont)
    # print(z)
    return z


def main():
    s = eval(input())
    n = len(s)
    k = int(eval(input()))
    z1 = compress(s)
    if len(z1) == 1:
        # like 'aaa'
        return n * k // 2
    k1 = sum([x // 2 for x in z1])
    if s[0] != s[-1]:
        # like 'ab'
        return k1 * k
    else:
        # like 'aba' / 'abaa'
        z2 = compress(s * 2)
        k2 = sum([x // 2 for x in z2])
        d = k2 - k1
        return k1 + d * (k - 1)


if __name__ == "__main__":
    print((main()))

-s = eval(input()) -n = len(s) -k = int(eval(input())) -lis = [] -b = None -cont = -1 -for c in s: -    if c != b: -        if b is not None: -            lis.append(cont) -        b = c -        cont = 1 +def compress(s): +    z = [] +    cont = 1 +    for ca, cb in zip(s, s[1:]): +        if ca == cb: +            cont += 1 +        else: +            z.append(cont) +            cont = 1 +    z.append(cont) +    # print(z) +    return z + + +def main(): +    s = eval(input()) +    n = len(s) +    k = int(eval(input())) +    z1 = compress(s) +    if len(z1) == 1: +        # like 'aaa' +        return n * k // 2 +    k1 = sum([x // 2 for x in z1]) +    if s[0] != s[-1]: +        # like 'ab' +        return k1 * k -        cont += 1 -if b is not None: -    lis.append(cont) -# print(lis) -if k == 1 or s[-1] != s[0]: -    print((sum([x // 2 for x in lis]) * k)) -else: -    if len(lis) == 1: -        odd = lis[0] // 2 -        even = ((lis[0] % 2) + lis[0]) // 2 -        # print(odd, even, k // 2) -        print((even * (k // 2) + odd * (k - k // 2))) -    else: -        top = lis[0] // 2 -        mid = sum([x // 2 for x in lis[1:-1]]) -        bottom = lis[-1] // 2 -        joint = (lis[0] + lis[-1]) // 2 -        print((top + bottom + joint * (k - 1) + mid * k)) +        # like 'aba' / 'abaa' +        z2 = compress(s * 2) +        k2 = sum([x // 2 for x in z2]) +        d = k2 - k1 +        return k1 + d * (k - 1) + + +if __name__ == "__main__": +    print((main()))