S=input()
K=int(input())

L=len(S)

D=[0]*(2*L)

D[0]=1
n=0
for i in range(1,2*L):
    if S[(i-1)%L]==S[i%L]:
        D[i]=D[i-1]+1
        n+=1
    else:
        D[i]=1

X=[]
if D[L-1]==L:
        print((L*K)//2)
else:
    if S[0]==S[-1]:
        f,g=True,False

        i=0
        while f:
            g=g or (S[i]!=S[i+1])
            
            if D[i]>=D[i+1]:
                if g:
                    X.append(D[i])
                    if i>=L-1:
                        f=False
                        
            i+=1

        A=sum(map(lambda n:n//2,X[1:]))*(K-1)+sum(map(lambda n:n//2,X[1:-1]))+(X[0]//2)+(D[L-1]//2)
    
    else:
        for i in range(L):
            if D[i]>D[i+1]:
                X.append(D[i])


        A=sum(map(lambda n:n//2,X))*K

    print(A) S=input() S input() input K=int(input()) K int(input()) int input() input L=len(S) L len(S) len S D=[0]*(2*L) D [0]*(2*L) [0] 0 2*L 2 L D[0]=1 D[0] D 0 1 n=0 n 0 for i in range(1,2*L):
    if S[(i-1)%L]==S[i%L]:
        D[i]=D[i-1]+1
        n+=1
    else:
        D[i]=1 i range(1,2*L) range 1 2*L 2 L if S[(i-1)%L]==S[i%L]:
        D[i]=D[i-1]+1
        n+=1
    else:
        D[i]=1 S[(i-1)%L]==S[i%L] S[(i-1)%L] S (i-1)%L i-1 i 1 L S[i%L] S i%L i L D[i]=D[i-1]+1 D[i] D i D[i-1]+1 D[i-1] D i-1 i 1 1 n+=1 n 1 D[i]=1 D[i] D i 1 X=[] X [] if D[L-1]==L:
        print((L*K)//2)
else:
    if S[0]==S[-1]:
        f,g=True,False

        i=0
        while f:
            g=g or (S[i]!=S[i+1])
            
            if D[i]>=D[i+1]:
                if g:
                    X.append(D[i])
                    if i>=L-1:
                        f=False
                        
            i+=1

        A=sum(map(lambda n:n//2,X[1:]))*(K-1)+sum(map(lambda n:n//2,X[1:-1]))+(X[0]//2)+(D[L-1]//2)
    
    else:
        for i in range(L):
            if D[i]>D[i+1]:
                X.append(D[i])


        A=sum(map(lambda n:n//2,X))*K

    print(A) D[L-1]==L D[L-1] D L-1 L 1 L print((L*K)//2) print (L*K)//2 L*K L K 2 if S[0]==S[-1]:
        f,g=True,False

        i=0
        while f:
            g=g or (S[i]!=S[i+1])
            
            if D[i]>=D[i+1]:
                if g:
                    X.append(D[i])
                    if i>=L-1:
                        f=False
                        
            i+=1

        A=sum(map(lambda n:n//2,X[1:]))*(K-1)+sum(map(lambda n:n//2,X[1:-1]))+(X[0]//2)+(D[L-1]//2)
    
    else:
        for i in range(L):
            if D[i]>D[i+1]:
                X.append(D[i])


        A=sum(map(lambda n:n//2,X))*K

     S[0]==S[-1] S[0] S 0 S[-1] S -1 f,g=True,False f True g False i=0 i 0 while f:
            g=g or (S[i]!=S[i+1])
            
            if D[i]>=D[i+1]:
                if g:
                    X.append(D[i])
                    if i>=L-1:
                        f=False
                        
            i+=1

         f g=g or (S[i]!=S[i+1]) g g or (S[i]!=S[i+1]) g S[i]!=S[i+1] S[i] S i S[i+1] S i+1 i 1 if D[i]>=D[i+1]:
                if g:
                    X.append(D[i])
                    if i>=L-1:
                        f=False
                        
             D[i]>=D[i+1] D[i] D i D[i+1] D i+1 i 1 if g:
                    X.append(D[i])
                    if i>=L-1:
                        f=False
                        
             g X.append(D[i]) X.append X append D[i] D i if i>=L-1:
                        f=False
                        
             i>=L-1 i L-1 L 1 f=False f False i+=1 i 1 A=sum(map(lambda n:n//2,X[1:]))*(K-1)+sum(map(lambda n:n//2,X[1:-1]))+(X[0]//2)+(D[L-1]//2) A sum(map(lambda n:n//2,X[1:]))*(K-1)+sum(map(lambda n:n//2,X[1:-1]))+(X[0]//2)+(D[L-1]//2) sum(map(lambda n:n//2,X[1:]))*(K-1)+sum(map(lambda n:n//2,X[1:-1]))+(X[0]//2) sum(map(lambda n:n//2,X[1:]))*(K-1)+sum(map(lambda n:n//2,X[1:-1])) sum(map(lambda n:n//2,X[1:]))*(K-1) sum(map(lambda n:n//2,X[1:])) sum map(lambda n:n//2,X[1:]) map lambda n:n//2 n//2 n 2 n X[1:] X 1: 1 K-1 K 1 sum(map(lambda n:n//2,X[1:-1])) sum map(lambda n:n//2,X[1:-1]) map lambda n:n//2 n//2 n 2 n X[1:-1] X 1:-1 1 -1 X[0]//2 X[0] X 0 2 D[L-1]//2 D[L-1] D L-1 L 1 2 for i in range(L):
            if D[i]>D[i+1]:
                X.append(D[i])


         i range(L) range L if D[i]>D[i+1]:
                X.append(D[i])


         D[i]>D[i+1] D[i] D i D[i+1] D i+1 i 1 X.append(D[i]) X.append X append D[i] D i A=sum(map(lambda n:n//2,X))*K A sum(map(lambda n:n//2,X))*K sum(map(lambda n:n//2,X)) sum map(lambda n:n//2,X) map lambda n:n//2 n//2 n 2 n X K print(A) print A n+=1 1 n X=[] [] X A=sum(map(lambda n:n//2,X[1:]))*(K-1)+sum(map(lambda n:n//2,X[1:-1]))+(X[0]//2)+(D[L-1]//2) sum(map(lambda n:n//2,X[1:]))*(K-1)+sum(map(lambda n:n//2,X[1:-1]))+(X[0]//2)+(D[L-1]//2) A L=len(S) len(S) L S=input() input() S f=False False f f,g=True,False True f i+=1 1 i A=sum(map(lambda n:n//2,X))*K sum(map(lambda n:n//2,X))*K A i=0 0 i g=True,False False g n=0 0 n D=[0]*(2*L) [0]*(2*L) D K=int(input()) int(input()) K g=g or (S[i]!=S[i+1]) g or (S[i]!=S[i+1]) g
S=input()
K=int(input())

L=len(S)

D=[0]*(2*L)

D[0]=1
n=0
for i in range(1,2*L):
    if S[(i-1)%L]==S[i%L]:
        D[i]=D[i-1]+1
        n+=1
    else:
        D[i]=1

X=[]
if D[L-1]==L:
        print((L*K)//2)
else:
    if S[0]==S[-1]:
        f,g=True,False

        i=0
        while f:
            g=g or (S[i]!=S[i+1])
            
            if D[i]>=D[i+1]:
                if g:
                    X.append(D[i])
                    if i>=L-1:
                        f=False
                        
            i+=1

        A=sum(map(lambda n:n//2,X[1:]))*(K-1)+sum(map(lambda n:n//2,X[1:-1]))+(X[0]//2)+(D[L-1]//2)
    
    else:
        for i in range(L):
            if D[i]>D[i+1]:
                X.append(D[i])


        A=sum(map(lambda n:n//2,X))*K

    print(A)
