#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	long long times;
	cin>>times;
	long long cnt=1,dif=1;
	long long sum=0;
		if(s.size()==1){
		printf("%lld\n",times/2);
		return 0;
	}
	for(int i=1;i<s.size();i++){
		while(s[i]==s[i-1]){
			if(i>=s.size())
				break;
			i++;
			cnt++;	
		}
		sum+=cnt/2;
		cnt=1;
		if(i<s.size()) dif++;
	}
	//cout<<dif<<endl;

	if(dif==1){
		printf("%lld\n",(s.size()*times)/2);
	}
	else if(s[0]==s[s.size()-1]){
		int cnt1=1,cnt2=1;
		int i=1;
		while(s[i]==s[i-1]){
			i++;
			cnt1++;
		}
		i=s.size()-1;
		while(s[i]==s[i-1]){
			i--;
			cnt2++;
		}
		//cout<<cnt1<<" "<<cnt2<<" ";
		sum=(sum-cnt1/2-cnt2/2)*times+cnt1/2+cnt2/2+(cnt1+cnt2)/2*(times-1);
		printf("%lld\n",sum);	
	}
	else printf("%lld\n",sum*times);
	
	
	return 0;
}