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

int main() {
	string s, u;
	int k;
	cin >> s >> k;
	long d[3] = {};
	for (int j = 0; j < 3; j++) {
		auto t = u += s;
		for (int i = 1; i < t.length(); i++)
			if (t[i - 1] == t[i])
				t[i] = '!', d[j]++;
	}
	if (k < 2) cout << d[0] << endl;
	else cout << (k % 2 ? d[2] : d[1]) + (d[2] - d[0])*(k / 2 - 1) << endl;
	return 0;
}
