s = input()
k = int(input())

from itertools import groupby

n=len(s)
cnt =0

gp = groupby(s)

Keys=[]
values=[]
for key,value in gp:
    Keys.append(key)
    values.append(len(list(value)))

if len(Keys)==1:
    print(values[0]*k//2)
    exit(0)

if k==1:
    for i in values:
        cnt+=i//2
    print(cnt)
    exit(0)
    
if k>=2:
    if Keys[0]==Keys[-1]:
        values2=list(reversed(values))

        m=len(values)

        for i in range(m-1):
            if values[i]>=2:
                cnt+=values[i]//2
            if values2[i]>=2:
                cnt+=values2[i]//2
        
        cnt+= (k-1) * ((values[0]+values[-1])//2)

        for j in range(m):
            if j==0 or j==m-1:
                continue
            else:
                cnt+= (k-2)*(values[j]//2)

        print(cnt)
        exit(0)

for i in values:
    if i>1:
        cnt += k*(i//2)


print(cnt) s = input() s input() input k = int(input()) k int(input()) int input() input from itertools import groupby n=len(s) n len(s) len s cnt =0 cnt 0 gp = groupby(s) gp groupby(s) groupby s Keys=[] Keys [] values=[] values [] for key,value in gp:
    Keys.append(key)
    values.append(len(list(value))) key value gp Keys.append(key) Keys.append Keys append key values.append(len(list(value))) values.append values append len(list(value)) len list(value) list value if len(Keys)==1:
    print(values[0]*k//2)
    exit(0) len(Keys)==1 len(Keys) len Keys 1 print(values[0]*k//2) print values[0]*k//2 values[0]*k values[0] values 0 k 2 exit(0) exit 0 if k==1:
    for i in values:
        cnt+=i//2
    print(cnt)
    exit(0)
     k==1 k 1 for i in values:
        cnt+=i//2
     i values cnt+=i//2 cnt i//2 i 2 print(cnt) print cnt exit(0) exit 0 if k>=2:
    if Keys[0]==Keys[-1]:
        values2=list(reversed(values))

        m=len(values)

        for i in range(m-1):
            if values[i]>=2:
                cnt+=values[i]//2
            if values2[i]>=2:
                cnt+=values2[i]//2
        
        cnt+= (k-1) * ((values[0]+values[-1])//2)

        for j in range(m):
            if j==0 or j==m-1:
                continue
            else:
                cnt+= (k-2)*(values[j]//2)

        print(cnt)
        exit(0) k>=2 k 2 if Keys[0]==Keys[-1]:
        values2=list(reversed(values))

        m=len(values)

        for i in range(m-1):
            if values[i]>=2:
                cnt+=values[i]//2
            if values2[i]>=2:
                cnt+=values2[i]//2
        
        cnt+= (k-1) * ((values[0]+values[-1])//2)

        for j in range(m):
            if j==0 or j==m-1:
                continue
            else:
                cnt+= (k-2)*(values[j]//2)

        print(cnt)
        exit(0) Keys[0]==Keys[-1] Keys[0] Keys 0 Keys[-1] Keys -1 values2=list(reversed(values)) values2 list(reversed(values)) list reversed(values) reversed values m=len(values) m len(values) len values for i in range(m-1):
            if values[i]>=2:
                cnt+=values[i]//2
            if values2[i]>=2:
                cnt+=values2[i]//2
        
         i range(m-1) range m-1 m 1 if values[i]>=2:
                cnt+=values[i]//2
             values[i]>=2 values[i] values i 2 cnt+=values[i]//2 cnt values[i]//2 values[i] values i 2 if values2[i]>=2:
                cnt+=values2[i]//2
        
         values2[i]>=2 values2[i] values2 i 2 cnt+=values2[i]//2 cnt values2[i]//2 values2[i] values2 i 2 cnt+= (k-1) * ((values[0]+values[-1])//2) cnt (k-1) * ((values[0]+values[-1])//2) k-1 k 1 (values[0]+values[-1])//2 values[0]+values[-1] values[0] values 0 values[-1] values -1 2 for j in range(m):
            if j==0 or j==m-1:
                continue
            else:
                cnt+= (k-2)*(values[j]//2)

         j range(m) range m if j==0 or j==m-1:
                continue
            else:
                cnt+= (k-2)*(values[j]//2)

         j==0 or j==m-1 j==0 j 0 j==m-1 j m-1 m 1 continue cnt+= (k-2)*(values[j]//2) cnt (k-2)*(values[j]//2) k-2 k 2 values[j]//2 values[j] values j 2 print(cnt) print cnt exit(0) exit 0 for i in values:
    if i>1:
        cnt += k*(i//2) i values if i>1:
        cnt += k*(i//2) i>1 i 1 cnt += k*(i//2) cnt k*(i//2) k i//2 i 2 print(cnt) print cnt cnt+=i//2 i//2 cnt cnt+= (k-2)*(values[j]//2) (k-2)*(values[j]//2) cnt values2=list(reversed(values)) list(reversed(values)) values2 cnt+=values2[i]//2 values2[i]//2 cnt gp = groupby(s) groupby(s) gp cnt =0 0 cnt values=[] [] values cnt+=values[i]//2 values[i]//2 cnt cnt+= (k-1) * ((values[0]+values[-1])//2) (k-1) * ((values[0]+values[-1])//2) cnt s = input() input() s cnt += k*(i//2) k*(i//2) cnt k = int(input()) int(input()) k Keys=[] [] Keys m=len(values) len(values) m n=len(s) len(s) n
s = input()
k = int(input())

from itertools import groupby

n=len(s)
cnt =0

gp = groupby(s)

Keys=[]
values=[]
for key,value in gp:
    Keys.append(key)
    values.append(len(list(value)))

if len(Keys)==1:
    print(values[0]*k//2)
    exit(0)

if k==1:
    for i in values:
        cnt+=i//2
    print(cnt)
    exit(0)
    
if k>=2:
    if Keys[0]==Keys[-1]:
        values2=list(reversed(values))

        m=len(values)

        for i in range(m-1):
            if values[i]>=2:
                cnt+=values[i]//2
            if values2[i]>=2:
                cnt+=values2[i]//2
        
        cnt+= (k-1) * ((values[0]+values[-1])//2)

        for j in range(m):
            if j==0 or j==m-1:
                continue
            else:
                cnt+= (k-2)*(values[j]//2)

        print(cnt)
        exit(0)

for i in values:
    if i>1:
        cnt += k*(i//2)


print(cnt)
