def mi():
    return map(int, input().split())

def main():
    S = input()
    K = int(input())
    N = len(S)
    if len(set(S)) == 1:
        print(N*K//2)
    else:
        SS = S+S
        t = ''
        tt = ''
        flg = 0
        for i in range(N):
            if i and t[i-1] == S[i]:
                t += '#'
            else:
                t += S[i]

        for i in range(2*N):
            if i and tt[i-1] == SS[i]:
                tt += '#'
            else:
                tt += SS[i]

        d = tt.count('#')-t.count('#')
        print(t.count('#')+(K-1)*d)

if __name__ == '__main__':
    main() def mi():
    return map(int, input().split()) mi return map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split def main():
    S = input()
    K = int(input())
    N = len(S)
    if len(set(S)) == 1:
        print(N*K//2)
    else:
        SS = S+S
        t = ''
        tt = ''
        flg = 0
        for i in range(N):
            if i and t[i-1] == S[i]:
                t += '#'
            else:
                t += S[i]

        for i in range(2*N):
            if i and tt[i-1] == SS[i]:
                tt += '#'
            else:
                tt += SS[i]

        d = tt.count('#')-t.count('#')
        print(t.count('#')+(K-1)*d) main S = input() S input() input K = int(input()) K int(input()) int input() input N = len(S) N len(S) len S if len(set(S)) == 1:
        print(N*K//2)
    else:
        SS = S+S
        t = ''
        tt = ''
        flg = 0
        for i in range(N):
            if i and t[i-1] == S[i]:
                t += '#'
            else:
                t += S[i]

        for i in range(2*N):
            if i and tt[i-1] == SS[i]:
                tt += '#'
            else:
                tt += SS[i]

        d = tt.count('#')-t.count('#')
        print(t.count('#')+(K-1)*d) len(set(S)) == 1 len(set(S)) len set(S) set S 1 print(N*K//2) print N*K//2 N*K N K 2 SS = S+S SS S+S S S t = '' t '' tt = '' tt '' flg = 0 flg 0 for i in range(N):
            if i and t[i-1] == S[i]:
                t += '#'
            else:
                t += S[i]

         i range(N) range N if i and t[i-1] == S[i]:
                t += '#'
            else:
                t += S[i]

         i and t[i-1] == S[i] i t[i-1] == S[i] t[i-1] t i-1 i 1 S[i] S i t += '#' t '#' t += S[i] t S[i] S i for i in range(2*N):
            if i and tt[i-1] == SS[i]:
                tt += '#'
            else:
                tt += SS[i]

         i range(2*N) range 2*N 2 N if i and tt[i-1] == SS[i]:
                tt += '#'
            else:
                tt += SS[i]

         i and tt[i-1] == SS[i] i tt[i-1] == SS[i] tt[i-1] tt i-1 i 1 SS[i] SS i tt += '#' tt '#' tt += SS[i] tt SS[i] SS i d = tt.count('#')-t.count('#') d tt.count('#')-t.count('#') tt.count('#') tt.count tt count '#' t.count('#') t.count t count '#' print(t.count('#')+(K-1)*d) print t.count('#')+(K-1)*d t.count('#') t.count t count '#' (K-1)*d K-1 K 1 d if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def mi():
    return map(int, input().split()) def mi():
    return map(int, input().split()) mi def main():
    S = input()
    K = int(input())
    N = len(S)
    if len(set(S)) == 1:
        print(N*K//2)
    else:
        SS = S+S
        t = ''
        tt = ''
        flg = 0
        for i in range(N):
            if i and t[i-1] == S[i]:
                t += '#'
            else:
                t += S[i]

        for i in range(2*N):
            if i and tt[i-1] == SS[i]:
                tt += '#'
            else:
                tt += SS[i]

        d = tt.count('#')-t.count('#')
        print(t.count('#')+(K-1)*d) def main():
    S = input()
    K = int(input())
    N = len(S)
    if len(set(S)) == 1:
        print(N*K//2)
    else:
        SS = S+S
        t = ''
        tt = ''
        flg = 0
        for i in range(N):
            if i and t[i-1] == S[i]:
                t += '#'
            else:
                t += S[i]

        for i in range(2*N):
            if i and tt[i-1] == SS[i]:
                tt += '#'
            else:
                tt += SS[i]

        d = tt.count('#')-t.count('#')
        print(t.count('#')+(K-1)*d) main
def mi():
    return map(int, input().split())

def main():
    S = input()
    K = int(input())
    N = len(S)
    if len(set(S)) == 1:
        print(N*K//2)
    else:
        SS = S+S
        t = ''
        tt = ''
        flg = 0
        for i in range(N):
            if i and t[i-1] == S[i]:
                t += '#'
            else:
                t += S[i]

        for i in range(2*N):
            if i and tt[i-1] == SS[i]:
                tt += '#'
            else:
                tt += SS[i]

        d = tt.count('#')-t.count('#')
        print(t.count('#')+(K-1)*d)

if __name__ == '__main__':
    main()
