void main() {
    string s = readln.chomp;
    long k = readln.chomp.to!int;
    auto g = s.group.array;
    long ans;
    if (g.length == 1) {
        ans = k * g[0][1].to!long / 2;
    } else {
        foreach (x; g) {
            ans += x[1] / 2;
        }
        ans *= k;
        if (s[0] == s[$-1]) {
            long tmp = (g[0][1] + g[$-1][1]) / 2;
            tmp -= g[0][1] / 2 + g[$-1][1] / 2;
            ans += (k - 1) * tmp;
        }
    }
    ans.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;