S = input()
K = int(input())

if S[0] != S[-1]:
    ans = 0
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S = S[:i + 1] + '*' + S[i + 2:]
            ans += 1
    print(ans * K)
else:
    # S -> s_1 s_2 ... s_k + A + t_l t_l-1 ... t_1 (s_i = t_j)と分解
    k, l = 0, len(S) - 1
    while k < len(S) and S[k] == S[-1]:
        k += 1
    while l > -1 and S[l] == S[0]:
        l -= 1

    # 連結に関係ない部分のカウント
    A = S[k:l + 1]
    ans = 0
    for i in range(len(A) - 1):
        if A[i + 1] == A[i]:
            A = A[:i + 1] + '*' + A[i + 2:]
            ans += 1
    ans *= K

    # 連結に関係ある部分のカウント
    if l == -1 and k == len(S):
        # 全部同じ
        print((len(S) * K) // 2)
    else:
        ans += (len(S) - l + k - 1) // 2 * (K - 1)
        ans += (len(S) - l - 1) // 2 + k // 2
        print(ans) S = input() S input() input K = int(input()) K int(input()) int input() input if S[0] != S[-1]:
    ans = 0
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S = S[:i + 1] + '*' + S[i + 2:]
            ans += 1
    print(ans * K)
else:
    # S -> s_1 s_2 ... s_k + A + t_l t_l-1 ... t_1 (s_i = t_j)と分解
    k, l = 0, len(S) - 1
    while k < len(S) and S[k] == S[-1]:
        k += 1
    while l > -1 and S[l] == S[0]:
        l -= 1

    # 連結に関係ない部分のカウント
    A = S[k:l + 1]
    ans = 0
    for i in range(len(A) - 1):
        if A[i + 1] == A[i]:
            A = A[:i + 1] + '*' + A[i + 2:]
            ans += 1
    ans *= K

    # 連結に関係ある部分のカウント
    if l == -1 and k == len(S):
        # 全部同じ
        print((len(S) * K) // 2)
    else:
        ans += (len(S) - l + k - 1) // 2 * (K - 1)
        ans += (len(S) - l - 1) // 2 + k // 2
        print(ans) S[0] != S[-1] S[0] S 0 S[-1] S -1 ans = 0 ans 0 for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S = S[:i + 1] + '*' + S[i + 2:]
            ans += 1
     i range(len(S) - 1) range len(S) - 1 len(S) len S 1 if S[i] == S[i + 1]:
            S = S[:i + 1] + '*' + S[i + 2:]
            ans += 1
     S[i] == S[i + 1] S[i] S i S[i + 1] S i + 1 i 1 S = S[:i + 1] + '*' + S[i + 2:] S S[:i + 1] + '*' + S[i + 2:] S[:i + 1] + '*' S[:i + 1] S :i + 1 i + 1 i 1 '*' S[i + 2:] S i + 2: i + 2 i 2 ans += 1 ans 1 print(ans * K) print ans * K ans K k, l = 0, len(S) - 1 k 0 l len(S) - 1 len(S) len S 1 while k < len(S) and S[k] == S[-1]:
        k += 1
     k < len(S) and S[k] == S[-1] k < len(S) k len(S) len S S[k] == S[-1] S[k] S k S[-1] S -1 k += 1 k 1 while l > -1 and S[l] == S[0]:
        l -= 1

    # 連結に関係ない部分のカウント
     l > -1 and S[l] == S[0] l > -1 l -1 S[l] == S[0] S[l] S l S[0] S 0 l -= 1 l 1 A = S[k:l + 1] A S[k:l + 1] S k:l + 1 k l + 1 l 1 ans = 0 ans 0 for i in range(len(A) - 1):
        if A[i + 1] == A[i]:
            A = A[:i + 1] + '*' + A[i + 2:]
            ans += 1
     i range(len(A) - 1) range len(A) - 1 len(A) len A 1 if A[i + 1] == A[i]:
            A = A[:i + 1] + '*' + A[i + 2:]
            ans += 1
     A[i + 1] == A[i] A[i + 1] A i + 1 i 1 A[i] A i A = A[:i + 1] + '*' + A[i + 2:] A A[:i + 1] + '*' + A[i + 2:] A[:i + 1] + '*' A[:i + 1] A :i + 1 i + 1 i 1 '*' A[i + 2:] A i + 2: i + 2 i 2 ans += 1 ans 1 ans *= K ans K if l == -1 and k == len(S):
        # 全部同じ
        print((len(S) * K) // 2)
    else:
        ans += (len(S) - l + k - 1) // 2 * (K - 1)
        ans += (len(S) - l - 1) // 2 + k // 2
        print(ans) l == -1 and k == len(S) l == -1 l -1 k == len(S) k len(S) len S print((len(S) * K) // 2) print (len(S) * K) // 2 len(S) * K len(S) len S K 2 ans += (len(S) - l + k - 1) // 2 * (K - 1) ans (len(S) - l + k - 1) // 2 * (K - 1) (len(S) - l + k - 1) // 2 len(S) - l + k - 1 len(S) - l + k len(S) - l len(S) len S l k 1 2 K - 1 K 1 ans += (len(S) - l - 1) // 2 + k // 2 ans (len(S) - l - 1) // 2 + k // 2 (len(S) - l - 1) // 2 len(S) - l - 1 len(S) - l len(S) len S l 1 2 k // 2 k 2 print(ans) print ans S = S[:i + 1] + '*' + S[i + 2:] S[:i + 1] + '*' + S[i + 2:] S ans += (len(S) - l - 1) // 2 + k // 2 (len(S) - l - 1) // 2 + k // 2 ans A = S[k:l + 1] S[k:l + 1] A ans += 1 1 ans S = input() input() S l = 0, len(S) - 1 len(S) - 1 l ans = 0 0 ans A = A[:i + 1] + '*' + A[i + 2:] A[:i + 1] + '*' + A[i + 2:] A l -= 1 1 l k, l = 0, len(S) - 1 0 k k += 1 1 k ans += 1 1 ans ans *= K K ans K = int(input()) int(input()) K ans = 0 0 ans ans += (len(S) - l + k - 1) // 2 * (K - 1) (len(S) - l + k - 1) // 2 * (K - 1) ans
S = input()
K = int(input())

if S[0] != S[-1]:
    ans = 0
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S = S[:i + 1] + '*' + S[i + 2:]
            ans += 1
    print(ans * K)
else:
    # S -> s_1 s_2 ... s_k + A + t_l t_l-1 ... t_1 (s_i = t_j)と分解
    k, l = 0, len(S) - 1
    while k < len(S) and S[k] == S[-1]:
        k += 1
    while l > -1 and S[l] == S[0]:
        l -= 1

    # 連結に関係ない部分のカウント
    A = S[k:l + 1]
    ans = 0
    for i in range(len(A) - 1):
        if A[i + 1] == A[i]:
            A = A[:i + 1] + '*' + A[i + 2:]
            ans += 1
    ans *= K

    # 連結に関係ある部分のカウント
    if l == -1 and k == len(S):
        # 全部同じ
        print((len(S) * K) // 2)
    else:
        ans += (len(S) - l + k - 1) // 2 * (K - 1)
        ans += (len(S) - l - 1) // 2 + k // 2
        print(ans)
