S=input()
K=int(input())
h=1
b=0
l=[]
f=False
c1=0
c2=0
c3=0
c4=0
r=[]
v=[]
vf=False
vf1=False
vf2=False
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        if i==0:
            c1=1
            c3=1
        if (i+1)==(len(S)-1):
            c2=1
            c4=1
        h+=1
        f=True
    else:
        f=False
    if not f:
        if h!=1:
            l.append(h)
            if c3==1:
                r.append(h)
                c3=0
            if c4==1:
                r.append(h)
                c4=0
        h=1
#print(l)
if f:
    l.append(h)
    #print(l)
    if c4==1:
        r.append(h)
        c4=0
#print(l)
if S[0]==S[-1]:
    #print(l)
    if c1==1 and c2==1:
        if len(l)==1:
            s=len(S)*K
            print(s//2)
            exit()
        else:
            v.append(l[0])
            v.append(l[-1])
            l[-1]+=l[0]
            del l[0]
            vf=True
    elif c1==1:
        #l[0]+=1
        v.append(l[0])
        #v.append(l[-1])
        l[0]+=1
        v.append(l[0])
        del l[0]
        vf1=True
    elif c2==1:
        #l[-1]+=1
        #v.append(l[0])
        v.append(l[-1])
        l[-1]+=1
        v.append(l[-1])
        del l[-1]
        vf2=True
    else:
        if len(S)==1:
            print(K//2)
            exit()
        print(K-1)
        exit()
h=0
if vf:
    h+=v[0]//2
    h+=v[-1]//2
    for i in range(len(l)):
        if i==(len(l)-1):
            h+=(l[i]//2)*(K-1)
        else:
            h+=(l[i]//2)*K
elif vf1:
    h+=(v[1]//2)*(K-1)
    h+=(v[0]//2)
    for i in range(len(l)):
        h+=(l[i]//2)*K
elif vf2:
    h+=(v[1]//2)*(K-1)
    h+=(v[0]//2)
    for i in range(len(l)):
        h+=(l[i]//2)*K
else:
    for i in range(len(l)):
        h+=(l[i]//2)*K

#print(l)
print(h) S=input() S input() input K=int(input()) K int(input()) int input() input h=1 h 1 b=0 b 0 l=[] l [] f=False f False c1=0 c1 0 c2=0 c2 0 c3=0 c3 0 c4=0 c4 0 r=[] r [] v=[] v [] vf=False vf False vf1=False vf1 False vf2=False vf2 False for i in range(len(S)-1):
    if S[i]==S[i+1]:
        if i==0:
            c1=1
            c3=1
        if (i+1)==(len(S)-1):
            c2=1
            c4=1
        h+=1
        f=True
    else:
        f=False
    if not f:
        if h!=1:
            l.append(h)
            if c3==1:
                r.append(h)
                c3=0
            if c4==1:
                r.append(h)
                c4=0
        h=1
#print(l) i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i]==S[i+1]:
        if i==0:
            c1=1
            c3=1
        if (i+1)==(len(S)-1):
            c2=1
            c4=1
        h+=1
        f=True
    else:
        f=False
     S[i]==S[i+1] S[i] S i S[i+1] S i+1 i 1 if i==0:
            c1=1
            c3=1
         i==0 i 0 c1=1 c1 1 c3=1 c3 1 if (i+1)==(len(S)-1):
            c2=1
            c4=1
         (i+1)==(len(S)-1) i+1 i 1 len(S)-1 len(S) len S 1 c2=1 c2 1 c4=1 c4 1 h+=1 h 1 f=True f True f=False f False if not f:
        if h!=1:
            l.append(h)
            if c3==1:
                r.append(h)
                c3=0
            if c4==1:
                r.append(h)
                c4=0
        h=1
#print(l) not f f if h!=1:
            l.append(h)
            if c3==1:
                r.append(h)
                c3=0
            if c4==1:
                r.append(h)
                c4=0
         h!=1 h 1 l.append(h) l.append l append h if c3==1:
                r.append(h)
                c3=0
             c3==1 c3 1 r.append(h) r.append r append h c3=0 c3 0 if c4==1:
                r.append(h)
                c4=0
         c4==1 c4 1 r.append(h) r.append r append h c4=0 c4 0 h=1 h 1 if f:
    l.append(h)
    #print(l)
    if c4==1:
        r.append(h)
        c4=0
#print(l) f l.append(h) l.append l append h if c4==1:
        r.append(h)
        c4=0
#print(l) c4==1 c4 1 r.append(h) r.append r append h c4=0 c4 0 if S[0]==S[-1]:
    #print(l)
    if c1==1 and c2==1:
        if len(l)==1:
            s=len(S)*K
            print(s//2)
            exit()
        else:
            v.append(l[0])
            v.append(l[-1])
            l[-1]+=l[0]
            del l[0]
            vf=True
    elif c1==1:
        #l[0]+=1
        v.append(l[0])
        #v.append(l[-1])
        l[0]+=1
        v.append(l[0])
        del l[0]
        vf1=True
    elif c2==1:
        #l[-1]+=1
        #v.append(l[0])
        v.append(l[-1])
        l[-1]+=1
        v.append(l[-1])
        del l[-1]
        vf2=True
    else:
        if len(S)==1:
            print(K//2)
            exit()
        print(K-1)
        exit() S[0]==S[-1] S[0] S 0 S[-1] S -1 if c1==1 and c2==1:
        if len(l)==1:
            s=len(S)*K
            print(s//2)
            exit()
        else:
            v.append(l[0])
            v.append(l[-1])
            l[-1]+=l[0]
            del l[0]
            vf=True
    elif c1==1:
        #l[0]+=1
        v.append(l[0])
        #v.append(l[-1])
        l[0]+=1
        v.append(l[0])
        del l[0]
        vf1=True
    elif c2==1:
        #l[-1]+=1
        #v.append(l[0])
        v.append(l[-1])
        l[-1]+=1
        v.append(l[-1])
        del l[-1]
        vf2=True
    else:
        if len(S)==1:
            print(K//2)
            exit()
        print(K-1)
        exit() c1==1 and c2==1 c1==1 c1 1 c2==1 c2 1 if len(l)==1:
            s=len(S)*K
            print(s//2)
            exit()
        else:
            v.append(l[0])
            v.append(l[-1])
            l[-1]+=l[0]
            del l[0]
            vf=True
     len(l)==1 len(l) len l 1 s=len(S)*K s len(S)*K len(S) len S K print(s//2) print s//2 s 2 exit() exit v.append(l[0]) v.append v append l[0] l 0 v.append(l[-1]) v.append v append l[-1] l -1 l[-1]+=l[0] l[-1] l -1 l[0] l 0 del l[0] l[0] l 0 vf=True vf True elif c1==1:
        #l[0]+=1
        v.append(l[0])
        #v.append(l[-1])
        l[0]+=1
        v.append(l[0])
        del l[0]
        vf1=True
     c1==1 c1 1 v.append(l[0]) v.append v append l[0] l 0 l[0]+=1 l[0] l 0 1 v.append(l[0]) v.append v append l[0] l 0 del l[0] l[0] l 0 vf1=True vf1 True elif c2==1:
        #l[-1]+=1
        #v.append(l[0])
        v.append(l[-1])
        l[-1]+=1
        v.append(l[-1])
        del l[-1]
        vf2=True
     c2==1 c2 1 v.append(l[-1]) v.append v append l[-1] l -1 l[-1]+=1 l[-1] l -1 1 v.append(l[-1]) v.append v append l[-1] l -1 del l[-1] l[-1] l -1 vf2=True vf2 True if len(S)==1:
            print(K//2)
            exit()
         len(S)==1 len(S) len S 1 print(K//2) print K//2 K 2 exit() exit print(K-1) print K-1 K 1 exit() exit h=0 h 0 if vf:
    h+=v[0]//2
    h+=v[-1]//2
    for i in range(len(l)):
        if i==(len(l)-1):
            h+=(l[i]//2)*(K-1)
        else:
            h+=(l[i]//2)*K
elif vf1:
    h+=(v[1]//2)*(K-1)
    h+=(v[0]//2)
    for i in range(len(l)):
        h+=(l[i]//2)*K
elif vf2:
    h+=(v[1]//2)*(K-1)
    h+=(v[0]//2)
    for i in range(len(l)):
        h+=(l[i]//2)*K
else:
    for i in range(len(l)):
        h+=(l[i]//2)*K

#print(l) vf h+=v[0]//2 h v[0]//2 v[0] v 0 2 h+=v[-1]//2 h v[-1]//2 v[-1] v -1 2 for i in range(len(l)):
        if i==(len(l)-1):
            h+=(l[i]//2)*(K-1)
        else:
            h+=(l[i]//2)*K i range(len(l)) range len(l) len l if i==(len(l)-1):
            h+=(l[i]//2)*(K-1)
        else:
            h+=(l[i]//2)*K i==(len(l)-1) i len(l)-1 len(l) len l 1 h+=(l[i]//2)*(K-1) h (l[i]//2)*(K-1) l[i]//2 l[i] l i 2 K-1 K 1 h+=(l[i]//2)*K h (l[i]//2)*K l[i]//2 l[i] l i 2 K elif vf1:
    h+=(v[1]//2)*(K-1)
    h+=(v[0]//2)
    for i in range(len(l)):
        h+=(l[i]//2)*K vf1 h+=(v[1]//2)*(K-1) h (v[1]//2)*(K-1) v[1]//2 v[1] v 1 2 K-1 K 1 h+=(v[0]//2) h v[0]//2 v[0] v 0 2 for i in range(len(l)):
        h+=(l[i]//2)*K i range(len(l)) range len(l) len l h+=(l[i]//2)*K h (l[i]//2)*K l[i]//2 l[i] l i 2 K elif vf2:
    h+=(v[1]//2)*(K-1)
    h+=(v[0]//2)
    for i in range(len(l)):
        h+=(l[i]//2)*K vf2 h+=(v[1]//2)*(K-1) h (v[1]//2)*(K-1) v[1]//2 v[1] v 1 2 K-1 K 1 h+=(v[0]//2) h v[0]//2 v[0] v 0 2 for i in range(len(l)):
        h+=(l[i]//2)*K i range(len(l)) range len(l) len l h+=(l[i]//2)*K h (l[i]//2)*K l[i]//2 l[i] l i 2 K for i in range(len(l)):
        h+=(l[i]//2)*K

#print(l) i range(len(l)) range len(l) len l h+=(l[i]//2)*K h (l[i]//2)*K l[i]//2 l[i] l i 2 K print(h) print h h+=(v[1]//2)*(K-1) (v[1]//2)*(K-1) h c1=1 1 c1 vf=True True vf vf1=False False vf1 c2=0 0 c2 h+=(v[0]//2) v[0]//2 h h+=(v[0]//2) v[0]//2 h h=1 1 h h+=(v[1]//2)*(K-1) (v[1]//2)*(K-1) h c4=1 1 c4 c3=0 0 c3 f=False False f S=input() input() S K=int(input()) int(input()) K c1=0 0 c1 c4=0 0 c4 v=[] [] v f=True True f vf2=True True vf2 h=1 1 h h=0 0 h h+=(l[i]//2)*K (l[i]//2)*K h h+=v[-1]//2 v[-1]//2 h h+=(l[i]//2)*K (l[i]//2)*K h h+=(l[i]//2)*K (l[i]//2)*K h h+=v[0]//2 v[0]//2 h b=0 0 b r=[] [] r c3=1 1 c3 vf=False False vf h+=(l[i]//2)*K (l[i]//2)*K h c4=0 0 c4 s=len(S)*K len(S)*K s c2=1 1 c2 h+=1 1 h l=[] [] l c3=0 0 c3 h+=(l[i]//2)*(K-1) (l[i]//2)*(K-1) h c4=0 0 c4 vf2=False False vf2 vf1=True True vf1 f=False False f
S=input()
K=int(input())
h=1
b=0
l=[]
f=False
c1=0
c2=0
c3=0
c4=0
r=[]
v=[]
vf=False
vf1=False
vf2=False
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        if i==0:
            c1=1
            c3=1
        if (i+1)==(len(S)-1):
            c2=1
            c4=1
        h+=1
        f=True
    else:
        f=False
    if not f:
        if h!=1:
            l.append(h)
            if c3==1:
                r.append(h)
                c3=0
            if c4==1:
                r.append(h)
                c4=0
        h=1
#print(l)
if f:
    l.append(h)
    #print(l)
    if c4==1:
        r.append(h)
        c4=0
#print(l)
if S[0]==S[-1]:
    #print(l)
    if c1==1 and c2==1:
        if len(l)==1:
            s=len(S)*K
            print(s//2)
            exit()
        else:
            v.append(l[0])
            v.append(l[-1])
            l[-1]+=l[0]
            del l[0]
            vf=True
    elif c1==1:
        #l[0]+=1
        v.append(l[0])
        #v.append(l[-1])
        l[0]+=1
        v.append(l[0])
        del l[0]
        vf1=True
    elif c2==1:
        #l[-1]+=1
        #v.append(l[0])
        v.append(l[-1])
        l[-1]+=1
        v.append(l[-1])
        del l[-1]
        vf2=True
    else:
        if len(S)==1:
            print(K//2)
            exit()
        print(K-1)
        exit()
h=0
if vf:
    h+=v[0]//2
    h+=v[-1]//2
    for i in range(len(l)):
        if i==(len(l)-1):
            h+=(l[i]//2)*(K-1)
        else:
            h+=(l[i]//2)*K
elif vf1:
    h+=(v[1]//2)*(K-1)
    h+=(v[0]//2)
    for i in range(len(l)):
        h+=(l[i]//2)*K
elif vf2:
    h+=(v[1]//2)*(K-1)
    h+=(v[0]//2)
    for i in range(len(l)):
        h+=(l[i]//2)*K
else:
    for i in range(len(l)):
        h+=(l[i]//2)*K

#print(l)
print(h)