from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

s = list(input())
k = readInt()

if len(Counter(s))==1:
	ans = k*len(s)//2
elif s[0]!=s[-1]:
	ans = 0
	i = 0
	l = 0
	tmp = s[:]+["!"]
	d = []
	while i<len(s):
		if tmp[i]==tmp[i+1]:
			i+=1
		else:
			d.append(tmp[l:i+1])
			l = i+1
			i+=1
	for i in d:
		ans+=len(i)//2
	ans*=k
else:
	ans = 0
	i = 0
	l = 0
	tmp = s[:]+["!"]
	d = []
	while i<len(s):
		if tmp[i]==tmp[i+1]:
			i+=1
		else:
			d.append(tmp[l:i+1])
			l = i+1
			i+=1
	for i in d[1:-1]:
		ans+=len(i)//2
	ans*=k
	ans+=len(d[0])//2
	ans+=len(d[-1])//2
	ans+=(len(d[0])+len(d[-1]))//2*(k-1)


print(ans) from collections import defaultdict from collections import deque from collections import Counter import math math def readInt():
	return int(input()) readInt return int(input()) int(input()) int input() input def readInts():
	return list(map(int, input().split())) readInts return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def readChar():
	return input() readChar return input() input() input def readChars():
	return input().split() readChars return input().split() input().split() ().split () input split s = list(input()) s list(input()) list input() input k = readInt() k readInt() readInt if len(Counter(s))==1:
	ans = k*len(s)//2
elif s[0]!=s[-1]:
	ans = 0
	i = 0
	l = 0
	tmp = s[:]+["!"]
	d = []
	while i<len(s):
		if tmp[i]==tmp[i+1]:
			i+=1
		else:
			d.append(tmp[l:i+1])
			l = i+1
			i+=1
	for i in d:
		ans+=len(i)//2
	ans*=k
