#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1e18;
constexpr double PI = 3.14159265358979;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  string s;
  long long k, ans = 0, cnt = 0;
  cin >> s >> k;
  string t = s + s + s;
  int n = (int)s.size();
  if (n == 1) {
    cout << k / 2 << endl;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i - 1]) {
      s[i] = '.';
      cnt++;
    }
  }
  if (s[0] == s[n - 1]) {
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i < n + n + n; i++) {
      if (t[i] == t[i - 1]) {
        if (i < n) {
          t[i] = '.';
          ans++;
        } else if (n <= i and i < n + n) {
          t[i] = '.';
          cnt1++;
        } else {
          t[i] = '.';
          cnt2++;
        }
      }
    }
    k--;
    if (cnt1 != cnt2) {
      ans += cnt1 * (k / 2 + k % 2);
      ans += cnt2 * (k / 2);
    } else {
      ans += cnt1 * k;
    }
  } else {
    ans += cnt * k;
  }
  cout << ans << endl;
  return 0;
}
