# -*- coding: utf-8 -*-

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

S = input()
K = int(input())


if len(S) >= 1:
	flagtail = 0
	old_s = ""
	cnt = 0
	for s_ in S:
		if s_ == old_s:
			cnt +=1
			old_s = ""
		else:
			old_s = s_
	ans = cnt

	cnt1 = cnt
	old_s = ""

	if(K > 1 and K %2 == 0):
		S = S*2
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)

	if(K > 1 and K %2 != 0):
		S = S*3
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)//2
	print(ans)
else:
	print(K//2) def input_multiple_number():
    return map(int, input().split()) input_multiple_number return map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split S = input() S input() input K = int(input()) K int(input()) int input() input if len(S) >= 1:
	flagtail = 0
	old_s = ""
	cnt = 0
	for s_ in S:
		if s_ == old_s:
			cnt +=1
			old_s = ""
		else:
			old_s = s_
	ans = cnt

	cnt1 = cnt
	old_s = ""

	if(K > 1 and K %2 == 0):
		S = S*2
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)

	if(K > 1 and K %2 != 0):
		S = S*3
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)//2
	print(ans)
else:
	print(K//2) len(S) >= 1 len(S) len S 1 flagtail = 0 flagtail 0 old_s = "" old_s "" cnt = 0 cnt 0 for s_ in S:
		if s_ == old_s:
			cnt +=1
			old_s = ""
		else:
			old_s = s_
	 s_ S if s_ == old_s:
			cnt +=1
			old_s = ""
		else:
			old_s = s_
	 s_ == old_s s_ old_s cnt +=1 cnt 1 old_s = "" old_s "" old_s = s_ old_s s_ ans = cnt ans cnt cnt1 = cnt cnt1 cnt old_s = "" old_s "" if(K > 1 and K %2 == 0):
		S = S*2
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)

	 K > 1 and K %2 == 0 K > 1 K 1 K %2 == 0 K %2 K 2 0 S = S*2 S S*2 S 2 cnt1 = cnt cnt1 cnt cnt = 0 cnt 0 old_s = "" old_s "" for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		 s_ S if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		 s_ == old_s s_ old_s cnt +=1 cnt 1 old_s = "" old_s "" old_s = s_ old_s s_ ans = cnt1 + (cnt-cnt1)*(K-1) ans cnt1 + (cnt-cnt1)*(K-1) cnt1 (cnt-cnt1)*(K-1) cnt-cnt1 cnt cnt1 K-1 K 1 if(K > 1 and K %2 != 0):
		S = S*3
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)//2
	 K > 1 and K %2 != 0 K > 1 K 1 K %2 != 0 K %2 K 2 0 S = S*3 S S*3 S 3 cnt1 = cnt cnt1 cnt cnt = 0 cnt 0 old_s = "" old_s "" for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		 s_ S if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		 s_ == old_s s_ old_s cnt +=1 cnt 1 old_s = "" old_s "" old_s = s_ old_s s_ ans = cnt1 + (cnt-cnt1)*(K-1)//2 ans cnt1 + (cnt-cnt1)*(K-1)//2 cnt1 (cnt-cnt1)*(K-1)//2 (cnt-cnt1)*(K-1) cnt-cnt1 cnt cnt1 K-1 K 1 2 print(ans) print ans print(K//2) print K//2 K 2 old_s = "" "" old_s old_s = "" "" old_s S = input() input() S cnt +=1 1 cnt flagtail = 0 0 flagtail old_s = "" "" old_s ans = cnt1 + (cnt-cnt1)*(K-1) cnt1 + (cnt-cnt1)*(K-1) ans cnt +=1 1 cnt cnt1 = cnt cnt cnt1 def input_multiple_number():
    return map(int, input().split()) def input_multiple_number():
    return map(int, input().split()) input_multiple_number cnt1 = cnt cnt cnt1 old_s = s_ s_ old_s cnt = 0 0 cnt old_s = "" "" old_s cnt1 = cnt cnt cnt1 old_s = "" "" old_s ans = cnt cnt ans K = int(input()) int(input()) K S = S*2 S*2 S cnt +=1 1 cnt ans = cnt1 + (cnt-cnt1)*(K-1)//2 cnt1 + (cnt-cnt1)*(K-1)//2 ans cnt = 0 0 cnt old_s = "" "" old_s cnt = 0 0 cnt old_s = "" "" old_s old_s = s_ s_ old_s old_s = s_ s_ old_s S = S*3 S*3 S
# -*- coding: utf-8 -*-

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

S = input()
K = int(input())


if len(S) >= 1:
	flagtail = 0
	old_s = ""
	cnt = 0
	for s_ in S:
		if s_ == old_s:
			cnt +=1
			old_s = ""
		else:
			old_s = s_
	ans = cnt

	cnt1 = cnt
	old_s = ""

	if(K > 1 and K %2 == 0):
		S = S*2
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)

	if(K > 1 and K %2 != 0):
		S = S*3
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)//2
	print(ans)
else:
	print(K//2)