def main():
    S = [i for i in input()]
    O = S[:]
    K = int(input())
    if len(S) == 1:
        return K // 2
    r = 0
    for i in range(1, len(S)):
        if S[i] == S[i - 1]:
            r += 1
            S[i] = S[i].upper()
    if S[-1] != S[0]:
        return r * K

    S = S + O
    p = 0
    for i in range(len(O), len(S)):
        if S[i] == S[i - 1]:
            p += 1
            S[i] = S[i].upper()
    if S[-1] == S[0]:
        return r + p * (K - 1)
    return (r + p) * (K // 2) + r * (K % 2)
   

print(main()) def main():
    S = [i for i in input()]
    O = S[:]
    K = int(input())
    if len(S) == 1:
        return K // 2
    r = 0
    for i in range(1, len(S)):
        if S[i] == S[i - 1]:
            r += 1
            S[i] = S[i].upper()
    if S[-1] != S[0]:
        return r * K

    S = S + O
    p = 0
    for i in range(len(O), len(S)):
        if S[i] == S[i - 1]:
            p += 1
            S[i] = S[i].upper()
    if S[-1] == S[0]:
        return r + p * (K - 1)
    return (r + p) * (K // 2) + r * (K % 2)
    main i for i in input() for i in input() i input() input for i in input() i S = [i for i in input()] S [i for i in input()] O = S[:] O S[:] S : K = int(input()) K int(input()) int input() input if len(S) == 1:
        return K // 2
     len(S) == 1 len(S) len S 1 return K // 2 K // 2 K 2 r = 0 r 0 for i in range(1, len(S)):
        if S[i] == S[i - 1]:
            r += 1
            S[i] = S[i].upper()
     i range(1, len(S)) range 1 len(S) len S if S[i] == S[i - 1]:
            r += 1
            S[i] = S[i].upper()
     S[i] == S[i - 1] S[i] S i S[i - 1] S i - 1 i 1 r += 1 r 1 S[i] = S[i].upper() S[i] S i S[i].upper() [i].upper [i] S i upper if S[-1] != S[0]:
        return r * K

     S[-1] != S[0] S[-1] S -1 S[0] S 0 return r * K r * K r K S = S + O S S + O S O p = 0 p 0 for i in range(len(O), len(S)):
        if S[i] == S[i - 1]:
            p += 1
            S[i] = S[i].upper()
     i range(len(O), len(S)) range len(O) len O len(S) len S if S[i] == S[i - 1]:
            p += 1
            S[i] = S[i].upper()
     S[i] == S[i - 1] S[i] S i S[i - 1] S i - 1 i 1 p += 1 p 1 S[i] = S[i].upper() S[i] S i S[i].upper() [i].upper [i] S i upper if S[-1] == S[0]:
        return r + p * (K - 1)
     S[-1] == S[0] S[-1] S -1 S[0] S 0 return r + p * (K - 1) r + p * (K - 1) r p * (K - 1) p K - 1 K 1 return (r + p) * (K // 2) + r * (K % 2) (r + p) * (K // 2) + r * (K % 2) (r + p) * (K // 2) r + p r p K // 2 K 2 r * (K % 2) r K % 2 K 2 print(main()) print main() main def main():
    S = [i for i in input()]
    O = S[:]
    K = int(input())
    if len(S) == 1:
        return K // 2
    r = 0
    for i in range(1, len(S)):
        if S[i] == S[i - 1]:
            r += 1
            S[i] = S[i].upper()
    if S[-1] != S[0]:
        return r * K

    S = S + O
    p = 0
    for i in range(len(O), len(S)):
        if S[i] == S[i - 1]:
            p += 1
            S[i] = S[i].upper()
    if S[-1] == S[0]:
        return r + p * (K - 1)
    return (r + p) * (K // 2) + r * (K % 2)
    def main():
    S = [i for i in input()]
    O = S[:]
    K = int(input())
    if len(S) == 1:
        return K // 2
    r = 0
    for i in range(1, len(S)):
        if S[i] == S[i - 1]:
            r += 1
            S[i] = S[i].upper()
    if S[-1] != S[0]:
        return r * K

    S = S + O
    p = 0
    for i in range(len(O), len(S)):
        if S[i] == S[i - 1]:
            p += 1
            S[i] = S[i].upper()
    if S[-1] == S[0]:
        return r + p * (K - 1)
    return (r + p) * (K // 2) + r * (K % 2)
    main
def main():
    S = [i for i in input()]
    O = S[:]
    K = int(input())
    if len(S) == 1:
        return K // 2
    r = 0
    for i in range(1, len(S)):
        if S[i] == S[i - 1]:
            r += 1
            S[i] = S[i].upper()
    if S[-1] != S[0]:
        return r * K

    S = S + O
    p = 0
    for i in range(len(O), len(S)):
        if S[i] == S[i - 1]:
            p += 1
            S[i] = S[i].upper()
    if S[-1] == S[0]:
        return r + p * (K - 1)
    return (r + p) * (K // 2) + r * (K % 2)
   

print(main())
