import sys
s = input()
k = int(input())
n = len(s)
all_same = True
for i in range(n-1):
    if s[i] != s[i+1]:
        all_same = False
if all_same:
    print((n*k)//2)
    sys.exit()
head_same = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        head_same += 1
    else:
        break
tail_same = 1
for i in range(n-1,0,-1):
    if s[i] == s[i-1]:
        tail_same += 1
    else:
        break
head_tail_same = 0
if s[0] == s[-1]:
    head_tail_same = head_same + tail_same
def return_internal_same(ls):
    i = 0
    same_count = 1
    return_value = 0
    while i < len(ls)-1:
        if ls[i] != ls[i+1]:
            i += 1
            return_value += same_count // 2
            same_count = 1
            continue
        else:
            same_count += 1
            i += 1
    return_value += same_count // 2
    return return_value
# head_tial_sameがあるかどうかで場合わけ
if head_tail_same > 0:
    ans = head_same//2 + tail_same//2
    ans += (k-1) * (head_tail_same//2)
    ans += k*(return_internal_same(s[head_same:n-tail_same]))
else:
    ans = k*(head_same//2 + tail_same//2)
    ans += (k-1) * (head_tail_same//2)
    ans += k*(return_internal_same(s[head_same:n-tail_same]))
print(ans) import sys sys s = input() s input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s all_same = True all_same True for i in range(n-1):
    if s[i] != s[i+1]:
        all_same = False i range(n-1) range n-1 n 1 if s[i] != s[i+1]:
        all_same = False s[i] != s[i+1] s[i] s i s[i+1] s i+1 i 1 all_same = False all_same False if all_same:
    print((n*k)//2)
    sys.exit() all_same print((n*k)//2) print (n*k)//2 n*k n k 2 sys.exit() sys.exit sys exit head_same = 1 head_same 1 for i in range(n-1):
    if s[i] == s[i+1]:
        head_same += 1
    else:
        break i range(n-1) range n-1 n 1 if s[i] == s[i+1]:
        head_same += 1
    else:
        break s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 head_same += 1 head_same 1 break tail_same = 1 tail_same 1 for i in range(n-1,0,-1):
    if s[i] == s[i-1]:
        tail_same += 1
    else:
        break i range(n-1,0,-1) range n-1 n 1 0 -1 if s[i] == s[i-1]:
        tail_same += 1
    else:
        break s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 tail_same += 1 tail_same 1 break head_tail_same = 0 head_tail_same 0 if s[0] == s[-1]:
    head_tail_same = head_same + tail_same s[0] == s[-1] s[0] s 0 s[-1] s -1 head_tail_same = head_same + tail_same head_tail_same head_same + tail_same head_same tail_same def return_internal_same(ls):
    i = 0
    same_count = 1
    return_value = 0
    while i < len(ls)-1:
        if ls[i] != ls[i+1]:
            i += 1
            return_value += same_count // 2
            same_count = 1
            continue
        else:
            same_count += 1
            i += 1
    return_value += same_count // 2
    return return_value
# head_tial_sameがあるかどうかで場合わけ return_internal_same i = 0 i 0 same_count = 1 same_count 1 return_value = 0 return_value 0 while i < len(ls)-1:
        if ls[i] != ls[i+1]:
            i += 1
            return_value += same_count // 2
            same_count = 1
            continue
        else:
            same_count += 1
            i += 1
     i < len(ls)-1 i len(ls)-1 len(ls) len ls 1 if ls[i] != ls[i+1]:
            i += 1
            return_value += same_count // 2
            same_count = 1
            continue
        else:
            same_count += 1
            i += 1
     ls[i] != ls[i+1] ls[i] ls i ls[i+1] ls i+1 i 1 i += 1 i 1 return_value += same_count // 2 return_value same_count // 2 same_count 2 same_count = 1 same_count 1 continue same_count += 1 same_count 1 i += 1 i 1 return_value += same_count // 2 return_value same_count // 2 same_count 2 return return_value return_value ls ls if head_tail_same > 0:
    ans = head_same//2 + tail_same//2
    ans += (k-1) * (head_tail_same//2)
    ans += k*(return_internal_same(s[head_same:n-tail_same]))
else:
    ans = k*(head_same//2 + tail_same//2)
    ans += (k-1) * (head_tail_same//2)
    ans += k*(return_internal_same(s[head_same:n-tail_same])) head_tail_same > 0 head_tail_same 0 ans = head_same//2 + tail_same//2 ans head_same//2 + tail_same//2 head_same//2 head_same 2 tail_same//2 tail_same 2 ans += (k-1) * (head_tail_same//2) ans (k-1) * (head_tail_same//2) k-1 k 1 head_tail_same//2 head_tail_same 2 ans += k*(return_internal_same(s[head_same:n-tail_same])) ans k*(return_internal_same(s[head_same:n-tail_same])) k return_internal_same(s[head_same:n-tail_same]) return_internal_same s[head_same:n-tail_same] s head_same:n-tail_same head_same n-tail_same n tail_same ans = k*(head_same//2 + tail_same//2) ans k*(head_same//2 + tail_same//2) k head_same//2 + tail_same//2 head_same//2 head_same 2 tail_same//2 tail_same 2 ans += (k-1) * (head_tail_same//2) ans (k-1) * (head_tail_same//2) k-1 k 1 head_tail_same//2 head_tail_same 2 ans += k*(return_internal_same(s[head_same:n-tail_same])) ans k*(return_internal_same(s[head_same:n-tail_same])) k return_internal_same(s[head_same:n-tail_same]) return_internal_same s[head_same:n-tail_same] s head_same:n-tail_same head_same n-tail_same n tail_same print(ans) print ans def return_internal_same(ls):
    i = 0
    same_count = 1
    return_value = 0
    while i < len(ls)-1:
        if ls[i] != ls[i+1]:
            i += 1
            return_value += same_count // 2
            same_count = 1
            continue
        else:
            same_count += 1
            i += 1
    return_value += same_count // 2
    return return_value
# head_tial_sameがあるかどうかで場合わけ def return_internal_same(ls):
    i = 0
    same_count = 1
    return_value = 0
    while i < len(ls)-1:
        if ls[i] != ls[i+1]:
            i += 1
            return_value += same_count // 2
            same_count = 1
            continue
        else:
            same_count += 1
            i += 1
    return_value += same_count // 2
    return return_value
# head_tial_sameがあるかどうかで場合わけ return_internal_same k = int(input()) int(input()) k ans += k*(return_internal_same(s[head_same:n-tail_same])) k*(return_internal_same(s[head_same:n-tail_same])) ans n = len(s) len(s) n ans += k*(return_internal_same(s[head_same:n-tail_same])) k*(return_internal_same(s[head_same:n-tail_same])) ans all_same = True True all_same ans += (k-1) * (head_tail_same//2) (k-1) * (head_tail_same//2) ans s = input() input() s tail_same = 1 1 tail_same head_tail_same = 0 0 head_tail_same head_tail_same = head_same + tail_same head_same + tail_same head_tail_same ans = k*(head_same//2 + tail_same//2) k*(head_same//2 + tail_same//2) ans head_same = 1 1 head_same tail_same += 1 1 tail_same ans += (k-1) * (head_tail_same//2) (k-1) * (head_tail_same//2) ans all_same = False False all_same ans = head_same//2 + tail_same//2 head_same//2 + tail_same//2 ans head_same += 1 1 head_same
import sys
s = input()
k = int(input())
n = len(s)
all_same = True
for i in range(n-1):
    if s[i] != s[i+1]:
        all_same = False
if all_same:
    print((n*k)//2)
    sys.exit()
head_same = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        head_same += 1
    else:
        break
tail_same = 1
for i in range(n-1,0,-1):
    if s[i] == s[i-1]:
        tail_same += 1
    else:
        break
head_tail_same = 0
if s[0] == s[-1]:
    head_tail_same = head_same + tail_same
def return_internal_same(ls):
    i = 0
    same_count = 1
    return_value = 0
    while i < len(ls)-1:
        if ls[i] != ls[i+1]:
            i += 1
            return_value += same_count // 2
            same_count = 1
            continue
        else:
            same_count += 1
            i += 1
    return_value += same_count // 2
    return return_value
# head_tial_sameがあるかどうかで場合わけ
if head_tail_same > 0:
    ans = head_same//2 + tail_same//2
    ans += (k-1) * (head_tail_same//2)
    ans += k*(return_internal_same(s[head_same:n-tail_same]))
else:
    ans = k*(head_same//2 + tail_same//2)
    ans += (k-1) * (head_tail_same//2)
    ans += k*(return_internal_same(s[head_same:n-tail_same]))
print(ans)