/* 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) {
  auto  S = readln.chomp.to!string;
  const K = readln.chomp.to!long;

  long ans;
  auto l = S.countUntil!(x => x != S[0]);
  auto r = S.retro.countUntil!(x => x != S[$-1]);

  if (l < 0 || r < 0) {
    (S.length*K/2).writeln;
    return;
  }

  ans += l/2;
  ans += r/2;

  if (S[0] == S[$-1]) {
    ans += (l+r)/2 * (K-1);
  } else {
    ans += (l/2 + r/2) * (K-1);
  }
  r = S.length - r;

  long n = 1;
  foreach (i; l..r+1) {
    if (S[i-1] == S[i]) {
      ++n;
    } else {
      ans += n/2 * K;
      n = 1;
    }
  }
  ans.writeln;
}
