#include <bits/stdc++.h>
using namespace std;
string s;
long long k, ans;
vector<pair<char, int> > g;
void kek() {
  for (int i = 0; i < g.size(); ++i) {
    ans += g[i].second / 2ll;
  }
  long long key = ans * k;
  cout << key;
}
void LOL() {
  long long key = g[0].second * k;
  cout << key / 2ll;
}
int main() {
  cin >> s;
  cin >> k;
  long long cnt = 0;
  bool check = 0;
  for (int i = 0; i < s.size(); ++i) {
    cnt++;
    if (!i) {
      continue;
    }
    if (s[i] != s[i - 1]) {
      if (!check) {
        check = 1;
        g.push_back(make_pair(s[i - 1], cnt - 1));
        cnt = 1;
      } else {
        g.push_back(make_pair(s[i - 1], cnt - 1));
        cnt = 1;
      }
    }
  }
  if (cnt) {
    g.push_back(make_pair(s[s.size() - 1], cnt));
  }
  if (g.size() == 1) {
    LOL();
  } else if (s[0] != s[s.size() - 1]) {
    kek();
  } else {
    for (int i = 0; i < g.size() - 1; ++i) {
      ans += g[i].second / 2ll;
    }
    long long all = ans * k + (g[g.size() - 1].second / 2ll) +
                    ((g[g.size() - 1].second + g[0].second) / 2ll) * (k - 1);
    cout << all;
  }
  return 0;
}
