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 solve(char[] s) {
        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;
        return r;
    }

    auto S2 = S.dup;
    reverse(S2);
    writeln(min(solve(S), solve(S2)));
}