#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order // k th index
#define ook order_of_key // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull,ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define SEGMENT_TREE int mid=(st+en)/2,lt=node*2,rg=lt+1
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const pair<T1, T2>& ps) {
    fout << ps.ff << " " << ps.ss;
    return fout;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& fout, const map<T1, T2>& mp) {
    for (pair<T1, T2> i : mp)
        fout << i.first << " : " << i.second << "\n";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const vector<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
template <typename T>
ostream& operator<<(ostream& fout, const ordered_set<T>& v) {
    for (T i : v)
        fout << i << " ";
    return fout;
}
ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */ // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */ // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */ // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */ // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int changed[209];
int taken[209][209];
int leftx[209];
int rightx[209];
int main() {
    string s;
    ll k;
    int j, l;
    cin >> s >> k;
    int n = s.size();
    bool same = 1;
    for(int i = 0; i < n; i++) {
        if(s[i] != s[0]) {
            same = 0;
            break;
        }
    }
    if(same) {
        if(n % 2 == 0) {
            cout << (n * 1ll / 2)*k << "\n";
        } else {
            cout << min((n * 1ll / 2 + 1)*(k / 2) + (n * 1ll / 2) * (k - k / 2), (n * 1ll / 2 )*(k / 2) + (n * 1ll / 2 + 1) * (k - k / 2)) << "\n";
        }
        return 0;
    }
    if(s[0] == s[n - 1]) {
        n = s.size();
        //0->l-1 | l->j | j+1->n-1
        ll fr, mid, lt;
        fr = mid = lt = 0;
        int j = n - 1;
        char now = s[j];
        string t;
        while(now == s[j]) {
            t += s[j];
            j--;
            lt++;
        }
        reverse(all(t));
        l = 0;
        now = s[0];
        while(now == s[l]) {
            t += s[l];
            l++;
            fr++;
        }
        for(int i = l; i <= j; i++) {
            int k = (i + 1) % n;
            if(s[i] == s[k]) {
                if(taken[i][k] || taken[k][i])
                    continue;
                if(changed[i] || changed[k])
                    continue;
                changed[k] = 1;
                mid++;
                taken[i][k] = 1;
            }
        }
        memset(taken, 0, sizeof taken);
        memset(changed, 0, sizeof changed);
        ll su = 0;
        int n = t.size();
        for(int i = 0; i < n - 1; i++) {
            int k = (i + 1) % n;
            if(t[i] == t[k]) {
                if(taken[i][k] || taken[k][i])
                    continue;
                if(changed[i] || changed[k])
                    continue;
                changed[k] = 1;
                su++;
                taken[i][k] = 1;
            }
        }
        cout << su*(k - 1) + fr / 2 + lt / 2 + mid*k << "\n";
    } else {
        ll ans = 0;
        n = s.size();
        memset(taken, 0, sizeof taken);
        memset(changed, 0, sizeof changed);
        for(int i = 0; i < n - 1; i++) {
            int k = (i + 1) % n;
            if(s[i] == s[k]) {
                if(taken[i][k] || taken[k][i])
                    continue;
                if(changed[i] || changed[k])
                    continue;
                changed[k] = 1;
                ans++;
                taken[i][k] = 1;
            }
        }
        cout << ans*k << "\n";
    }
}


Measured memory_bytes: 384