from math import floor



def solve(s, k):

    counts = [0] * len(s)

    prev = ''

    index = -1

    for l in s:

        if prev == l:

            counts[index] += 1

        else:

            index += 1

            counts[index] = 1

        prev = l

    if index == 0:

        return floor(len(s) * k / 2)

    total = 0

    for i in range(index + 1):

        if counts[i] > 1:

            total += floor(counts[i] / 2) * k

    if s[0] == s[-1] and counts[0] % 2 == 1 and counts[index] % 2 == 1:

        if (counts[0] + counts[index]) % 2 == 0:

            total += k - 1

    return total



_s = eval(input())

_k = int(eval(input()))

print((solve(_s, _k)))

from math import floor



def solve(s, k):

    counts = [0] * len(s)

    prev = ''

    index = -1

    for l in s:

        if prev == l:

            counts[index] += 1

        else:

            index += 1

            counts[index] = 1

        prev = l

    if index == 0:

        return floor(len(s) * k / 2)

    total = sum(floor(counts[i] / 2) * k for i in range(index + 1) if counts[i] > 1)

    if s[0] == s[-1] and counts[0] % 2 == 1 and counts[index] % 2 == 1:

        total += k - 1

    return total



_s = eval(input())

_k = int(eval(input()))

print((solve(_s, _k)))

from math import floor


def solve(s, k):
    counts = [0] * len(s)
    prev = ""
    index = -1
    for l in s:
        if prev == l:
            counts[index] += 1
        else:
            index += 1
            counts[index] = 1
        prev = l
    if index == 0:
        return floor(len(s) * k / 2)
    total = 0
    for i in range(index + 1):
        if counts[i] > 1:
            total += floor(counts[i] / 2) * k
    if s[0] == s[-1] and counts[0] % 2 == 1 and counts[index] % 2 == 1:
        if (counts[0] + counts[index]) % 2 == 0:
            total += k - 1
    return total


_s = eval(input())
_k = int(eval(input()))
print((solve(_s, _k)))

from math import floor


def solve(s, k):
    counts = [0] * len(s)
    prev = ""
    index = -1
    for l in s:
        if prev == l:
            counts[index] += 1
        else:
            index += 1
            counts[index] = 1
        prev = l
    if index == 0:
        return floor(len(s) * k / 2)
    total = sum(floor(counts[i] / 2) * k for i in range(index + 1) if counts[i] > 1)
    if s[0] == s[-1] and counts[0] % 2 == 1 and counts[index] % 2 == 1:
        total += k - 1
    return total


_s = eval(input())
_k = int(eval(input()))
print((solve(_s, _k)))

-    total = 0 -    for i in range(index + 1): -        if counts[i] > 1: -            total += floor(counts[i] / 2) * k +    total = sum(floor(counts[i] / 2) * k for i in range(index + 1) if counts[i] > 1) -        if (counts[0] + counts[index]) % 2 == 0: -            total += k - 1 +        total += k - 1