def main():
    S = input()
    k = int(input())
    if len(set(list(S))) == 1:
        print(len(S) * k // 2)
        exit()
    A = []
    cnt = 1
    tmp = S[0]
    for s in S[1::]:
        if s == tmp:
            cnt += 1
        else:
            A.append(cnt)
            tmp = s
            cnt = 1
    A.append(cnt)
    ans = sum([a // 2 for a in A])
    if S[0] == S[-1]:
        A[0] += A[-1]
        A.pop()
    ans += sum([a // 2 for a in A]) * (k - 1)
    print(ans)

if __name__ == '__main__':
    main() def main():
    S = input()
    k = int(input())
    if len(set(list(S))) == 1:
        print(len(S) * k // 2)
        exit()
    A = []
    cnt = 1
    tmp = S[0]
    for s in S[1::]:
        if s == tmp:
            cnt += 1
        else:
            A.append(cnt)
            tmp = s
            cnt = 1
    A.append(cnt)
    ans = sum([a // 2 for a in A])
    if S[0] == S[-1]:
        A[0] += A[-1]
        A.pop()
    ans += sum([a // 2 for a in A]) * (k - 1)
    print(ans) main S = input() S input() input k = int(input()) k int(input()) int input() input if len(set(list(S))) == 1:
        print(len(S) * k // 2)
        exit()
     len(set(list(S))) == 1 len(set(list(S))) len set(list(S)) set list(S) list S 1 print(len(S) * k // 2) print len(S) * k // 2 len(S) * k len(S) len S k 2 exit() exit A = [] A [] cnt = 1 cnt 1 tmp = S[0] tmp S[0] S 0 for s in S[1::]:
        if s == tmp:
            cnt += 1
        else:
            A.append(cnt)
            tmp = s
            cnt = 1
     s S[1::] S 1:: 1 if s == tmp:
            cnt += 1
        else:
            A.append(cnt)
            tmp = s
            cnt = 1
     s == tmp s tmp cnt += 1 cnt 1 A.append(cnt) A.append A append cnt tmp = s tmp s cnt = 1 cnt 1 A.append(cnt) A.append A append cnt a // 2 for a in A for a in A a A for a in A a // 2 a 2 ans = sum([a // 2 for a in A]) ans sum([a // 2 for a in A]) sum [a // 2 for a in A] if S[0] == S[-1]:
        A[0] += A[-1]
        A.pop()
     S[0] == S[-1] S[0] S 0 S[-1] S -1 A[0] += A[-1] A[0] A 0 A[-1] A -1 A.pop() A.pop A pop a // 2 for a in A for a in A a A for a in A a // 2 a 2 ans += sum([a // 2 for a in A]) * (k - 1) ans sum([a // 2 for a in A]) * (k - 1) sum([a // 2 for a in A]) sum [a // 2 for a in A] k - 1 k 1 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    S = input()
    k = int(input())
    if len(set(list(S))) == 1:
        print(len(S) * k // 2)
        exit()
    A = []
    cnt = 1
    tmp = S[0]
    for s in S[1::]:
        if s == tmp:
            cnt += 1
        else:
            A.append(cnt)
            tmp = s
            cnt = 1
    A.append(cnt)
    ans = sum([a // 2 for a in A])
    if S[0] == S[-1]:
        A[0] += A[-1]
        A.pop()
    ans += sum([a // 2 for a in A]) * (k - 1)
    print(ans) def main():
    S = input()
    k = int(input())
    if len(set(list(S))) == 1:
        print(len(S) * k // 2)
        exit()
    A = []
    cnt = 1
    tmp = S[0]
    for s in S[1::]:
        if s == tmp:
            cnt += 1
        else:
            A.append(cnt)
            tmp = s
            cnt = 1
    A.append(cnt)
    ans = sum([a // 2 for a in A])
    if S[0] == S[-1]:
        A[0] += A[-1]
        A.pop()
    ans += sum([a // 2 for a in A]) * (k - 1)
    print(ans) main
def main():
    S = input()
    k = int(input())
    if len(set(list(S))) == 1:
        print(len(S) * k // 2)
        exit()
    A = []
    cnt = 1
    tmp = S[0]
    for s in S[1::]:
        if s == tmp:
            cnt += 1
        else:
            A.append(cnt)
            tmp = s
            cnt = 1
    A.append(cnt)
    ans = sum([a // 2 for a in A])
    if S[0] == S[-1]:
        A[0] += A[-1]
        A.pop()
    ans += sum([a // 2 for a in A]) * (k - 1)
    print(ans)

if __name__ == '__main__':
    main()
