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!long;

  if (s.uniq.array.length == 1) {
    writeln(s.length * k /2);
  } else {
    long tmp;
    long cnt = 1;
    foreach (i; 1..s.length) {
      if (s[i-1] == s[i]) {
        cnt++;
      } else {
        tmp += cnt / 2;
        cnt = 1;
      }
    }
    
    tmp += cnt / 2;
    tmp *= k;

    if (s[0] != s[$-1]) {
      tmp.writeln;
    } else {
      long a=1, b=1;
      foreach (i; 1..s.length) {
        if (s[i-1] == s[i]) a++;
        else break;
      }
      foreach_reverse (i; 0..s.length-1) {
        if (s[i+1] == s[i]) b++;
        else break;
      }
      tmp -= (k-1) * (a/2 + b/2 - (a+b)/2);
      tmp.writeln;
    } 
  }
}
