
def solve(S,K):
    if all(S[0]==c for c in S):
        return (len(S)*K)//2

    if S[0] == S[-1]:
        cnt0 = 0
        for c in S:
            if c == S[0]:
                cnt0 += 1
            else:
                break
        cnt1 = 0
        for c in reversed(S):
            if c == S[0]:
                cnt1 += 1
            else:
                break
        res = cnt0//2 + cnt1//2 - (cnt0+cnt1)//2
        S = S[cnt0:]+S[:cnt0]
    else:
        res = 0

    t = 0
    k = 0
    last = S[0]
    for c in S:
        if c == last:
            k += 1
        else:
            t += k//2
            k = 1
            last = c
    t += k//2
    res += t*K
    return res

S = input()
K = int(input())
print(solve(S,K)) def solve(S,K):
    if all(S[0]==c for c in S):
        return (len(S)*K)//2

    if S[0] == S[-1]:
        cnt0 = 0
        for c in S:
            if c == S[0]:
                cnt0 += 1
            else:
                break
        cnt1 = 0
        for c in reversed(S):
            if c == S[0]:
                cnt1 += 1
            else:
                break
        res = cnt0//2 + cnt1//2 - (cnt0+cnt1)//2
        S = S[cnt0:]+S[:cnt0]
    else:
        res = 0

    t = 0
    k = 0
    last = S[0]
    for c in S:
        if c == last:
            k += 1
        else:
            t += k//2
            k = 1
            last = c
    t += k//2
    res += t*K
    return res solve if all(S[0]==c for c in S):
        return (len(S)*K)//2

     all(S[0]==c for c in S) all S[0]==c S[0] S 0 c return (len(S)*K)//2 (len(S)*K)//2 len(S)*K len(S) len S K 2 if S[0] == S[-1]:
        cnt0 = 0
        for c in S:
            if c == S[0]:
                cnt0 += 1
            else:
                break
        cnt1 = 0
        for c in reversed(S):
            if c == S[0]:
                cnt1 += 1
            else:
                break
        res = cnt0//2 + cnt1//2 - (cnt0+cnt1)//2
        S = S[cnt0:]+S[:cnt0]
    else:
        res = 0

     S[0] == S[-1] S[0] S 0 S[-1] S -1 cnt0 = 0 cnt0 0 for c in S:
            if c == S[0]:
                cnt0 += 1
            else:
                break
         c S if c == S[0]:
                cnt0 += 1
            else:
                break
         c == S[0] c S[0] S 0 cnt0 += 1 cnt0 1 break cnt1 = 0 cnt1 0 for c in reversed(S):
            if c == S[0]:
                cnt1 += 1
            else:
                break
         c reversed(S) reversed S if c == S[0]:
                cnt1 += 1
            else:
                break
         c == S[0] c S[0] S 0 cnt1 += 1 cnt1 1 break res = cnt0//2 + cnt1//2 - (cnt0+cnt1)//2 res cnt0//2 + cnt1//2 - (cnt0+cnt1)//2 cnt0//2 + cnt1//2 cnt0//2 cnt0 2 cnt1//2 cnt1 2 (cnt0+cnt1)//2 cnt0+cnt1 cnt0 cnt1 2 S = S[cnt0:]+S[:cnt0] S S[cnt0:]+S[:cnt0] S[cnt0:] S cnt0: cnt0 S[:cnt0] S :cnt0 cnt0 res = 0 res 0 t = 0 t 0 k = 0 k 0 last = S[0] last S[0] S 0 for c in S:
        if c == last:
            k += 1
        else:
            t += k//2
            k = 1
            last = c
     c S if c == last:
            k += 1
        else:
            t += k//2
            k = 1
            last = c
     c == last c last k += 1 k 1 t += k//2 t k//2 k 2 k = 1 k 1 last = c last c t += k//2 t k//2 k 2 res += t*K res t*K t K return res res S S K K S = input() S input() input K = int(input()) K int(input()) int input() input print(solve(S,K)) print solve(S,K) solve S K S = input() input() S def solve(S,K):
    if all(S[0]==c for c in S):
        return (len(S)*K)//2

    if S[0] == S[-1]:
        cnt0 = 0
        for c in S:
            if c == S[0]:
                cnt0 += 1
            else:
                break
        cnt1 = 0
        for c in reversed(S):
            if c == S[0]:
                cnt1 += 1
            else:
                break
        res = cnt0//2 + cnt1//2 - (cnt0+cnt1)//2
        S = S[cnt0:]+S[:cnt0]
    else:
        res = 0

    t = 0
    k = 0
    last = S[0]
    for c in S:
        if c == last:
            k += 1
        else:
            t += k//2
            k = 1
            last = c
    t += k//2
    res += t*K
    return res def solve(S,K):
    if all(S[0]==c for c in S):
        return (len(S)*K)//2

    if S[0] == S[-1]:
        cnt0 = 0
        for c in S:
            if c == S[0]:
                cnt0 += 1
            else:
                break
        cnt1 = 0
        for c in reversed(S):
            if c == S[0]:
                cnt1 += 1
            else:
                break
        res = cnt0//2 + cnt1//2 - (cnt0+cnt1)//2
        S = S[cnt0:]+S[:cnt0]
    else:
        res = 0

    t = 0
    k = 0
    last = S[0]
    for c in S:
        if c == last:
            k += 1
        else:
            t += k//2
            k = 1
            last = c
    t += k//2
    res += t*K
    return res solve K = int(input()) int(input()) K

def solve(S,K):
    if all(S[0]==c for c in S):
        return (len(S)*K)//2

    if S[0] == S[-1]:
        cnt0 = 0
        for c in S:
            if c == S[0]:
                cnt0 += 1
            else:
                break
        cnt1 = 0
        for c in reversed(S):
            if c == S[0]:
                cnt1 += 1
            else:
                break
        res = cnt0//2 + cnt1//2 - (cnt0+cnt1)//2
        S = S[cnt0:]+S[:cnt0]
    else:
        res = 0

    t = 0
    k = 0
    last = S[0]
    for c in S:
        if c == last:
            k += 1
        else:
            t += k//2
            k = 1
            last = c
    t += k//2
    res += t*K
    return res

S = input()
K = int(input())
print(solve(S,K))