#include<iostream>
using namespace std;
int main()
{
    string s;
    long long int k;
    int i,cnt=1,flag=0,ans=0;
    cin >> s;
    cin >> k;
    if(s[0]==s[s.size()-1])flag=-1;
    for(i=0;i<s.size()-1;i++){
        if(s[i]==s[i+1])cnt++;
        else{
            if(flag==-1) flag=cnt;
            else ans+=(cnt-cnt%2)/2;
            cnt=1;
        }
    }
    if(flag==-1) cout << (s.size()*k-s.size()%2*k%2)/2;
    else if(flag>0) cout << ans*k+((flag+cnt)-(flag+cnt)%2)*(k-1)/2+(flag-flag%2)/2+(cnt-cnt%2)/2;
    else {
        ans+=(cnt-cnt%2)/2;
        cout << ans*k;
    }
    return 0;
}