#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int MaxN = 100;
char s[MaxN+5]; int k,len;

int main(){
	cin >> s >> k;
	len = strlen(s);
	long long ans = 0;
	int head, tail;
	for(int i=0, j; i<len; i=j){
		for(j=i; j<len; ++j)
			if(s[j] != s[i])
				break;
		ans += (j-i)>>1;
		if(not i) head = j-i;
		if(j == len) tail = j-i;
	}
	if(head == len and tail == len)
		ans = 1ll*k*len>>1;
	else{
		ans = ans*k;
		if(s[0] == s[len-1] and head/2+tail/2 < (head+tail)/2)
			ans += k-1;
	}
	cout << ans;
	return 0;
}