s=input()
k=int(input())
l=len(s)
now=1
seq=[]
re=False
all=False
for i in range(l):
    if s[i%l]==s[(i+1)%l]:
        if i==l-1:
            re=True
            if len(seq)==0:
                all=True
            else:
                first=seq[0]//2
                end=now//2
                seq[0]=(seq[0]+now)
        now+=1
    else:
        seq.append(now)
        now=1
if all:
    ans=len(s)*k//2
else:
    seq=[i//2 for i in seq]
    if re:
        ans=sum(seq)*k-seq[0]+first+end
    else:
        ans=sum(seq)*k

print(ans) s=input() s input() input k=int(input()) k int(input()) int input() input l=len(s) l len(s) len s now=1 now 1 seq=[] seq [] re=False re False all=False all False for i in range(l):
    if s[i%l]==s[(i+1)%l]:
        if i==l-1:
            re=True
            if len(seq)==0:
                all=True
            else:
                first=seq[0]//2
                end=now//2
                seq[0]=(seq[0]+now)
        now+=1
    else:
        seq.append(now)
        now=1 i range(l) range l if s[i%l]==s[(i+1)%l]:
        if i==l-1:
            re=True
            if len(seq)==0:
                all=True
            else:
                first=seq[0]//2
                end=now//2
                seq[0]=(seq[0]+now)
        now+=1
    else:
        seq.append(now)
        now=1 s[i%l]==s[(i+1)%l] s[i%l] s i%l i l s[(i+1)%l] s (i+1)%l i+1 i 1 l if i==l-1:
            re=True
            if len(seq)==0:
                all=True
            else:
                first=seq[0]//2
                end=now//2
                seq[0]=(seq[0]+now)
         i==l-1 i l-1 l 1 re=True re True if len(seq)==0:
                all=True
            else:
                first=seq[0]//2
                end=now//2
                seq[0]=(seq[0]+now)
         len(seq)==0 len(seq) len seq 0 all=True all True first=seq[0]//2 first seq[0]//2 seq[0] seq 0 2 end=now//2 end now//2 now 2 seq[0]=(seq[0]+now) seq[0] seq 0 seq[0]+now seq[0] seq 0 now now+=1 now 1 seq.append(now) seq.append seq append now now=1 now 1 if all:
    ans=len(s)*k//2
else:
    seq=[i//2 for i in seq]
    if re:
        ans=sum(seq)*k-seq[0]+first+end
    else:
        ans=sum(seq)*k all ans=len(s)*k//2 ans len(s)*k//2 len(s)*k len(s) len s k 2 i//2 for i in seq for i in seq i seq for i in seq i//2 i 2 seq=[i//2 for i in seq] seq [i//2 for i in seq] if re:
        ans=sum(seq)*k-seq[0]+first+end
    else:
        ans=sum(seq)*k re ans=sum(seq)*k-seq[0]+first+end ans sum(seq)*k-seq[0]+first+end sum(seq)*k-seq[0]+first sum(seq)*k-seq[0] sum(seq)*k sum(seq) sum seq k seq[0] seq 0 first end ans=sum(seq)*k ans sum(seq)*k sum(seq) sum seq k print(ans) print ans ans=sum(seq)*k-seq[0]+first+end sum(seq)*k-seq[0]+first+end ans end=now//2 now//2 end seq=[i//2 for i in seq] [i//2 for i in seq] seq k=int(input()) int(input()) k re=False False re now=1 1 now s=input() input() s now+=1 1 now re=True True re first=seq[0]//2 seq[0]//2 first seq=[] [] seq ans=sum(seq)*k sum(seq)*k ans all=False False all l=len(s) len(s) l all=True True all now=1 1 now ans=len(s)*k//2 len(s)*k//2 ans
s=input()
k=int(input())
l=len(s)
now=1
seq=[]
re=False
all=False
for i in range(l):
    if s[i%l]==s[(i+1)%l]:
        if i==l-1:
            re=True
            if len(seq)==0:
                all=True
            else:
                first=seq[0]//2
                end=now//2
                seq[0]=(seq[0]+now)
        now+=1
    else:
        seq.append(now)
        now=1
if all:
    ans=len(s)*k//2
else:
    seq=[i//2 for i in seq]
    if re:
        ans=sum(seq)*k-seq[0]+first+end
    else:
        ans=sum(seq)*k

print(ans)
