/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
issii
2
---+/
/+---test
qq
81
---+/
/+---test
cooooooooonteeeeeeeeeest
999993333
---+/

void main(string[] args) {
  const S = readln.chomp;
  const K = readln.chomp.to!long;

  long cnt(string str) {
    long ans;
    long l = -1;
    char ps;
    foreach (i, s; str~'|') {
      if (s == ps) {
        if (l == -1) l = i-1;
      } else if (l != -1) {
        ans += (i - l) / 2;
        l = -1;
      }
      ps = s;
    }
    return ans;
  }

  auto l = S.countUntil!(x => x != S[0]);
  if (l < 0) l = S.length;
  (cnt(S[0..l]) + cnt(S[l..$]~S[0..l])*(K-1) + cnt(S[l..$])).writeln;
}
