import sys
input = sys.stdin.readline


def main():
    S = input().rstrip()
    K = int(input())

    N = len(S)
    if S == S[0] * N:
        ans = (N * K) // 2
    elif S[0] == S[-1]:
        a = 1
        for i in range(N):
            if S[i] == S[i+1]:
                a += 1
            else:
                break
        b = 1
        for i in reversed(range(N)):
            if S[i-1] == S[i]:
                b += 1
            else:
                break
        seq = 1
        ans = 0
        for i in range(a, N-b):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K
        ans += a//2
        ans += (a+b)//2 * (K-1)
        ans += b//2
    else:
        seq = 1
        ans = 0
        for i in range(N-1):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K

    print(ans)


if __name__ == "__main__":
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    S = input().rstrip()
    K = int(input())

    N = len(S)
    if S == S[0] * N:
        ans = (N * K) // 2
    elif S[0] == S[-1]:
        a = 1
        for i in range(N):
            if S[i] == S[i+1]:
                a += 1
            else:
                break
        b = 1
        for i in reversed(range(N)):
            if S[i-1] == S[i]:
                b += 1
            else:
                break
        seq = 1
        ans = 0
        for i in range(a, N-b):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K
        ans += a//2
        ans += (a+b)//2 * (K-1)
        ans += b//2
    else:
        seq = 1
        ans = 0
        for i in range(N-1):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K

    print(ans) main S = input().rstrip() S input().rstrip() ().rstrip () input rstrip K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S if S == S[0] * N:
        ans = (N * K) // 2
    elif S[0] == S[-1]:
        a = 1
        for i in range(N):
            if S[i] == S[i+1]:
                a += 1
            else:
                break
        b = 1
        for i in reversed(range(N)):
            if S[i-1] == S[i]:
                b += 1
            else:
                break
        seq = 1
        ans = 0
        for i in range(a, N-b):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K
        ans += a//2
        ans += (a+b)//2 * (K-1)
        ans += b//2
    else:
        seq = 1
        ans = 0
        for i in range(N-1):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K

     S == S[0] * N S S[0] * N S[0] S 0 N ans = (N * K) // 2 ans (N * K) // 2 N * K N K 2 elif S[0] == S[-1]:
        a = 1
        for i in range(N):
            if S[i] == S[i+1]:
                a += 1
            else:
                break
        b = 1
        for i in reversed(range(N)):
            if S[i-1] == S[i]:
                b += 1
            else:
                break
        seq = 1
        ans = 0
        for i in range(a, N-b):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K
        ans += a//2
        ans += (a+b)//2 * (K-1)
        ans += b//2
     S[0] == S[-1] S[0] S 0 S[-1] S -1 a = 1 a 1 for i in range(N):
            if S[i] == S[i+1]:
                a += 1
            else:
                break
         i range(N) range N if S[i] == S[i+1]:
                a += 1
            else:
                break
         S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 a += 1 a 1 break b = 1 b 1 for i in reversed(range(N)):
            if S[i-1] == S[i]:
                b += 1
            else:
                break
         i reversed(range(N)) reversed range(N) range N if S[i-1] == S[i]:
                b += 1
            else:
                break
         S[i-1] == S[i] S[i-1] S i-1 i 1 S[i] S i b += 1 b 1 break seq = 1 seq 1 ans = 0 ans 0 for i in range(a, N-b):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
         i range(a, N-b) range a N-b N b if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
         S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 seq += 1 seq 1 elif seq > 1:
                ans += seq//2
                seq = 1
         seq > 1 seq 1 ans += seq//2 ans seq//2 seq 2 seq = 1 seq 1 if seq > 1:
            ans += seq//2
         seq > 1 seq 1 ans += seq//2 ans seq//2 seq 2 ans *= K ans K ans += a//2 ans a//2 a 2 ans += (a+b)//2 * (K-1) ans (a+b)//2 * (K-1) (a+b)//2 a+b a b 2 K-1 K 1 ans += b//2 ans b//2 b 2 seq = 1 seq 1 ans = 0 ans 0 for i in range(N-1):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
         i range(N-1) range N-1 N 1 if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
         S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 seq += 1 seq 1 elif seq > 1:
                ans += seq//2
                seq = 1
         seq > 1 seq 1 ans += seq//2 ans seq//2 seq 2 seq = 1 seq 1 if seq > 1:
            ans += seq//2
         seq > 1 seq 1 ans += seq//2 ans seq//2 seq 2 ans *= K ans K print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    S = input().rstrip()
    K = int(input())

    N = len(S)
    if S == S[0] * N:
        ans = (N * K) // 2
    elif S[0] == S[-1]:
        a = 1
        for i in range(N):
            if S[i] == S[i+1]:
                a += 1
            else:
                break
        b = 1
        for i in reversed(range(N)):
            if S[i-1] == S[i]:
                b += 1
            else:
                break
        seq = 1
        ans = 0
        for i in range(a, N-b):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K
        ans += a//2
        ans += (a+b)//2 * (K-1)
        ans += b//2
    else:
        seq = 1
        ans = 0
        for i in range(N-1):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K

    print(ans) def main():
    S = input().rstrip()
    K = int(input())

    N = len(S)
    if S == S[0] * N:
        ans = (N * K) // 2
    elif S[0] == S[-1]:
        a = 1
        for i in range(N):
            if S[i] == S[i+1]:
                a += 1
            else:
                break
        b = 1
        for i in reversed(range(N)):
            if S[i-1] == S[i]:
                b += 1
            else:
                break
        seq = 1
        ans = 0
        for i in range(a, N-b):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K
        ans += a//2
        ans += (a+b)//2 * (K-1)
        ans += b//2
    else:
        seq = 1
        ans = 0
        for i in range(N-1):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K

    print(ans) main input = sys.stdin.readline sys.stdin.readline input
import sys
input = sys.stdin.readline


def main():
    S = input().rstrip()
    K = int(input())

    N = len(S)
    if S == S[0] * N:
        ans = (N * K) // 2
    elif S[0] == S[-1]:
        a = 1
        for i in range(N):
            if S[i] == S[i+1]:
                a += 1
            else:
                break
        b = 1
        for i in reversed(range(N)):
            if S[i-1] == S[i]:
                b += 1
            else:
                break
        seq = 1
        ans = 0
        for i in range(a, N-b):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K
        ans += a//2
        ans += (a+b)//2 * (K-1)
        ans += b//2
    else:
        seq = 1
        ans = 0
        for i in range(N-1):
            if S[i] == S[i+1]:
                seq += 1
            elif seq > 1:
                ans += seq//2
                seq = 1
        if seq > 1:
            ans += seq//2
        ans *= K

    print(ans)


if __name__ == "__main__":
    main()
