import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto S = readln.chomp.to!(char[]);
    auto K = readln.chomp.to!long;

    long r;
    foreach (i, ref c; S) {
        if (i == 0) continue;
        if (S[i-1] == c) {
            ++r;
            c = '*';
        }
    }
    r *= K;
    if (S[0] == S[$-1]) r += K - 1;
    writeln(r);
}