#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int main(){
  string s;
  ll k;
  cin >> s >> k;
  ll ans=0;
  ll n=s.size();
  ll cnt=1;
  char c=s[0];
  bool flag=false;
  for(int i=1;i<n;i++){
    if(s[i]==c) cnt++;
    else{
      if(flag||s[0]!=s[n-1]) ans+=cnt/2*k;
      else ans+=cnt/2;
      cnt=1;
      c=s[i];
      flag=true;
    }
  }
  if(cnt==n) cout << n*k/2 << endl;
  else{
    ans+=cnt/2;
    for(int i=0;i<n;i++){
      if(c==s[i]) cnt++;
      else break;
    }
    ans+=cnt/2*(k-1);
    cout << ans << endl;
  }
}