string = input()
k = int(input())

before = string[0]
flg = False
cnt = 0
if string.count(before) == len(string):
    print(len(string) * k // 2)
    exit()
for s in string[1:]:
    if s == before and not flg:
        cnt += 1
        flg = True
        continue
    flg = False
    before = s
ans = cnt * k
if string[0] == string[-1]:
    tmp = string[0]
    b_cnt = 0
    for s in string:
        if s == tmp:
            b_cnt += 1
        else:
            break
    a_cnt = 0
    for s in string[::-1]:
        if s == tmp:
            a_cnt += 1
        else:
            break
    if (a_cnt + b_cnt) % 2 == 0 and b_cnt % 2 == 1:
        ans += k - 1
        
    
print(ans) string = input() string input() input k = int(input()) k int(input()) int input() input before = string[0] before string[0] string 0 flg = False flg False cnt = 0 cnt 0 if string.count(before) == len(string):
    print(len(string) * k // 2)
    exit() string.count(before) == len(string) string.count(before) string.count string count before len(string) len string print(len(string) * k // 2) print len(string) * k // 2 len(string) * k len(string) len string k 2 exit() exit for s in string[1:]:
    if s == before and not flg:
        cnt += 1
        flg = True
        continue
    flg = False
    before = s s string[1:] string 1: 1 if s == before and not flg:
        cnt += 1
        flg = True
        continue
     s == before and not flg s == before s before not flg flg cnt += 1 cnt 1 flg = True flg True continue flg = False flg False before = s before s ans = cnt * k ans cnt * k cnt k if string[0] == string[-1]:
    tmp = string[0]
    b_cnt = 0
    for s in string:
        if s == tmp:
            b_cnt += 1
        else:
            break
    a_cnt = 0
    for s in string[::-1]:
        if s == tmp:
            a_cnt += 1
        else:
            break
    if (a_cnt + b_cnt) % 2 == 0 and b_cnt % 2 == 1:
        ans += k - 1
        
     string[0] == string[-1] string[0] string 0 string[-1] string -1 tmp = string[0] tmp string[0] string 0 b_cnt = 0 b_cnt 0 for s in string:
        if s == tmp:
            b_cnt += 1
        else:
            break
     s string if s == tmp:
            b_cnt += 1
        else:
            break
     s == tmp s tmp b_cnt += 1 b_cnt 1 break a_cnt = 0 a_cnt 0 for s in string[::-1]:
        if s == tmp:
            a_cnt += 1
        else:
            break
     s string[::-1] string ::-1 -1 if s == tmp:
            a_cnt += 1
        else:
            break
     s == tmp s tmp a_cnt += 1 a_cnt 1 break if (a_cnt + b_cnt) % 2 == 0 and b_cnt % 2 == 1:
        ans += k - 1
        
     (a_cnt + b_cnt) % 2 == 0 and b_cnt % 2 == 1 (a_cnt + b_cnt) % 2 == 0 (a_cnt + b_cnt) % 2 a_cnt + b_cnt a_cnt b_cnt 2 0 b_cnt % 2 == 1 b_cnt % 2 b_cnt 2 1 ans += k - 1 ans k - 1 k 1 print(ans) print ans tmp = string[0] string[0] tmp k = int(input()) int(input()) k ans = cnt * k cnt * k ans before = s s before flg = False False flg cnt += 1 1 cnt a_cnt = 0 0 a_cnt cnt = 0 0 cnt flg = False False flg b_cnt += 1 1 b_cnt b_cnt = 0 0 b_cnt flg = True True flg ans += k - 1 k - 1 ans a_cnt += 1 1 a_cnt before = string[0] string[0] before string = input() input() string
string = input()
k = int(input())

before = string[0]
flg = False
cnt = 0
if string.count(before) == len(string):
    print(len(string) * k // 2)
    exit()
for s in string[1:]:
    if s == before and not flg:
        cnt += 1
        flg = True
        continue
    flg = False
    before = s
ans = cnt * k
if string[0] == string[-1]:
    tmp = string[0]
    b_cnt = 0
    for s in string:
        if s == tmp:
            b_cnt += 1
        else:
            break
    a_cnt = 0
    for s in string[::-1]:
        if s == tmp:
            a_cnt += 1
        else:
            break
    if (a_cnt + b_cnt) % 2 == 0 and b_cnt % 2 == 1:
        ans += k - 1
        
    
print(ans)