#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int N = 1e9+5;
 
vector<int> col;
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int k;
    cin >> s >> k;
    col.clear();
    int len = s.size();
    int num = 1;
    char c = s[0];
    int sum = 0;
    for(int i=1;i<len;i++)
    {
        if(s[i]==c)
            num++;
        else
        {
            col.push_back(num);
            sum += num/2;
            num = 1;
            c = s[i];
        }
    }
    col.push_back(num);
    int siz = col.size();
    if(siz==1)
    {
        cout << (ll)(len)*(ll)(k)/2LL << "\n";
    }
    else if(s[0]==s[len-1])
    {
        sum -= col[0]/2;
        cout << (ll)(sum)*(ll)(k) + (ll)(col[0]/2) + (ll)(col[siz-1]/2) + (ll)((col[0]+col[siz-1])/2) * (ll)(k-1);
    }
    else
    {
        sum += col[siz-1]/2;
        cout << (ll)(sum)*(ll)(k) << "\n";
    }
    return 0;
}