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

if len(set(s)) == 1:
    print((len(s))*k//2)
    exit()

first, last = s[0], s[-1]
first_flag = 1
a, b  = 0, 0
tmp = s[0]
tmp_cnt = 0
cnt = 0

for i in range(len(s)):
    c = s[i]
    if c == first and first_flag:  # 最初に続く文字数をカウント (a)
        a += 1
    elif c != first:
        first_flag = 0
    
    if c == tmp:  # s単体のとき必要な操作回数を求める (cnt)
        tmp_cnt += 1
    else:
        cnt += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c
        
    if i == len(s) -1:  # 最後に続く文字数を取得 (b)
        b = tmp_cnt
        cnt += (tmp_cnt // 2)

if first != last:  # sの最初の文字と最後の文字が違う場合
    ans = cnt * k
else:  # sの最初の文字と最後の文字が同じ場合
    ans = cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1)

print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
    print((len(s))*k//2)
    exit() len(set(s)) == 1 len(set(s)) len set(s) set s 1 print((len(s))*k//2) print (len(s))*k//2 (len(s))*k len(s) len s k 2 exit() exit first, last = s[0], s[-1] first s[0] s 0 last s[-1] s -1 first_flag = 1 first_flag 1 a, b  = 0, 0 a 0 b 0 tmp = s[0] tmp s[0] s 0 tmp_cnt = 0 tmp_cnt 0 cnt = 0 cnt 0 for i in range(len(s)):
    c = s[i]
    if c == first and first_flag:  # 最初に続く文字数をカウント (a)
        a += 1
    elif c != first:
        first_flag = 0
    
    if c == tmp:  # s単体のとき必要な操作回数を求める (cnt)
        tmp_cnt += 1
    else:
        cnt += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c
        
    if i == len(s) -1:  # 最後に続く文字数を取得 (b)
        b = tmp_cnt
        cnt += (tmp_cnt // 2) i range(len(s)) range len(s) len s c = s[i] c s[i] s i if c == first and first_flag:  # 最初に続く文字数をカウント (a)
        a += 1
    elif c != first:
        first_flag = 0
    
     c == first and first_flag c == first c first first_flag a += 1 a 1 elif c != first:
        first_flag = 0
    
     c != first c first first_flag = 0 first_flag 0 if c == tmp:  # s単体のとき必要な操作回数を求める (cnt)
        tmp_cnt += 1
    else:
        cnt += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c
        
     c == tmp c tmp tmp_cnt += 1 tmp_cnt 1 cnt += (tmp_cnt // 2) cnt tmp_cnt // 2 tmp_cnt 2 tmp_cnt = 1 tmp_cnt 1 tmp = c tmp c if i == len(s) -1:  # 最後に続く文字数を取得 (b)
        b = tmp_cnt
        cnt += (tmp_cnt // 2) i == len(s) -1 i len(s) -1 len(s) len s 1 b = tmp_cnt b tmp_cnt cnt += (tmp_cnt // 2) cnt tmp_cnt // 2 tmp_cnt 2 if first != last:  # sの最初の文字と最後の文字が違う場合
    ans = cnt * k
else:  # sの最初の文字と最後の文字が同じ場合
    ans = cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1) first != last first last ans = cnt * k ans cnt * k cnt k ans = cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1) ans cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1) cnt * k cnt k (a//2 + b//2 - (a+b)//2)*(k-1) a//2 + b//2 - (a+b)//2 a//2 + b//2 a//2 a 2 b//2 b 2 (a+b)//2 a+b a b 2 k-1 k 1 print(ans) print ans cnt += (tmp_cnt // 2) tmp_cnt // 2 cnt cnt += (tmp_cnt // 2) tmp_cnt // 2 cnt tmp_cnt = 1 1 tmp_cnt tmp = s[0] s[0] tmp ans = cnt * k cnt * k ans first_flag = 0 0 first_flag first_flag = 1 1 first_flag cnt = 0 0 cnt s = input() input() s k = int(input()) int(input()) k b  = 0, 0 0 b b = tmp_cnt tmp_cnt b tmp_cnt = 0 0 tmp_cnt last = s[0], s[-1] s[-1] last a += 1 1 a tmp = c c tmp ans = cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1) cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1) ans tmp_cnt += 1 1 tmp_cnt a, b  = 0, 0 0 a c = s[i] s[i] c first, last = s[0], s[-1] s[0] first
s = input()
k = int(input())

if len(set(s)) == 1:
    print((len(s))*k//2)
    exit()

first, last = s[0], s[-1]
first_flag = 1
a, b  = 0, 0
tmp = s[0]
tmp_cnt = 0
cnt = 0

for i in range(len(s)):
    c = s[i]
    if c == first and first_flag:  # 最初に続く文字数をカウント (a)
        a += 1
    elif c != first:
        first_flag = 0
    
    if c == tmp:  # s単体のとき必要な操作回数を求める (cnt)
        tmp_cnt += 1
    else:
        cnt += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c
        
    if i == len(s) -1:  # 最後に続く文字数を取得 (b)
        b = tmp_cnt
        cnt += (tmp_cnt // 2)

if first != last:  # sの最初の文字と最後の文字が違う場合
    ans = cnt * k
else:  # sの最初の文字と最後の文字が同じ場合
    ans = cnt * k - (a//2 + b//2 - (a+b)//2)*(k-1)

print(ans)