#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	string str;
	ll k;
	while(cin >> str >> k){
	int n = str.size();
	bool f = false;
	for(int i = 0; i < n - 1; i++){
		if(str[i] != str[i+1]){
			f = true;
			break;
		}
	}
	ll ans = 0;
	if(!f){		//如果全一样 
		ans = k * n / 2;
		printf("%lld\n",ans);
	}
	else{
		//找出一个串里面的连续，和两个串里面的，加减一下
		ll ans2 = 0;
		int m = 1;
		for(int i = 0; i < n; i++){	
			if(str[i] == str[i+1])
				m++;	
			else if(i != 0 && str[i] == str[i-1]){
				ans += m / 2;
				m = 1;
			}
		}
		n += n;  str += str;  m = 1;
		for(int i = 0; i < n; i++){	
			if(str[i] == str[i+1])
				m++;	
			else if(i != 0 && str[i] == str[i-1]){
				ans2 += m / 2;
				m = 1;
			}
		}
		ans =  ans + (ans2 - ans) * (k - 1);
		printf("%lld\n",ans);
	}
	
	}
	return 0;
}