def main():
    S = list(input())
    K = int(input())
    cnt = 0
    if K == 1:
        T = S
        for i in range(len(T)-1):
            if T[i] == T[i+1]:
                T[i+1] = '.'
        ans = T.count('.')
        print(ans)
        return

    if len(S) == 1:
        ans = max(0, (K - (K%2==1))//2)
        print(ans)
        return

    if len(set(S)) == 1:
        tmp = len(S)*K
        tmp = tmp - (tmp%2 == 1)
        ans = tmp//2
        print(ans)
        return

    T3 = S + S + S
    for i in range(len(T3)-1):
        if T3[i] == T3[i+1]:
            T3[i+1] = '.'
    
    T2aster = T3[len(S):(2*len(S))].count('.')
    T3aster = T3.count('.')
    ans = T3aster + T2aster * (K-3)
    print(ans)

if __name__ == "__main__":
    main() def main():
    S = list(input())
    K = int(input())
    cnt = 0
    if K == 1:
        T = S
        for i in range(len(T)-1):
            if T[i] == T[i+1]:
                T[i+1] = '.'
        ans = T.count('.')
        print(ans)
        return

    if len(S) == 1:
        ans = max(0, (K - (K%2==1))//2)
        print(ans)
        return

    if len(set(S)) == 1:
        tmp = len(S)*K
        tmp = tmp - (tmp%2 == 1)
        ans = tmp//2
        print(ans)
        return

    T3 = S + S + S
    for i in range(len(T3)-1):
        if T3[i] == T3[i+1]:
            T3[i+1] = '.'
    
    T2aster = T3[len(S):(2*len(S))].count('.')
    T3aster = T3.count('.')
    ans = T3aster + T2aster * (K-3)
    print(ans) main S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input cnt = 0 cnt 0 if K == 1:
        T = S
        for i in range(len(T)-1):
            if T[i] == T[i+1]:
                T[i+1] = '.'
        ans = T.count('.')
        print(ans)
        return

     K == 1 K 1 T = S T S for i in range(len(T)-1):
            if T[i] == T[i+1]:
                T[i+1] = '.'
         i range(len(T)-1) range len(T)-1 len(T) len T 1 if T[i] == T[i+1]:
                T[i+1] = '.'
         T[i] == T[i+1] T[i] T i T[i+1] T i+1 i 1 T[i+1] = '.' T[i+1] T i+1 i 1 '.' ans = T.count('.') ans T.count('.') T.count T count '.' print(ans) print ans return if len(S) == 1:
        ans = max(0, (K - (K%2==1))//2)
        print(ans)
        return

     len(S) == 1 len(S) len S 1 ans = max(0, (K - (K%2==1))//2) ans max(0, (K - (K%2==1))//2) max 0 (K - (K%2==1))//2 K - (K%2==1) K K%2==1 K%2 K 2 1 2 print(ans) print ans return if len(set(S)) == 1:
        tmp = len(S)*K
        tmp = tmp - (tmp%2 == 1)
        ans = tmp//2
        print(ans)
        return

     len(set(S)) == 1 len(set(S)) len set(S) set S 1 tmp = len(S)*K tmp len(S)*K len(S) len S K tmp = tmp - (tmp%2 == 1) tmp tmp - (tmp%2 == 1) tmp tmp%2 == 1 tmp%2 tmp 2 1 ans = tmp//2 ans tmp//2 tmp 2 print(ans) print ans return T3 = S + S + S T3 S + S + S S + S S S S for i in range(len(T3)-1):
        if T3[i] == T3[i+1]:
            T3[i+1] = '.'
    
     i range(len(T3)-1) range len(T3)-1 len(T3) len T3 1 if T3[i] == T3[i+1]:
            T3[i+1] = '.'
    
     T3[i] == T3[i+1] T3[i] T3 i T3[i+1] T3 i+1 i 1 T3[i+1] = '.' T3[i+1] T3 i+1 i 1 '.' T2aster = T3[len(S):(2*len(S))].count('.') T2aster T3[len(S):(2*len(S))].count('.') [len(S):(2*len(S))].count [len(S):(2*len(S))] T3 len(S):(2*len(S)) len(S) len S 2*len(S) 2 len(S) len S count '.' T3aster = T3.count('.') T3aster T3.count('.') T3.count T3 count '.' ans = T3aster + T2aster * (K-3) ans T3aster + T2aster * (K-3) T3aster T2aster * (K-3) T2aster K-3 K 3 print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    S = list(input())
    K = int(input())
    cnt = 0
    if K == 1:
        T = S
        for i in range(len(T)-1):
            if T[i] == T[i+1]:
                T[i+1] = '.'
        ans = T.count('.')
        print(ans)
        return

    if len(S) == 1:
        ans = max(0, (K - (K%2==1))//2)
        print(ans)
        return

    if len(set(S)) == 1:
        tmp = len(S)*K
        tmp = tmp - (tmp%2 == 1)
        ans = tmp//2
        print(ans)
        return

    T3 = S + S + S
    for i in range(len(T3)-1):
        if T3[i] == T3[i+1]:
            T3[i+1] = '.'
    
    T2aster = T3[len(S):(2*len(S))].count('.')
    T3aster = T3.count('.')
    ans = T3aster + T2aster * (K-3)
    print(ans) def main():
    S = list(input())
    K = int(input())
    cnt = 0
    if K == 1:
        T = S
        for i in range(len(T)-1):
            if T[i] == T[i+1]:
                T[i+1] = '.'
        ans = T.count('.')
        print(ans)
        return

    if len(S) == 1:
        ans = max(0, (K - (K%2==1))//2)
        print(ans)
        return

    if len(set(S)) == 1:
        tmp = len(S)*K
        tmp = tmp - (tmp%2 == 1)
        ans = tmp//2
        print(ans)
        return

    T3 = S + S + S
    for i in range(len(T3)-1):
        if T3[i] == T3[i+1]:
            T3[i+1] = '.'
    
    T2aster = T3[len(S):(2*len(S))].count('.')
    T3aster = T3.count('.')
    ans = T3aster + T2aster * (K-3)
    print(ans) main
def main():
    S = list(input())
    K = int(input())
    cnt = 0
    if K == 1:
        T = S
        for i in range(len(T)-1):
            if T[i] == T[i+1]:
                T[i+1] = '.'
        ans = T.count('.')
        print(ans)
        return

    if len(S) == 1:
        ans = max(0, (K - (K%2==1))//2)
        print(ans)
        return

    if len(set(S)) == 1:
        tmp = len(S)*K
        tmp = tmp - (tmp%2 == 1)
        ans = tmp//2
        print(ans)
        return

    T3 = S + S + S
    for i in range(len(T3)-1):
        if T3[i] == T3[i+1]:
            T3[i+1] = '.'
    
    T2aster = T3[len(S):(2*len(S))].count('.')
    T3aster = T3.count('.')
    ans = T3aster + T2aster * (K-3)
    print(ans)

if __name__ == "__main__":
    main()
