#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;

int main()
{
	ll k; string s, l;
	cin >> s >> k;
	int n = s.size();
	if(n == 1)
	{
		cout << k / 2 << endl;
		return 0;
	}
	if(s[0] != s[n - 1] or k == 1)
	{
		l = s;
		ll tot = 0;
		for(ll i = 1; i < n; i++)
		{
			if(l[i] == l[i - 1])
			{
				tot++;
				l[i] = '*';
			}
		}
		cout << tot * k << endl;
		return 0;
	}
	
	l = s;
	ll tot1 = 1;
	l[0] = '*';
	for(ll i = 1; i < n; i++)
	{
		if(l[i] == l[i - 1])
		{
			tot1++;
			l[i] = '*';
		}
	}
	l = s;
	tot1 *= k;
	if(l[1] != l[0]) tot1--;
	
	l = s;
	reverse(l.begin(), l.end());
	ll tot2 = 1;
	l[0] = '*';
	for(ll i = 1; i < n; i++)
	{
		if(l[i] == l[i - 1])
		{
			tot2++;
			l[i] = '*';
		}
	}
	l = s;
	reverse(l.begin(), l.end());
	tot2 *= k;
	if(l[1] != l[0]) tot2--;
	
	cout << min(tot1, tot2) << endl;
}
