S=input()
K=int(input())
ans=0
last=S[0]
cnt=1
if len(set(S))>1:
    for i in range(1,len(S)):
        if S[i]==last:
            cnt+=1
        else:
            ans+=cnt//2
            cnt=1
            last=S[i]
    ans+=cnt//2
    ans*=K
    if S[0]==S[-1]:
        a,b=0,0
        last=S[0]
        for i in range(len(S)):
            if last==S[i]:
                a+=1
            else:
                break
        S=S[::-1]
        for i in range(len(S)):
            if last==S[i]:
                b+=1
            else:
                break
        ans-=(a//2+b//2-(a+b)//2)*(K-1)
else:
    ans=len(S)*K//2
print(ans) S=input() S input() input K=int(input()) K int(input()) int input() input ans=0 ans 0 last=S[0] last S[0] S 0 cnt=1 cnt 1 if len(set(S))>1:
    for i in range(1,len(S)):
        if S[i]==last:
            cnt+=1
        else:
            ans+=cnt//2
            cnt=1
            last=S[i]
    ans+=cnt//2
    ans*=K
    if S[0]==S[-1]:
        a,b=0,0
        last=S[0]
        for i in range(len(S)):
            if last==S[i]:
                a+=1
            else:
                break
        S=S[::-1]
        for i in range(len(S)):
            if last==S[i]:
                b+=1
            else:
                break
        ans-=(a//2+b//2-(a+b)//2)*(K-1)
else:
    ans=len(S)*K//2 len(set(S))>1 len(set(S)) len set(S) set S 1 for i in range(1,len(S)):
        if S[i]==last:
            cnt+=1
        else:
            ans+=cnt//2
            cnt=1
            last=S[i]
     i range(1,len(S)) range 1 len(S) len S if S[i]==last:
            cnt+=1
        else:
            ans+=cnt//2
            cnt=1
            last=S[i]
     S[i]==last S[i] S i last cnt+=1 cnt 1 ans+=cnt//2 ans cnt//2 cnt 2 cnt=1 cnt 1 last=S[i] last S[i] S i ans+=cnt//2 ans cnt//2 cnt 2 ans*=K ans K if S[0]==S[-1]:
        a,b=0,0
        last=S[0]
        for i in range(len(S)):
            if last==S[i]:
                a+=1
            else:
                break
        S=S[::-1]
        for i in range(len(S)):
            if last==S[i]:
                b+=1
            else:
                break
        ans-=(a//2+b//2-(a+b)//2)*(K-1) S[0]==S[-1] S[0] S 0 S[-1] S -1 a,b=0,0 a 0 b 0 last=S[0] last S[0] S 0 for i in range(len(S)):
            if last==S[i]:
                a+=1
            else:
                break
         i range(len(S)) range len(S) len S if last==S[i]:
                a+=1
            else:
                break
         last==S[i] last S[i] S i a+=1 a 1 break S=S[::-1] S S[::-1] S ::-1 -1 for i in range(len(S)):
            if last==S[i]:
                b+=1
            else:
                break
         i range(len(S)) range len(S) len S if last==S[i]:
                b+=1
            else:
                break
         last==S[i] last S[i] S i b+=1 b 1 break ans-=(a//2+b//2-(a+b)//2)*(K-1) ans (a//2+b//2-(a+b)//2)*(K-1) a//2+b//2-(a+b)//2 a//2+b//2 a//2 a 2 b//2 b 2 (a+b)//2 a+b a b 2 K-1 K 1 ans=len(S)*K//2 ans len(S)*K//2 len(S)*K len(S) len S K 2 print(ans) print ans ans*=K K ans cnt+=1 1 cnt S=S[::-1] S[::-1] S S=input() input() S ans=0 0 ans last=S[i] S[i] last ans+=cnt//2 cnt//2 ans a,b=0,0 0 a a+=1 1 a last=S[0] S[0] last b+=1 1 b ans=len(S)*K//2 len(S)*K//2 ans cnt=1 1 cnt ans-=(a//2+b//2-(a+b)//2)*(K-1) (a//2+b//2-(a+b)//2)*(K-1) ans b=0,0 0 b ans+=cnt//2 cnt//2 ans last=S[0] S[0] last K=int(input()) int(input()) K cnt=1 1 cnt
S=input()
K=int(input())
ans=0
last=S[0]
cnt=1
if len(set(S))>1:
    for i in range(1,len(S)):
        if S[i]==last:
            cnt+=1
        else:
            ans+=cnt//2
            cnt=1
            last=S[i]
    ans+=cnt//2
    ans*=K
    if S[0]==S[-1]:
        a,b=0,0
        last=S[0]
        for i in range(len(S)):
            if last==S[i]:
                a+=1
            else:
                break
        S=S[::-1]
        for i in range(len(S)):
            if last==S[i]:
                b+=1
            else:
                break
        ans-=(a//2+b//2-(a+b)//2)*(K-1)
else:
    ans=len(S)*K//2
print(ans)