#include<bits/stdc++.h>
using namespace std;

int main(){
	string s; long long k;
	cin >> s >> k;
	string t = s,d = s;
	long long ans1 = 0,ans2 = 0,ans3 = 0;
	for(int i = 1;i < s.size();i++){
		if(s[i] == s[i-1]){
			ans1++;
			s[i] = '-';
		}
	}
	t = s + t;
	for(int i = 1;i < t.size();i++){
		if(t[i] == t[i-1]){
			ans2++;
			t[i] = '-';
		}
	}
	d = t + d;
	for(int i = 1;i < d.size();i++){
		if(d[i] == d[i-1]){
			ans3++;
			d[i] = '-';
		}
	}
	long long sum = ans1 + (ans2 + ans3) * ((k-1)/2);
	if((k-1)%2 == 1) sum += ans2;
	cout << sum << endl;
	return 0;
}