#! /usr/bin/env python3

import sys
import numpy as np
from itertools import groupby
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = list(readline().decode().rstrip())
K = int(readline())

g = [len(list(g)) for _, g in groupby(S)]

if len(g) == 1:
    print(len(S) * K // 2)
else:
    acc = sum(l // 2 for l in g) * K
    if S[0] == S[-1] and g[0] % 2 == 1 and g[-1] % 2 == 1:
        acc += K - 1
    print(acc) import sys sys import numpy as np numpy from itertools import groupby int1 = lambda x: int(x) - 1 int1 lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines sys.setrecursionlimit(500000) sys.setrecursionlimit sys setrecursionlimit 500000 S = list(readline().decode().rstrip()) S list(readline().decode().rstrip()) list readline().decode().rstrip() ().decode().rstrip ().decode() ().decode () readline decode rstrip K = int(readline()) K int(readline()) int readline() readline len(list(g)) for _, g in groupby(S) for _, g in groupby(S) _ g groupby(S) groupby S for _, g in groupby(S) len(list(g)) len list(g) list g g = [len(list(g)) for _, g in groupby(S)] g [len(list(g)) for _, g in groupby(S)] if len(g) == 1:
    print(len(S) * K // 2)
else:
    acc = sum(l // 2 for l in g) * K
    if S[0] == S[-1] and g[0] % 2 == 1 and g[-1] % 2 == 1:
        acc += K - 1
    print(acc) len(g) == 1 len(g) len g 1 print(len(S) * K // 2) print len(S) * K // 2 len(S) * K len(S) len S K 2 acc = sum(l // 2 for l in g) * K acc sum(l // 2 for l in g) * K sum(l // 2 for l in g) sum l // 2 l 2 K if S[0] == S[-1] and g[0] % 2 == 1 and g[-1] % 2 == 1:
        acc += K - 1
     S[0] == S[-1] and g[0] % 2 == 1 and g[-1] % 2 == 1 S[0] == S[-1] and g[0] % 2 == 1 S[0] == S[-1] S[0] S 0 S[-1] S -1 g[0] % 2 == 1 g[0] % 2 g[0] g 0 2 1 g[-1] % 2 == 1 g[-1] % 2 g[-1] g -1 2 1 acc += K - 1 acc K - 1 K 1 print(acc) print acc int1 = lambda x: int(x) - 1 lambda x: int(x) - 1 int1 acc = sum(l // 2 for l in g) * K sum(l // 2 for l in g) * K acc K = int(readline()) int(readline()) K acc += K - 1 K - 1 acc g = [len(list(g)) for _, g in groupby(S)] [len(list(g)) for _, g in groupby(S)] g read = sys.stdin.buffer.read sys.stdin.buffer.read read S = list(readline().decode().rstrip()) list(readline().decode().rstrip()) S readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines
#! /usr/bin/env python3

import sys
import numpy as np
from itertools import groupby
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = list(readline().decode().rstrip())
K = int(readline())

g = [len(list(g)) for _, g in groupby(S)]

if len(g) == 1:
    print(len(S) * K // 2)
else:
    acc = sum(l // 2 for l in g) * K
    if S[0] == S[-1] and g[0] % 2 == 1 and g[-1] % 2 == 1:
        acc += K - 1
    print(acc)
