import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto s = readln.chomp.array;
  auto k = readln.chomp.to!int;
  auto cnt = long.max;

  if (k == 1 || s[0] != s[$-1]) {
    long tmp;
    foreach (i; 1..s.length) {
      if (s[i-1] == s[i]) {
        tmp++;
        s[i] = 'A';
      }
    }
    tmp *= k;
    cnt = min(cnt, tmp);
  } else {
    if (s.length > 2 && s[0] == s[1]) {
      auto t = s.dup;
      long tmp;
      t[0] = 'A';
      foreach (i; 1..t.length) {
        if (t[i-1] == t[i]) {
          tmp++;
          t[i] = 'A';
        }
      }
      
      tmp *= k;
      tmp += k - 1;
      cnt = min(cnt, tmp);
    }
    if (s.length > 2 && s[$-2] == s[$-1]) {
      auto t = s.dup;
      long tmp;
      t[$-2] = 'A';
      tmp++;
      foreach (i; 1..t.length) {
        if (t[i-1] == t[i]) {
          tmp++;
          t[i] = 'A';
        }
      }
      tmp *= k;
      
      t[0] ='A';
      tmp += k - 1;

      cnt = min(cnt, tmp);
    }
    long tmp;
    auto t = s.dup;
    foreach (i; 1..t.length) {
      if (t[i-1] == t[i]) {
        tmp++;
        t[i] = 'A';
      }
    }
    tmp *= k;
    if (t[0] == t[$-1]) {
      t[0] ='A';
      tmp += k - 1;
    }
    cnt = min(cnt, tmp);
  }
  cnt.writeln;
}
