#include<cstdio>
#include<cstring>
const int S=105;

int len;
long long cnt,tot,at;
char s[S],k[S];

int main() {
	scanf("%s",s+1);
	len=strlen(s+1);
	scanf("%lld",&cnt);
	at=1;
	k[1]='-';
	for(int i=2;i<=len;i++) {
		k[i]=s[i];
		if(s[i]==s[i-1])
			tot++,s[i]='-';
		if(k[i]==k[i-1])
			at++,k[i]='-';
	}
	if(s[1]!=s[len])
		printf("%lld\n",1LL*cnt*tot);
	else {
		if(k[len]=='-')
			printf("%lld\n",cnt/2*tot+cnt/2*at+(cnt%2)*tot);
		else printf("%lld\n",tot+(cnt-1)*at);
	}
	return 0;
}