else:
	ans = 0
	i = 0
	l = 0
	tmp = s[:]+["!"]
	d = []
	while i<len(s):
		if tmp[i]==tmp[i+1]:
			i+=1
		else:
			d.append(tmp[l:i+1])
			l = i+1
			i+=1
	for i in d[1:-1]:
		ans+=len(i)//2
	ans*=k
	ans+=len(d[0])//2
	ans+=len(d[-1])//2
	ans+=(len(d[0])+len(d[-1]))//2*(k-1) len(Counter(s))==1 len(Counter(s)) len Counter(s) Counter s 1 ans = k*len(s)//2 ans k*len(s)//2 k*len(s) k len(s) len s 2 elif s[0]!=s[-1]:
	ans = 0
	i = 0
	l = 0
	tmp = s[:]+["!"]
	d = []
	while i<len(s):
		if tmp[i]==tmp[i+1]:
			i+=1
		else:
			d.append(tmp[l:i+1])
			l = i+1
			i+=1
	for i in d:
		ans+=len(i)//2
	ans*=k s[0]!=s[-1] s[0] s 0 s[-1] s -1 ans = 0 ans 0 i = 0 i 0 l = 0 l 0 tmp = s[:]+["!"] tmp s[:]+["!"] s[:] s : ["!"] "!" d = [] d [] while i<len(s):
		if tmp[i]==tmp[i+1]:
			i+=1
		else:
			d.append(tmp[l:i+1])
			l = i+1
			i+=1
	 i<len(s) i len(s) len s if tmp[i]==tmp[i+1]:
			i+=1
		else:
			d.append(tmp[l:i+1])
			l = i+1
			i+=1
	 tmp[i]==tmp[i+1] tmp[i] tmp i tmp[i+1] tmp i+1 i 1 i+=1 i 1 d.append(tmp[l:i+1]) d.append d append tmp[l:i+1] tmp l:i+1 l i+1 i 1 l = i+1 l i+1 i 1 i+=1 i 1 for i in d:
		ans+=len(i)//2
	 i d ans+=len(i)//2 ans len(i)//2 len(i) len i 2 ans*=k ans k ans = 0 ans 0 i = 0 i 0 l = 0 l 0 tmp = s[:]+["!"] tmp s[:]+["!"] s[:] s : ["!"] "!" d = [] d [] while i<len(s):
		if tmp[i]==tmp[i+1]:
			i+=1
		else:
			d.append(tmp[l:i+1])
			l = i+1
			i+=1
	 i<len(s) i len(s) len s if tmp[i]==tmp[i+1]:
			i+=1
		else:
			d.append(tmp[l:i+1])
			l = i+1
			i+=1
	 tmp[i]==tmp[i+1] tmp[i] tmp i tmp[i+1] tmp i+1 i 1 i+=1 i 1 d.append(tmp[l:i+1]) d.append d append tmp[l:i+1] tmp l:i+1 l i+1 i 1 l = i+1 l i+1 i 1 i+=1 i 1 for i in d[1:-1]:
		ans+=len(i)//2
	 i d[1:-1] d 1:-1 1 -1 ans+=len(i)//2 ans len(i)//2 len(i) len i 2 ans*=k ans k ans+=len(d[0])//2 ans len(d[0])//2 len(d[0]) len d[0] d 0 2 ans+=len(d[-1])//2 ans len(d[-1])//2 len(d[-1]) len d[-1] d -1 2 ans+=(len(d[0])+len(d[-1]))//2*(k-1) ans (len(d[0])+len(d[-1]))//2*(k-1) (len(d[0])+len(d[-1]))//2 len(d[0])+len(d[-1]) len(d[0]) len d[0] d 0 len(d[-1]) len d[-1] d -1 2 k-1 k 1 print(ans) print ans l = 0 0 l ans*=k k ans tmp = s[:]+["!"] s[:]+["!"] tmp def readChars():
	return input().split() def readChars():
	return input().split() readChars l = i+1 i+1 l d = [] [] d ans+=len(i)//2 len(i)//2 ans ans+=len(d[-1])//2 len(d[-1])//2 ans ans = k*len(s)//2 k*len(s)//2 ans ans = 0 0 ans i+=1 1 i ans+=len(i)//2 len(i)//2 ans i = 0 0 i l = i+1 i+1 l k = readInt() readInt() k ans = 0 0 ans i = 0 0 i def readChar():
	return input() def readChar():
	return input() readChar s = list(input()) list(input()) s l = 0 0 l ans*=k k ans i+=1 1 i i+=1 1 i ans+=len(d[0])//2 len(d[0])//2 ans def readInt():
	return int(input()) def readInt():
	return int(input()) readInt d = [] [] d ans+=(len(d[0])+len(d[-1]))//2*(k-1) (len(d[0])+len(d[-1]))//2*(k-1) ans tmp = s[:]+["!"] s[:]+["!"] tmp i+=1 1 i def readInts():
	return list(map(int, input().split())) def readInts():
	return list(map(int, input().split())) readInts
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

s = list(input())
k = readInt()

if len(Counter(s))==1:
	ans = k*len(s)//2
elif s[0]!=s[-1]:
	ans = 0
	i = 0
	l = 0
	tmp = s[:]+["!"]
	d = []
	while i<len(s):
		if tmp[i]==tmp[i+1]:
			i+=1
		else:
			d.append(tmp[l:i+1])
			l = i+1
			i+=1
	for i in d:
		ans+=len(i)//2
	ans*=k
else:
	ans = 0
	i = 0
	l = 0
	tmp = s[:]+["!"]
	d = []
	while i<len(s):
		if tmp[i]==tmp[i+1]:
			i+=1
		else:
			d.append(tmp[l:i+1])
			l = i+1
			i+=1
	for i in d[1:-1]:
		ans+=len(i)//2
	ans*=k
	ans+=len(d[0])//2
	ans+=len(d[-1])//2
	ans+=(len(d[0])+len(d[-1]))//2*(k-1)


print(ans)