import sys
input = sys.stdin.readline
def main():
    S = input().rstrip()
    K = int(input())
    if len(set(S)) == 1:
        ans = len(S)*K //2 
        print(ans)
        return
    CNT = 1
    ans = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            CNT += 1
        else:
            ans += CNT//2
            CNT = 1
    ans += CNT//2

    if S[0] != S[len(S)-1]:
        print(ans*K)
    else:
        ans2 = 0
        CNT = 1
        SS = S + S
        for i in range(len(SS)-1):
            if SS[i] == SS[i+1]:
                CNT += 1
            else:
                ans2 += CNT//2
                CNT = 1
        ans2 += CNT//2
        # print(ans*(K-1))
        print(ans*K + (ans2-ans*2)*(K-1))

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())
    if len(set(S)) == 1:
        ans = len(S)*K //2 
        print(ans)
        return
    CNT = 1
    ans = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            CNT += 1
        else:
            ans += CNT//2
            CNT = 1
    ans += CNT//2

    if S[0] != S[len(S)-1]:
        print(ans*K)
    else:
        ans2 = 0
        CNT = 1
        SS = S + S
        for i in range(len(SS)-1):
            if SS[i] == SS[i+1]:
                CNT += 1
            else:
                ans2 += CNT//2
                CNT = 1
        ans2 += CNT//2
        # print(ans*(K-1))
        print(ans*K + (ans2-ans*2)*(K-1)) main S = input().rstrip() S input().rstrip() ().rstrip () input rstrip K = int(input()) K int(input()) int input() input if len(set(S)) == 1:
        ans = len(S)*K //2 
        print(ans)
        return
     len(set(S)) == 1 len(set(S)) len set(S) set S 1 ans = len(S)*K //2 ans len(S)*K //2 len(S)*K len(S) len S K 2 print(ans) print ans return CNT = 1 CNT 1 ans = 0 ans 0 for i in range(len(S)-1):
        if S[i] == S[i+1]:
            CNT += 1
        else:
            ans += CNT//2
            CNT = 1
     i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i] == S[i+1]:
            CNT += 1
        else:
            ans += CNT//2
            CNT = 1
     S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 CNT += 1 CNT 1 ans += CNT//2 ans CNT//2 CNT 2 CNT = 1 CNT 1 ans += CNT//2 ans CNT//2 CNT 2 if S[0] != S[len(S)-1]:
        print(ans*K)
    else:
        ans2 = 0
        CNT = 1
        SS = S + S
        for i in range(len(SS)-1):
            if SS[i] == SS[i+1]:
                CNT += 1
            else:
                ans2 += CNT//2
                CNT = 1
        ans2 += CNT//2
        # print(ans*(K-1))
        print(ans*K + (ans2-ans*2)*(K-1)) S[0] != S[len(S)-1] S[0] S 0 S[len(S)-1] S len(S)-1 len(S) len S 1 print(ans*K) print ans*K ans K ans2 = 0 ans2 0 CNT = 1 CNT 1 SS = S + S SS S + S S S for i in range(len(SS)-1):
            if SS[i] == SS[i+1]:
                CNT += 1
            else:
                ans2 += CNT//2
                CNT = 1
         i range(len(SS)-1) range len(SS)-1 len(SS) len SS 1 if SS[i] == SS[i+1]:
                CNT += 1
            else:
                ans2 += CNT//2
                CNT = 1
         SS[i] == SS[i+1] SS[i] SS i SS[i+1] SS i+1 i 1 CNT += 1 CNT 1 ans2 += CNT//2 ans2 CNT//2 CNT 2 CNT = 1 CNT 1 ans2 += CNT//2 ans2 CNT//2 CNT 2 print(ans*K + (ans2-ans*2)*(K-1)) print ans*K + (ans2-ans*2)*(K-1) ans*K ans K (ans2-ans*2)*(K-1) ans2-ans*2 ans2 ans*2 ans 2 K-1 K 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    S = input().rstrip()
    K = int(input())
    if len(set(S)) == 1:
        ans = len(S)*K //2 
        print(ans)
        return
    CNT = 1
    ans = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            CNT += 1
        else:
            ans += CNT//2
            CNT = 1
    ans += CNT//2

    if S[0] != S[len(S)-1]:
        print(ans*K)
    else:
        ans2 = 0
        CNT = 1
        SS = S + S
        for i in range(len(SS)-1):
            if SS[i] == SS[i+1]:
                CNT += 1
            else:
                ans2 += CNT//2
                CNT = 1
        ans2 += CNT//2
        # print(ans*(K-1))
        print(ans*K + (ans2-ans*2)*(K-1)) def main():
    S = input().rstrip()
    K = int(input())
    if len(set(S)) == 1:
        ans = len(S)*K //2 
        print(ans)
        return
    CNT = 1
    ans = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            CNT += 1
        else:
            ans += CNT//2
            CNT = 1
    ans += CNT//2

    if S[0] != S[len(S)-1]:
        print(ans*K)
    else:
        ans2 = 0
        CNT = 1
        SS = S + S
        for i in range(len(SS)-1):
            if SS[i] == SS[i+1]:
                CNT += 1
            else:
                ans2 += CNT//2
                CNT = 1
        ans2 += CNT//2
        # print(ans*(K-1))
        print(ans*K + (ans2-ans*2)*(K-1)) main input = sys.stdin.readline sys.stdin.readline input
import sys
input = sys.stdin.readline
def main():
    S = input().rstrip()
    K = int(input())
    if len(set(S)) == 1:
        ans = len(S)*K //2 
        print(ans)
        return
    CNT = 1
    ans = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            CNT += 1
        else:
            ans += CNT//2
            CNT = 1
    ans += CNT//2

    if S[0] != S[len(S)-1]:
        print(ans*K)
    else:
        ans2 = 0
        CNT = 1
        SS = S + S
        for i in range(len(SS)-1):
            if SS[i] == SS[i+1]:
                CNT += 1
            else:
                ans2 += CNT//2
                CNT = 1
        ans2 += CNT//2
        # print(ans*(K-1))
        print(ans*K + (ans2-ans*2)*(K-1))

if __name__ == '__main__':
    main()