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 = input()
K = INT()

cnt = 0
tmp = False
for i in range(1, len(S)):
	if tmp:
		tmp = False
	elif S[i] == S[i-1]:
		cnt += 1
		tmp = True

if tmp or S[0] != S[-1]:
	print(cnt*K)
	exit()

cnt2 = 1
tmp = True
for i in range(1, len(S)):
	if tmp:
		tmp = False
	elif S[i] == S[i-1]:
		cnt2 += 1
		tmp = True

if tmp:
	print((cnt+cnt2)*(K//2) + cnt*(K%2))
else:
	print(cnt+cnt2*(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 = input() S input() input K = INT() K INT() INT cnt = 0 cnt 0 tmp = False tmp False for i in range(1, len(S)):
	if tmp:
		tmp = False
	elif S[i] == S[i-1]:
		cnt += 1
		tmp = True i range(1, len(S)) range 1 len(S) len S if tmp:
		tmp = False
	elif S[i] == S[i-1]:
		cnt += 1
		tmp = True tmp tmp = False tmp False elif S[i] == S[i-1]:
		cnt += 1
		tmp = True S[i] == S[i-1] S[i] S i S[i-1] S i-1 i 1 cnt += 1 cnt 1 tmp = True tmp True if tmp or S[0] != S[-1]:
	print(cnt*K)
	exit() tmp or S[0] != S[-1] tmp S[0] != S[-1] S[0] S 0 S[-1] S -1 print(cnt*K) print cnt*K cnt K exit() exit cnt2 = 1 cnt2 1 tmp = True tmp True for i in range(1, len(S)):
	if tmp:
		tmp = False
	elif S[i] == S[i-1]:
		cnt2 += 1
		tmp = True i range(1, len(S)) range 1 len(S) len S if tmp:
		tmp = False
	elif S[i] == S[i-1]:
		cnt2 += 1
		tmp = True tmp tmp = False tmp False elif S[i] == S[i-1]:
		cnt2 += 1
		tmp = True S[i] == S[i-1] S[i] S i S[i-1] S i-1 i 1 cnt2 += 1 cnt2 1 tmp = True tmp True if tmp:
	print((cnt+cnt2)*(K//2) + cnt*(K%2))
else:
	print(cnt+cnt2*(K-1)) tmp print((cnt+cnt2)*(K//2) + cnt*(K%2)) print (cnt+cnt2)*(K//2) + cnt*(K%2) (cnt+cnt2)*(K//2) cnt+cnt2 cnt cnt2 K//2 K 2 cnt*(K%2) cnt K%2 K 2 print(cnt+cnt2*(K-1)) print cnt+cnt2*(K-1) cnt cnt2*(K-1) cnt2 K-1 K 1 def INT(): return int(input()) def INT(): return int(input()) INT tmp = True True tmp tmp = False False tmp tmp = True True tmp S = input() input() S K = INT() INT() K def LIST(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) LIST tmp = False False tmp def ZIP(n): return zip(*(MAP() for _ in range(n))) def ZIP(n): return zip(*(MAP() for _ in range(n))) ZIP cnt += 1 1 cnt INF = float('inf') float('inf') INF cnt2 += 1 1 cnt2 mod = 10**9 + 7 10**9 + 7 mod tmp = False False tmp tmp = True True tmp cnt = 0 0 cnt cnt2 = 1 1 cnt2 def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP
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 = input()
K = INT()

cnt = 0
tmp = False
for i in range(1, len(S)):
	if tmp:
		tmp = False
	elif S[i] == S[i-1]:
		cnt += 1
		tmp = True

if tmp or S[0] != S[-1]:
	print(cnt*K)
	exit()

cnt2 = 1
tmp = True
for i in range(1, len(S)):
	if tmp:
		tmp = False
	elif S[i] == S[i-1]:
		cnt2 += 1
		tmp = True

if tmp:
	print((cnt+cnt2)*(K//2) + cnt*(K%2))
else:
	print(cnt+cnt2*(K-1))


