#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define lb lower_bound
#define vi vector < ll  int >
#define CLR(a) memset((a),0,sizeof(a))
#define mp make_pair
#define hell 1000000007
#define pc __builtin_popcount
using namespace std;
/*
vector < int > tree(400005);

void buildtree (vector < int > v,int node,int start,int fin)
  {
      if(start==fin)
      {
          tree[node]=v[start];
          return;
      }
      int mid=(start+fin)/2;
      buildtree(v,2*node,start,mid);
      buildtree(v,2*node+1,mid+1,fin);
      tree[node]=tree[2*node]+tree[2*node+1];
  }

 int sum (int node,int tl,int tr,int l , int r)
   {
       if(l>r) return 0;
       if(l==tl and r==tr) return tree[node];
       int mid=(tl+tr)/2;
       return sum(2*node,tl,mid,l,min(r,mid))+sum(2*node+1,mid+1,tr,max(l,mid+1),r);
   }

  void update(int node,int tl , int tr,int pos,int val)
    {
        if(tl==tr) {tree[node]=val; return;}
        int mid=(tl+tr)/2;
        if(pos<=mid)
              update(2*node,tl,mid,pos,val);
        else
            update(2*node+1,mid+1,tr,pos,val);
        tree[node]=tree[2*node]+tree[2*node+1];

    }

*/
vector  < int > callps(string &s)
{
    int i,j=0,n=s.size();
    vector < int > lps(n+1);
    for(i=1;i<n;)
    {
        if(s[i]==s[j])
        {
            lps[i++]=++j;
        }
        else
        {
            if(j==0) i++;
            else{
                j=lps[j-1];
            }
        }
    }
    return lps;
}

int KMP(string &A, string &B)
{
    int n=A.size(),m=B.size(),i,j=0;
    vector < int > lps=callps(B);
    for(i=max(0,n-m);i<n;)
    {
        if(A[i]==B[j])
        {i++,j++;
        }

        else
        {
            if(j==0) i++;
            else{
                j=lps[j-1];
            }
        }
    }
    return j;
}

ll pr (ll x, ll y)
{
    if(!y) return 1;
    ll res=1;
    while(y>1)
    {
        if(y&1) res*=x,res%=hell;
        x*=x; x%=hell;
        y>>=1;
    }
    res*=x; res%=hell;
    return res;

}
ll fact[100050],ifact[100050];
ll inv(ll x)
{
    return pr(x,hell-2);
}

class comp
{
private:
    int a,b;
public:
    void st(int x, int y)
    {
        a=x; b=y;
    }
    void sd()
    {
        cout<<a<<" "<<b<<endl;
    }
    void add(comp cc)
    {
        a+=cc.a;
        b+=cc.b;
    }
    comp operator-()
    {
        comp temp;
        temp.a=-a;
        temp.b=-b; return temp;
    }
};
void solve()
{
    ll int i,j=0,r=200,p,q,k,d,y=0,h,flag=1,n,m=0,a=hell,b=hell,h1,h2,a1,b1,a2,w,x,u,f,l,c,z;
    string s;
    cin>>s>>k;
    n=s.size();
    set < char > st;
    rep(i,0,n) st.insert(s[i]);
    if(st.size()==1) {cout<<(n*k)/2; return;}
    if(n==1) {cout<<k/2; return;}
    if(k==1)
    {
        rep(i,1,n)
        {
            if(s[i]==s[i-1])
            {
                y++; i++;
            }
        }
        cout<<y; return;
    }
    if(k==2)
    {
        s+=s;
         rep(i,1,2*n)
        {
            if(s[i]==s[i-1])
            {
                y++; i++;
            }
        }
        cout<<y; return;
    }
    if(n==2)
    {
        if(s[0]!=s[1]) {cout<<0; return;}
        else cout<<k; return;
    }

    else
    {
        string ss=s+s; flag=0;
      /*  rep(i,1,n)
        {
            if(s[i]==s[i-1])
            {   if(i==n-1) flag=1;
                y++; i++;
            }
        }
        if(flag) {cout<<k*y; return;}
        if(s[0]!=s[n-1]) {cout<<k*y; return;}

       */
       y=0;
         rep(i,1,n)
        {
            if(s[i]==s[i-1])
            {   //if(i==n-1) flag=1;
                y++; i++;
            }
        }
        ll y2=0;
        rep(i,1,2*n)
        {
            if(ss[i]==ss[i-1])
            {
                y2++; i++;
            }
        } //cout<<y<<" "<<y2<<endl;
        d=y2-y;
        y+=(k-1)*d;
        cout<<y;

    }
}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--)
    solve();
}


Measured memory_bytes: 256