import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *


S = list(input())
K = INT()

if len(Counter(S).values()) == 1:
	print(len(S)*K//2)
	exit()

S_one = S.copy()
S_two = S*2

inner = 0
outer = 0

tmp = ""
for i, s in enumerate(S_one):
	if tmp == s:
		S_one[i] ="_"
		inner += 1
		tmp = ""
	else:
		tmp = s

tmp = ""
for i, s in enumerate(S_two):
	if tmp == s:
		S_two[i] = "_"
		outer += 1
		tmp = ""
	else:
		tmp = s

outer -= inner
print(inner+outer*(K-1)) import sys, re sys re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() input def INT(): return int(input()) INT def MAP(): return map(int, input().split()) MAP def LIST(): return list(map(int, input().split())) LIST MAP() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) MAP() MAP def ZIP(n): return zip(*(MAP() for _ in range(n))) ZIP n n sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = float('inf') INF float('inf') float 'inf' mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 S = list(input()) S list(input()) list input() input K = INT() K INT() INT if len(Counter(S).values()) == 1:
	print(len(S)*K//2)
	exit() len(Counter(S).values()) == 1 len(Counter(S).values()) len Counter(S).values() (S).values (S) Counter S values 1 print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 exit() exit S_one = S.copy() S_one S.copy() S.copy S copy S_two = S*2 S_two S*2 S 2 inner = 0 inner 0 outer = 0 outer 0 tmp = "" tmp "" for i, s in enumerate(S_one):
	if tmp == s:
		S_one[i] ="_"
		inner += 1
		tmp = ""
	else:
		tmp = s i s enumerate(S_one) enumerate S_one if tmp == s:
		S_one[i] ="_"
		inner += 1
		tmp = ""
	else:
		tmp = s tmp == s tmp s S_one[i] ="_" S_one[i] S_one i "_" inner += 1 inner 1 tmp = "" tmp "" tmp = s tmp s tmp = "" tmp "" for i, s in enumerate(S_two):
	if tmp == s:
		S_two[i] = "_"
		outer += 1
		tmp = ""
	else:
		tmp = s i s enumerate(S_two) enumerate S_two if tmp == s:
		S_two[i] = "_"
		outer += 1
		tmp = ""
	else:
		tmp = s tmp == s tmp s S_two[i] = "_" S_two[i] S_two i "_" outer += 1 outer 1 tmp = "" tmp "" tmp = s tmp s outer -= inner outer inner print(inner+outer*(K-1)) print inner+outer*(K-1) inner outer*(K-1) outer K-1 K 1 inner += 1 1 inner K = INT() INT() K tmp = s s tmp tmp = "" "" tmp tmp = s s tmp outer -= inner inner outer S_two = S*2 S*2 S_two mod = 10**9 + 7 10**9 + 7 mod S_one = S.copy() S.copy() S_one S = list(input()) list(input()) S def INT(): return int(input()) def INT(): return int(input()) INT tmp = "" "" tmp def LIST(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) LIST INF = float('inf') float('inf') INF def ZIP(n): return zip(*(MAP() for _ in range(n))) def ZIP(n): return zip(*(MAP() for _ in range(n))) ZIP tmp = "" "" tmp inner = 0 0 inner def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP tmp = "" "" tmp outer += 1 1 outer def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input outer = 0 0 outer
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *


S = list(input())
K = INT()

if len(Counter(S).values()) == 1:
	print(len(S)*K//2)
	exit()

S_one = S.copy()
S_two = S*2

inner = 0
outer = 0

tmp = ""
for i, s in enumerate(S_one):
	if tmp == s:
		S_one[i] ="_"
		inner += 1
		tmp = ""
	else:
		tmp = s

tmp = ""
for i, s in enumerate(S_two):
	if tmp == s:
		S_two[i] = "_"
		outer += 1
		tmp = ""
	else:
		tmp = s

outer -= inner
print(inner+outer*(K-1))