import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


s = S()
k = I()
counts = [1]
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        counts[-1] += 1
    else:
        counts.append(1)

# 文字が 1 種類
if len(counts) == 1:
    print(len(s) * k // 2)

else:
    ans = 0
    # 語頭と語尾が同じ文字でない
    if s[0] != s[-1]:
        for cnt in counts:
            ans += cnt // 2
        ans *= k

    # 語頭と語尾が同じ文字
    else:
        # 語頭と語尾(の連続する文字)を除いて考える
        for cnt in counts[1:-1]:
            ans += cnt // 2
        ans *= k
        # 一番初めの先頭の変換のぶんを足す
        ans += counts[0] // 2
        # 一番最後の末尾の変換のぶんを足す
        ans += counts[-1] // 2
        length = counts[0] + counts[-1]
        # k-1個あるsの境目の変換の回数
        ans += (length // 2) * (k - 1)

    print(ans) import sys sys def input(): return sys.stdin.readline().strip() input def I(): return int(input()) I def LI(): return list(map(int, input().split())) LI I() for i in range(n) for i in range(n) i range(n) range n for i in range(n) I() I def IR(n): return [I() for i in range(n)] IR n n LI() for i in range(n) for i in range(n) i range(n) range n for i in range(n) LI() LI def LIR(n): return [LI() for i in range(n)] LIR n n S() for i in range(n) for i in range(n) i range(n) range n for i in range(n) S() S def SR(n): return [S() for i in range(n)] SR n n def S(): return input() S def LS(): return input().split() LS s = S() s S() S k = I() k I() I counts = [1] counts [1] 1 for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        counts[-1] += 1
    else:
        counts.append(1)

# 文字が 1 種類 i range(1, len(s)) range 1 len(s) len s if s[i - 1] == s[i]:
        counts[-1] += 1
    else:
        counts.append(1)

# 文字が 1 種類 s[i - 1] == s[i] s[i - 1] s i - 1 i 1 s[i] s i counts[-1] += 1 counts[-1] counts -1 1 counts.append(1) counts.append counts append 1 if len(counts) == 1:
    print(len(s) * k // 2)

else:
    ans = 0
    # 語頭と語尾が同じ文字でない
    if s[0] != s[-1]:
        for cnt in counts:
            ans += cnt // 2
        ans *= k

    # 語頭と語尾が同じ文字
    else:
        # 語頭と語尾(の連続する文字)を除いて考える
        for cnt in counts[1:-1]:
            ans += cnt // 2
        ans *= k
        # 一番初めの先頭の変換のぶんを足す
        ans += counts[0] // 2
        # 一番最後の末尾の変換のぶんを足す
        ans += counts[-1] // 2
        length = counts[0] + counts[-1]
        # k-1個あるsの境目の変換の回数
        ans += (length // 2) * (k - 1)

    print(ans) len(counts) == 1 len(counts) len counts 1 print(len(s) * k // 2) print len(s) * k // 2 len(s) * k len(s) len s k 2 ans = 0 ans 0 if s[0] != s[-1]:
        for cnt in counts:
            ans += cnt // 2
        ans *= k

    # 語頭と語尾が同じ文字
    else:
        # 語頭と語尾(の連続する文字)を除いて考える
        for cnt in counts[1:-1]:
            ans += cnt // 2
        ans *= k
        # 一番初めの先頭の変換のぶんを足す
        ans += counts[0] // 2
        # 一番最後の末尾の変換のぶんを足す
        ans += counts[-1] // 2
        length = counts[0] + counts[-1]
        # k-1個あるsの境目の変換の回数
        ans += (length // 2) * (k - 1)

     s[0] != s[-1] s[0] s 0 s[-1] s -1 for cnt in counts:
            ans += cnt // 2
         cnt counts ans += cnt // 2 ans cnt // 2 cnt 2 ans *= k ans k for cnt in counts[1:-1]:
            ans += cnt // 2
         cnt counts[1:-1] counts 1:-1 1 -1 ans += cnt // 2 ans cnt // 2 cnt 2 ans *= k ans k ans += counts[0] // 2 ans counts[0] // 2 counts[0] counts 0 2 ans += counts[-1] // 2 ans counts[-1] // 2 counts[-1] counts -1 2 length = counts[0] + counts[-1] length counts[0] + counts[-1] counts[0] counts 0 counts[-1] counts -1 ans += (length // 2) * (k - 1) ans (length // 2) * (k - 1) length // 2 length 2 k - 1 k 1 print(ans) print ans s = S() S() s ans += cnt // 2 cnt // 2 ans length = counts[0] + counts[-1] counts[0] + counts[-1] length def LS(): return input().split() def LS(): return input().split() LS ans += cnt // 2 cnt // 2 ans ans += (length // 2) * (k - 1) (length // 2) * (k - 1) ans ans += counts[0] // 2 counts[0] // 2 ans counts = [1] [1] counts def IR(n): return [I() for i in range(n)] def IR(n): return [I() for i in range(n)] IR def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input ans *= k k ans def I(): return int(input()) def I(): return int(input()) I ans += counts[-1] // 2 counts[-1] // 2 ans ans *= k k ans def SR(n): return [S() for i in range(n)] def SR(n): return [S() for i in range(n)] SR def LIR(n): return [LI() for i in range(n)] def LIR(n): return [LI() for i in range(n)] LIR def S(): return input() def S(): return input() S def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI k = I() I() k ans = 0 0 ans
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


s = S()
k = I()
counts = [1]
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        counts[-1] += 1
    else:
        counts.append(1)

# 文字が 1 種類
if len(counts) == 1:
    print(len(s) * k // 2)

else:
    ans = 0
    # 語頭と語尾が同じ文字でない
    if s[0] != s[-1]:
        for cnt in counts:
            ans += cnt // 2
        ans *= k

    # 語頭と語尾が同じ文字
    else:
        # 語頭と語尾(の連続する文字)を除いて考える
        for cnt in counts[1:-1]:
            ans += cnt // 2
        ans *= k
        # 一番初めの先頭の変換のぶんを足す
        ans += counts[0] // 2
        # 一番最後の末尾の変換のぶんを足す
        ans += counts[-1] // 2
        length = counts[0] + counts[-1]
        # k-1個あるsの境目の変換の回数
        ans += (length // 2) * (k - 1)

    print(ans)
