#include <iostream>
#include <cstdio>
#include <cstring>
char s[105];
int main() {
    int k;
    int cnt = 0;
    scanf("%s", s);
    scanf("%d", &k);
    int len = strlen(s);
    if (len == 1) {
        printf("%d", k >> 1);
        return 0;
    }
    for (int i = 0; i < len; i++) {
        if (s[i] == s[i - 1]) {
            s[i] = '#';
            cnt++;
        }
    }
    printf("%lld", (s[0] == s[len - 1]) ?
           (long long)k * cnt + k - 1: (long long)k * cnt);
    return 0;
}
