#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cassert>

#include<cmath>
#include<functional>
#include<algorithm>

#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<bitset>
#include<tuple>

#define TEST {IS_TEST=true;}

using namespace std;
using ll = int_fast64_t;
using v_bool = vector <bool>;
using v_ll = vector <ll>;
using v_std = vector <string>;
using p_ll = pair <ll,ll>;
using vv_ll = vector <vector <ll> >;
using vp_ll = vector < p_ll >;

bool IS_TEST=false;
ll ll_min=1LL<<63;
ll ll_max=~ll_min;
ll MOD = 1000000007;


template<class T> bool show_nl(const T&){ return true;}
bool show_nl(const ll&){ return false;}
template<class T,class S> bool show_nl(const pair<T,S>&){ return false;}

template<class T> void show(const T& x,bool newline=false){
  if (!IS_TEST) return;
  cout << x; if (newline) cout << " <#>" <<  endl;
}
void show(const string& x,bool newline=true){
  if (!IS_TEST) return;
  cout << x; if (newline) cout << endl;
}
template<class T,class S> void show(const pair<T,S>& x,bool newline=false){
  if (!IS_TEST) return;
  cout << "{ " << x.first << " " << x.second << " }";
  if (newline) cout << " <#>" <<  endl;
}
template<class T> void show_common3(const T&x){
  if (!IS_TEST) return;
  auto itr=x.begin();
  if (x.begin()==x.end()) {cout<<"<NULL>"<<endl;return;}
  if (show_nl(*itr)){
    cout << "--------------------------------" << endl;
    auto itr=x.begin();
    while(itr!=x.end()){ show(*itr); itr++;}
    cout << "--------------------------------" << endl;
  }else{
    if (itr==x.end()){ cout<<endl; return;}
    while(true){
      show(*itr);itr++;
      if (itr==x.end()) break; else cout << " ";
    }
    cout << endl;
  }
}
template<class T> void show(const vector<T>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T,class S> void show(const set<T,S>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T,class S> void show(const multiset<T,S>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T> void show(const unordered_set<T>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T,class S,class U> void show(const map<T,S,U>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T,class S,class U> void show(const multimap<T,S,U>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T,class S> void show(const unordered_map<T,S>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}

void load(ll& x){ cin >> x;}
void load(string& x){ cin >> x;}
void load(v_ll& v,ll b,ll e){
    v.assign(e+1,0);
    for(ll i=b;i<e;i++)cin >> v[i];
}
v_ll loadvec0(ll n){
    v_ll v(n+1,0);
    for(ll i=0;i<n;i++)cin >> v[i];
    return v;
}
v_ll loadvec1(ll n){
    v_ll v(n+2,0);
    for(ll i=1;i<=n;i++)cin >> v[i];
    return v;
}

void disp(const ll& x){ cout << x << endl;}
void disp(const string& x){ cout << x << endl;}
void disp(const v_ll& v,ll b,ll e){
    for(ll i=b;i<e;i++){
        if (i!=b) cout << " ";
        cout << v[i];
    }
    cout << endl;
}

v_ll arange(ll n){
    v_ll v(n+1,0);
    for(ll i=0;i<=n;i++)v[i]=i;
    return v;
}

ll vec_sum(const v_ll& v,ll b,ll e){
    ll ans=0;
    for(ll i=b;i<e;i++)ans+=v[i];
    return ans;
}


template<class T> void refl_max(T& x,const T& y){ if (x>=y) return; x=y; }
template<class T> void refl_min(T& x,const T& y){ if (x<=y) return; x=y; }

template<class T,class S> void refl_max(T& x,const T& y,S& xx,const S& yy){
  if (x>=y) return; x=y; xx=yy;
}
template<class T,class S> void refl_min(T& x,const T& y,S& xx,const S& yy){
  if (x<=y) return; x=y; xx=yy;
}


string S;
ll K;
int main(){
  cin >> S >> K;
  string T=S;
  ll change=0;
  ll special=0;
  ll keypoint=-1;
  bool all_same=true;
  for (ll i=1;i<T.length();i++)
    if (T[i]!=T[i-1]){
      all_same=false;
      keypoint=i;
      break;
    }
  if (all_same) {
    cout << T.length()*K/2 << endl;
    return 0;
  }
  for (ll i=keypoint+1;i<keypoint+T.length();i++){
    ll j1=i%T.length();ll j2=(i-1)%T.length();
    if (T[j1]==T[j2]){
      T[j1]=' ';change++;
    }
  }
  for (ll i=1;i<S.length();i++){
    if (S[i]==S[i-1]){
      S[i]=' ';special++;
    }
  }
  cout << change*(K-1)+special << endl;

}




Measured memory_bytes: 888