#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b = 0, c = 0;
  string s;
  cin >> s >> a;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == s[i + 1]) s[i + 1] = '#', b++;
  }
  if (s[0] == s[s.size() - 1]) c++;
  cout << b * a << endl;
  return 0;
}
