#include <bits/stdc++.h>
#define MAXN 110
#define ll long long
using namespace std;

char s[MAXN], s1[MAXN];

int main() {
    int K, len, cnt, last;
    ll ans = 0;
    cin >> s >> K;
    len = strlen(s);
    last = 0;
    for(int i = 1; i < len; i++) {
        if(s[i] != s[i - 1]) last = i;
    }
    if(last == 0) ans = 1ll * len * K / 2;
    else {
        memcpy(s1, s, sizeof(s));
        for(int i = 1; i < last; i++) {
            if(s1[i] == s1[i - 1]){
                ++ans;
                s1[i] = '#';
            }
        }
        ans += (len - last) / 2;
        for(int i = last, j = 0; j < len; ++j, i = (i + 1) % len)
            s1[j] = s[i];
        cnt = 0;
        for (int i = 1; i < len; i++) {
            if (s1[i] == s1[i - 1]) {
                ++cnt;
                s1[i] = '#';
            }
        }
        ans += 1ll * cnt * (K - 1);
    }
    cout << ans << endl;
}