#include <iostream>
#include <string>
using namespace std;

typedef long long ll;

string s; int n;
ll k;
int ans1, ans2;

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