#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

string S;
ll K;

bool all_same() {
  for (ll i = 0; i < S.size(); ++i)
    if (S[i] != S[0]) return false;
  return true;
}
ll calc(string s) {
  ll r = 0;
  for (ll i = 1; i < s.size(); ++i) {
    if (s[i - 1] == s[i]) {
      s[i] = '%';
      ++r;
    }
  }
  return r;
}
ll solve() {
  if (all_same()) {
    return S.size() * K / 2;
  }
  ll a = calc(S), b = calc(S + S);
  return (b - a) * (K - 1) + a;
}
int main() {
  cin >> S >> K;
  cout << solve() << endl;
  return 0;
}
