def f(S):
    all_cnt = 0
    cnt = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            if cnt > 0:
                if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
            cnt = 0
        # print(cnt,all_cnt)
    if cnt > 0:
        if cnt % 2 == 1:
            all_cnt += (cnt + 1) / 2
        else:
            all_cnt += cnt / 2
    return int(all_cnt)

def main():
    S = input()
    K = int(input())
    if S.count(S[0]) == len(S):
        print(len(S)*K // 2)
        return
    if S[-1] == S[0]:
        print((f(S + S) - f(S))*(K-1) + f(S))
    else:
        print(f(S)*K)

if __name__ == '__main__':
    main() def f(S):
    all_cnt = 0
    cnt = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            if cnt > 0:
                if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
            cnt = 0
        # print(cnt,all_cnt)
    if cnt > 0:
        if cnt % 2 == 1:
            all_cnt += (cnt + 1) / 2
        else:
            all_cnt += cnt / 2
    return int(all_cnt) f all_cnt = 0 all_cnt 0 cnt = 0 cnt 0 for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            if cnt > 0:
                if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
            cnt = 0
        # print(cnt,all_cnt)
     i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i] == S[i+1]:
            cnt += 1
        else:
            if cnt > 0:
                if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
            cnt = 0
        # print(cnt,all_cnt)
     S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 cnt += 1 cnt 1 if cnt > 0:
                if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
             cnt > 0 cnt 0 if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
             cnt % 2 == 1 cnt % 2 cnt 2 1 all_cnt += (cnt + 1) / 2 all_cnt (cnt + 1) / 2 cnt + 1 cnt 1 2 all_cnt += cnt / 2 all_cnt cnt / 2 cnt 2 cnt = 0 cnt 0 if cnt > 0:
        if cnt % 2 == 1:
            all_cnt += (cnt + 1) / 2
        else:
            all_cnt += cnt / 2
     cnt > 0 cnt 0 if cnt % 2 == 1:
            all_cnt += (cnt + 1) / 2
        else:
            all_cnt += cnt / 2
     cnt % 2 == 1 cnt % 2 cnt 2 1 all_cnt += (cnt + 1) / 2 all_cnt (cnt + 1) / 2 cnt + 1 cnt 1 2 all_cnt += cnt / 2 all_cnt cnt / 2 cnt 2 return int(all_cnt) int(all_cnt) int all_cnt S S def main():
    S = input()
    K = int(input())
    if S.count(S[0]) == len(S):
        print(len(S)*K // 2)
        return
    if S[-1] == S[0]:
        print((f(S + S) - f(S))*(K-1) + f(S))
    else:
        print(f(S)*K) main S = input() S input() input K = int(input()) K int(input()) int input() input if S.count(S[0]) == len(S):
        print(len(S)*K // 2)
        return
     S.count(S[0]) == len(S) S.count(S[0]) S.count S count S[0] S 0 len(S) len S print(len(S)*K // 2) print len(S)*K // 2 len(S)*K len(S) len S K 2 return if S[-1] == S[0]:
        print((f(S + S) - f(S))*(K-1) + f(S))
    else:
        print(f(S)*K) S[-1] == S[0] S[-1] S -1 S[0] S 0 print((f(S + S) - f(S))*(K-1) + f(S)) print (f(S + S) - f(S))*(K-1) + f(S) (f(S + S) - f(S))*(K-1) f(S + S) - f(S) f(S + S) f S + S S S f(S) f S K-1 K 1 f(S) f S print(f(S)*K) print f(S)*K f(S) f S K if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def f(S):
    all_cnt = 0
    cnt = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            if cnt > 0:
                if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
            cnt = 0
        # print(cnt,all_cnt)
    if cnt > 0:
        if cnt % 2 == 1:
            all_cnt += (cnt + 1) / 2
        else:
            all_cnt += cnt / 2
    return int(all_cnt) def f(S):
    all_cnt = 0
    cnt = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            if cnt > 0:
                if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
            cnt = 0
        # print(cnt,all_cnt)
    if cnt > 0:
        if cnt % 2 == 1:
            all_cnt += (cnt + 1) / 2
        else:
            all_cnt += cnt / 2
    return int(all_cnt) f def main():
    S = input()
    K = int(input())
    if S.count(S[0]) == len(S):
        print(len(S)*K // 2)
        return
    if S[-1] == S[0]:
        print((f(S + S) - f(S))*(K-1) + f(S))
    else:
        print(f(S)*K) def main():
    S = input()
    K = int(input())
    if S.count(S[0]) == len(S):
        print(len(S)*K // 2)
        return
    if S[-1] == S[0]:
        print((f(S + S) - f(S))*(K-1) + f(S))
    else:
        print(f(S)*K) main
def f(S):
    all_cnt = 0
    cnt = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            if cnt > 0:
                if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
            cnt = 0
        # print(cnt,all_cnt)
    if cnt > 0:
        if cnt % 2 == 1:
            all_cnt += (cnt + 1) / 2
        else:
            all_cnt += cnt / 2
    return int(all_cnt)

def main():
    S = input()
    K = int(input())
    if S.count(S[0]) == len(S):
        print(len(S)*K // 2)
        return
    if S[-1] == S[0]:
        print((f(S + S) - f(S))*(K-1) + f(S))
    else:
        print(f(S)*K)

if __name__ == '__main__':
    main()