S=input()
N=len(S)
K=int(input())
s="".join((S,S))
cnt1=0
cnt2=0
buf=0
piv=""
if len(set(S))!=1:
    for i in range(N):
        if S[i]==piv:
            buf=buf+1
        else:
            piv=S[i]
            cnt1=cnt1+(buf+1)//2
            buf=0
    cnt1=cnt1+(buf+1)//2
    buf=0
    piv=""
    for i in range(2*N):
        if s[i]==piv:
            buf=buf+1
        else:
            piv=s[i]
            cnt2=cnt2+(buf+1)//2
            buf=0
    #print(buf)
    cnt2 = cnt2 + (buf + 1) // 2
    x = cnt2 - cnt1
    print(cnt1 + (K - 1) * x)
else:
    print((len(S)*K)//2) S=input() S input() input N=len(S) N len(S) len S K=int(input()) K int(input()) int input() input s="".join((S,S)) s "".join((S,S)) "".join "" join (S,S) S S cnt1=0 cnt1 0 cnt2=0 cnt2 0 buf=0 buf 0 piv="" piv "" if len(set(S))!=1:
    for i in range(N):
        if S[i]==piv:
            buf=buf+1
        else:
            piv=S[i]
            cnt1=cnt1+(buf+1)//2
            buf=0
    cnt1=cnt1+(buf+1)//2
    buf=0
    piv=""
    for i in range(2*N):
        if s[i]==piv:
            buf=buf+1
        else:
            piv=s[i]
            cnt2=cnt2+(buf+1)//2
            buf=0
    #print(buf)
    cnt2 = cnt2 + (buf + 1) // 2
    x = cnt2 - cnt1
    print(cnt1 + (K - 1) * x)
else:
    print((len(S)*K)//2) len(set(S))!=1 len(set(S)) len set(S) set S 1 for i in range(N):
        if S[i]==piv:
            buf=buf+1
        else:
            piv=S[i]
            cnt1=cnt1+(buf+1)//2
            buf=0
     i range(N) range N if S[i]==piv:
            buf=buf+1
        else:
            piv=S[i]
            cnt1=cnt1+(buf+1)//2
            buf=0
     S[i]==piv S[i] S i piv buf=buf+1 buf buf+1 buf 1 piv=S[i] piv S[i] S i cnt1=cnt1+(buf+1)//2 cnt1 cnt1+(buf+1)//2 cnt1 (buf+1)//2 buf+1 buf 1 2 buf=0 buf 0 cnt1=cnt1+(buf+1)//2 cnt1 cnt1+(buf+1)//2 cnt1 (buf+1)//2 buf+1 buf 1 2 buf=0 buf 0 piv="" piv "" for i in range(2*N):
        if s[i]==piv:
            buf=buf+1
        else:
            piv=s[i]
            cnt2=cnt2+(buf+1)//2
            buf=0
    #print(buf)
     i range(2*N) range 2*N 2 N if s[i]==piv:
            buf=buf+1
        else:
            piv=s[i]
            cnt2=cnt2+(buf+1)//2
            buf=0
    #print(buf)
     s[i]==piv s[i] s i piv buf=buf+1 buf buf+1 buf 1 piv=s[i] piv s[i] s i cnt2=cnt2+(buf+1)//2 cnt2 cnt2+(buf+1)//2 cnt2 (buf+1)//2 buf+1 buf 1 2 buf=0 buf 0 cnt2 = cnt2 + (buf + 1) // 2 cnt2 cnt2 + (buf + 1) // 2 cnt2 (buf + 1) // 2 buf + 1 buf 1 2 x = cnt2 - cnt1 x cnt2 - cnt1 cnt2 cnt1 print(cnt1 + (K - 1) * x) print cnt1 + (K - 1) * x cnt1 (K - 1) * x K - 1 K 1 x print((len(S)*K)//2) print (len(S)*K)//2 len(S)*K len(S) len S K 2 piv=s[i] s[i] piv cnt1=cnt1+(buf+1)//2 cnt1+(buf+1)//2 cnt1 buf=0 0 buf cnt1=0 0 cnt1 cnt2 = cnt2 + (buf + 1) // 2 cnt2 + (buf + 1) // 2 cnt2 N=len(S) len(S) N buf=0 0 buf piv="" "" piv buf=buf+1 buf+1 buf x = cnt2 - cnt1 cnt2 - cnt1 x buf=0 0 buf piv=S[i] S[i] piv S=input() input() S cnt2=cnt2+(buf+1)//2 cnt2+(buf+1)//2 cnt2 s="".join((S,S)) "".join((S,S)) s cnt2=0 0 cnt2 buf=0 0 buf piv="" "" piv buf=buf+1 buf+1 buf cnt1=cnt1+(buf+1)//2 cnt1+(buf+1)//2 cnt1 K=int(input()) int(input()) K
S=input()
N=len(S)
K=int(input())
s="".join((S,S))
cnt1=0
cnt2=0
buf=0
piv=""
if len(set(S))!=1:
    for i in range(N):
        if S[i]==piv:
            buf=buf+1
        else:
            piv=S[i]
            cnt1=cnt1+(buf+1)//2
            buf=0
    cnt1=cnt1+(buf+1)//2
    buf=0
    piv=""
    for i in range(2*N):
        if s[i]==piv:
            buf=buf+1
        else:
            piv=s[i]
            cnt2=cnt2+(buf+1)//2
            buf=0
    #print(buf)
    cnt2 = cnt2 + (buf + 1) // 2
    x = cnt2 - cnt1
    print(cnt1 + (K - 1) * x)
else:
    print((len(S)*K)//2)
