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

l = len(s)
cnt = 0
cnt_list = [0]

for i in range(l-1):#sの中での連続数
    if s[i] == s[i+1]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        cnt = 0
        cnt_list.append(cnt)
#print(cnt_list)

for i in range(l-1):#sの末尾と最初がつながっているとき
    if s[-1] == s[i]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        break
#print(cnt_list)
L = len(cnt_list)

if len(set(s)) == 1:#1文字のみのとき
    print(l*k//2)
    
elif k == 1:#k = 1の時  
    ans = 0
    for i in cnt_list[:l]:#最初のl文字での回数
        if i % 2 == 1:
            ans += 1
    print(ans)
    
else:
    cnt_ref = cnt_list[L-l:] #繰り返し部分
    ans_ref = 0
    for i in cnt_ref:
        if i % 2 == 1:
            ans_ref += 1
    num_ref = (k*l-L) // l #num回繰り返す 
    #print("ans_ref =" ,ans_ref)
    
    amari = (k*l-L) % l
    ans_amari = 0
    for i in cnt_ref[:amari]:
        if i % 2 == 1:
            ans_amari += 1
    #print("ans_amari", ans_amari)
    #print("cnt_ref[:amari] = ", cnt_ref[:amari])  
    
    ans = 0
    for i in cnt_list:
        if i % 2 == 1:
            ans += 1
    #print("ans = ",ans)
    
    ans += ans_amari + ans_ref * num_ref
    print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input l = len(s) l len(s) len s cnt = 0 cnt 0 cnt_list = [0] cnt_list [0] 0 for i in range(l-1):#sの中での連続数
    if s[i] == s[i+1]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        cnt = 0
        cnt_list.append(cnt)
#print(cnt_list) i range(l-1) range l-1 l 1 if s[i] == s[i+1]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        cnt = 0
        cnt_list.append(cnt)
#print(cnt_list) s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 cnt += 1 cnt 1 cnt_list.append(cnt) cnt_list.append cnt_list append cnt cnt = 0 cnt 0 cnt_list.append(cnt) cnt_list.append cnt_list append cnt for i in range(l-1):#sの末尾と最初がつながっているとき
    if s[-1] == s[i]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        break
#print(cnt_list) i range(l-1) range l-1 l 1 if s[-1] == s[i]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        break
#print(cnt_list) s[-1] == s[i] s[-1] s -1 s[i] s i cnt += 1 cnt 1 cnt_list.append(cnt) cnt_list.append cnt_list append cnt break L = len(cnt_list) L len(cnt_list) len cnt_list if len(set(s)) == 1:#1文字のみのとき
    print(l*k//2)
    
elif k == 1:#k = 1の時  
    ans = 0
    for i in cnt_list[:l]:#最初のl文字での回数
        if i % 2 == 1:
            ans += 1
    print(ans)
    
else:
    cnt_ref = cnt_list[L-l:] #繰り返し部分
    ans_ref = 0
    for i in cnt_ref:
        if i % 2 == 1:
            ans_ref += 1
    num_ref = (k*l-L) // l #num回繰り返す 
    #print("ans_ref =" ,ans_ref)
    
    amari = (k*l-L) % l
    ans_amari = 0
    for i in cnt_ref[:amari]:
        if i % 2 == 1:
            ans_amari += 1
    #print("ans_amari", ans_amari)
    #print("cnt_ref[:amari] = ", cnt_ref[:amari])  
    
    ans = 0
    for i in cnt_list:
        if i % 2 == 1:
            ans += 1
    #print("ans = ",ans)
    
    ans += ans_amari + ans_ref * num_ref
    print(ans) len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(l*k//2) print l*k//2 l*k l k 2 elif k == 1:#k = 1の時  
    ans = 0
    for i in cnt_list[:l]:#最初のl文字での回数
        if i % 2 == 1:
            ans += 1
    print(ans)
     k == 1 k 1 ans = 0 ans 0 for i in cnt_list[:l]:#最初のl文字での回数
        if i % 2 == 1:
            ans += 1
     i cnt_list[:l] cnt_list :l l if i % 2 == 1:
            ans += 1
     i % 2 == 1 i % 2 i 2 1 ans += 1 ans 1 print(ans) print ans cnt_ref = cnt_list[L-l:] cnt_ref cnt_list[L-l:] cnt_list L-l: L-l L l ans_ref = 0 ans_ref 0 for i in cnt_ref:
        if i % 2 == 1:
            ans_ref += 1
     i cnt_ref if i % 2 == 1:
            ans_ref += 1
     i % 2 == 1 i % 2 i 2 1 ans_ref += 1 ans_ref 1 num_ref = (k*l-L) // l num_ref (k*l-L) // l k*l-L k*l k l L l amari = (k*l-L) % l amari (k*l-L) % l k*l-L k*l k l L l ans_amari = 0 ans_amari 0 for i in cnt_ref[:amari]:
        if i % 2 == 1:
            ans_amari += 1
    #print("ans_amari", ans_amari)
    #print("cnt_ref[:amari] = ", cnt_ref[:amari])  
    
     i cnt_ref[:amari] cnt_ref :amari amari if i % 2 == 1:
            ans_amari += 1
    #print("ans_amari", ans_amari)
    #print("cnt_ref[:amari] = ", cnt_ref[:amari])  
    
     i % 2 == 1 i % 2 i 2 1 ans_amari += 1 ans_amari 1 ans = 0 ans 0 for i in cnt_list:
        if i % 2 == 1:
            ans += 1
    #print("ans = ",ans)
    
     i cnt_list if i % 2 == 1:
            ans += 1
    #print("ans = ",ans)
    
     i % 2 == 1 i % 2 i 2 1 ans += 1 ans 1 ans += ans_amari + ans_ref * num_ref ans ans_amari + ans_ref * num_ref ans_amari ans_ref * num_ref ans_ref num_ref print(ans) print ans ans_amari = 0 0 ans_amari cnt = 0 0 cnt ans += 1 1 ans cnt_list = [0] [0] cnt_list ans += ans_amari + ans_ref * num_ref ans_amari + ans_ref * num_ref ans cnt += 1 1 cnt cnt += 1 1 cnt cnt = 0 0 cnt ans_ref += 1 1 ans_ref amari = (k*l-L) % l (k*l-L) % l amari cnt_ref = cnt_list[L-l:] cnt_list[L-l:] cnt_ref ans += 1 1 ans ans = 0 0 ans ans_amari += 1 1 ans_amari s = input() input() s L = len(cnt_list) len(cnt_list) L ans = 0 0 ans k = int(input()) int(input()) k num_ref = (k*l-L) // l (k*l-L) // l num_ref l = len(s) len(s) l ans_ref = 0 0 ans_ref
s = input()
k = int(input())

l = len(s)
cnt = 0
cnt_list = [0]

for i in range(l-1):#sの中での連続数
    if s[i] == s[i+1]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        cnt = 0
        cnt_list.append(cnt)
#print(cnt_list)

for i in range(l-1):#sの末尾と最初がつながっているとき
    if s[-1] == s[i]:
        cnt += 1
        cnt_list.append(cnt)
    else:
        break
#print(cnt_list)
L = len(cnt_list)

if len(set(s)) == 1:#1文字のみのとき
    print(l*k//2)
    
elif k == 1:#k = 1の時  
    ans = 0
    for i in cnt_list[:l]:#最初のl文字での回数
        if i % 2 == 1:
            ans += 1
    print(ans)
    
else:
    cnt_ref = cnt_list[L-l:] #繰り返し部分
    ans_ref = 0
    for i in cnt_ref:
        if i % 2 == 1:
            ans_ref += 1
    num_ref = (k*l-L) // l #num回繰り返す 
    #print("ans_ref =" ,ans_ref)
    
    amari = (k*l-L) % l
    ans_amari = 0
    for i in cnt_ref[:amari]:
        if i % 2 == 1:
            ans_amari += 1
    #print("ans_amari", ans_amari)
    #print("cnt_ref[:amari] = ", cnt_ref[:amari])  
    
    ans = 0
    for i in cnt_list:
        if i % 2 == 1:
            ans += 1
    #print("ans = ",ans)
    
    ans += ans_amari + ans_ref * num_ref
    print(ans)