s = input()
n = len(s)
k = int(input())
start = True
start_count = 0
start_char = s[0]
inside_num = 0
end_count = 0
end_char = ""
memory = s[0]
count = 1
for i in range(1,n):
    if s[i] == memory:
        count += 1
    else:
        if start:
            start_count = count
            start = False
        else:
            inside_num += count//2
        count = 1
        memory = s[i]
end_count = count
end_char = memory
ans = 0
if start_char == end_char:
    if end_count == n:
        ans = n*k//2
    else:
        ans += inside_num*k
        ans += (start_count+end_count)//2*(k-1)+start_count//2+end_count//2
else:
    inside_num += start_count//2
    inside_num += end_count//2
    ans += inside_num*k
print(ans) s = input() s input() input n = len(s) n len(s) len s k = int(input()) k int(input()) int input() input start = True start True start_count = 0 start_count 0 start_char = s[0] start_char s[0] s 0 inside_num = 0 inside_num 0 end_count = 0 end_count 0 end_char = "" end_char "" memory = s[0] memory s[0] s 0 count = 1 count 1 for i in range(1,n):
    if s[i] == memory:
        count += 1
    else:
        if start:
            start_count = count
            start = False
        else:
            inside_num += count//2
        count = 1
        memory = s[i] i range(1,n) range 1 n if s[i] == memory:
        count += 1
    else:
        if start:
            start_count = count
            start = False
        else:
            inside_num += count//2
        count = 1
        memory = s[i] s[i] == memory s[i] s i memory count += 1 count 1 if start:
            start_count = count
            start = False
        else:
            inside_num += count//2
         start start_count = count start_count count start = False start False inside_num += count//2 inside_num count//2 count 2 count = 1 count 1 memory = s[i] memory s[i] s i end_count = count end_count count end_char = memory end_char memory ans = 0 ans 0 if start_char == end_char:
    if end_count == n:
        ans = n*k//2
    else:
        ans += inside_num*k
        ans += (start_count+end_count)//2*(k-1)+start_count//2+end_count//2
else:
    inside_num += start_count//2
    inside_num += end_count//2
    ans += inside_num*k start_char == end_char start_char end_char if end_count == n:
        ans = n*k//2
    else:
        ans += inside_num*k
        ans += (start_count+end_count)//2*(k-1)+start_count//2+end_count//2 end_count == n end_count n ans = n*k//2 ans n*k//2 n*k n k 2 ans += inside_num*k ans inside_num*k inside_num k ans += (start_count+end_count)//2*(k-1)+start_count//2+end_count//2 ans (start_count+end_count)//2*(k-1)+start_count//2+end_count//2 (start_count+end_count)//2*(k-1)+start_count//2 (start_count+end_count)//2*(k-1) (start_count+end_count)//2 start_count+end_count start_count end_count 2 k-1 k 1 start_count//2 start_count 2 end_count//2 end_count 2 inside_num += start_count//2 inside_num start_count//2 start_count 2 inside_num += end_count//2 inside_num end_count//2 end_count 2 ans += inside_num*k ans inside_num*k inside_num k print(ans) print ans count = 1 1 count ans += (start_count+end_count)//2*(k-1)+start_count//2+end_count//2 (start_count+end_count)//2*(k-1)+start_count//2+end_count//2 ans ans += inside_num*k inside_num*k ans inside_num += end_count//2 end_count//2 inside_num inside_num += start_count//2 start_count//2 inside_num start = True True start inside_num = 0 0 inside_num memory = s[0] s[0] memory ans += inside_num*k inside_num*k ans memory = s[i] s[i] memory ans = 0 0 ans count += 1 1 count end_char = "" "" end_char start = False False start end_count = 0 0 end_count n = len(s) len(s) n inside_num += count//2 count//2 inside_num s = input() input() s start_count = count count start_count ans = n*k//2 n*k//2 ans start_count = 0 0 start_count end_count = count count end_count k = int(input()) int(input()) k end_char = memory memory end_char start_char = s[0] s[0] start_char count = 1 1 count
s = input()
n = len(s)
k = int(input())
start = True
start_count = 0
start_char = s[0]
inside_num = 0
end_count = 0
end_char = ""
memory = s[0]
count = 1
for i in range(1,n):
    if s[i] == memory:
        count += 1
    else:
        if start:
            start_count = count
            start = False
        else:
            inside_num += count//2
        count = 1
        memory = s[i]
end_count = count
end_char = memory
ans = 0
if start_char == end_char:
    if end_count == n:
        ans = n*k//2
    else:
        ans += inside_num*k
        ans += (start_count+end_count)//2*(k-1)+start_count//2+end_count//2
else:
    inside_num += start_count//2
    inside_num += end_count//2
    ans += inside_num*k
print(ans)