#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

int main()
{
    FASTIO;
    string s;
    long long n,ans=0;
    cin>>s>>n;

    if(s.size() == 1)
    {
        if(n != 1) ans = n/2;
    }
    else
    {
        if(n == 1)
        {
            for(int j=1; j<s.size(); j++)
            {
                if(s[j] == s[j-1])
                {
                    s[j] = 'A';
                    ans++;
                }
            }
        }
        else if(s.size() == 2)
        {
            if(s[0]==s[1])
            {
                ans = n;
            }
        }
        else if(s.size() == 3)
        {
            if(s[0] == s[1] && s[1] == s[2])
            {
                ans = ((n+1)/2) + int(n/2)*2;
            }
            else if(s[0] == s[1] && s[1] != s[2])
            {
                ans = n;
            }
            else if(s[0] != s[1] && s[1] == s[2])
            {
                ans = n;
            }
            else if(s[0] == s[2] && s[1] != s[2])
            {
                ans = n-1;
            }
        }
        else
        {
            if(s[0] == s.back())
            {
                string temp = s+s;
                int ans1=0,ans2=0;
                for(int j=1; j<s.size(); j++)
                {
                    if(s[j] == s[j-1])
                    {
                        s[j] = 'A';
                        ans1++;
                    }
                }
                for(int j=1; j<temp.size(); j++)
                {
                    if(temp[j] == temp[j-1])
                    {
                        temp[j] = 'A';
                        ans2++;
                    }
                }
                ans = (ans2-ans1)*(n-1) + ans1;
            }
            else
            {
                for(int j=1; j<s.size(); j++)
                {
                    if(s[j] == s[j-1])
                    {
                        s[j] = 'A';
                        ans++;
                    }
                }
                ans *= n;
            }
            
        }
        
        
    }
    cout<<ans;
}