#!/usr/bin/env python3
s = input()
n = len(s)
k = int(input())
if s.count(s[0]) == n:
    print(n * k // 2)
    exit()
# pre,post を数えた上で前から連続しているやつの長さを数えて和をとる
ans = 0  # k倍する前をおく
cnt = 1
pre, post = 0, 0
pre_bit = 1
for i in range(n - 1):
    if s[i] == s[i + 1]:
        cnt += 1
    else:
        ans += cnt // 2
        if pre_bit:
            pre = cnt
            pre_bit = 0
        cnt = 1

ans += cnt // 2
post = cnt
if s[0] != s[-1]:
    print(ans * k)
else:
    print(ans * k + (k - 1) * (-1 * (pre // 2 + post // 2) + (pre + post) // 2)) s = input() s input() input n = len(s) n len(s) len s k = int(input()) k int(input()) int input() input if s.count(s[0]) == n:
    print(n * k // 2)
    exit()
# pre,post を数えた上で前から連続しているやつの長さを数えて和をとる s.count(s[0]) == n s.count(s[0]) s.count s count s[0] s 0 n print(n * k // 2) print n * k // 2 n * k n k 2 exit() exit ans = 0 ans 0 cnt = 1 cnt 1 pre, post = 0, 0 pre 0 post 0 pre_bit = 1 pre_bit 1 for i in range(n - 1):
    if s[i] == s[i + 1]:
        cnt += 1
    else:
        ans += cnt // 2
        if pre_bit:
            pre = cnt
            pre_bit = 0
        cnt = 1 i range(n - 1) range n - 1 n 1 if s[i] == s[i + 1]:
        cnt += 1
    else:
        ans += cnt // 2
        if pre_bit:
            pre = cnt
            pre_bit = 0
        cnt = 1 s[i] == s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 cnt += 1 cnt 1 ans += cnt // 2 ans cnt // 2 cnt 2 if pre_bit:
            pre = cnt
            pre_bit = 0
         pre_bit pre = cnt pre cnt pre_bit = 0 pre_bit 0 cnt = 1 cnt 1 ans += cnt // 2 ans cnt // 2 cnt 2 post = cnt post cnt if s[0] != s[-1]:
    print(ans * k)
else:
    print(ans * k + (k - 1) * (-1 * (pre // 2 + post // 2) + (pre + post) // 2)) s[0] != s[-1] s[0] s 0 s[-1] s -1 print(ans * k) print ans * k ans k print(ans * k + (k - 1) * (-1 * (pre // 2 + post // 2) + (pre + post) // 2)) print ans * k + (k - 1) * (-1 * (pre // 2 + post // 2) + (pre + post) // 2) ans * k ans k (k - 1) * (-1 * (pre // 2 + post // 2) + (pre + post) // 2) k - 1 k 1 -1 * (pre // 2 + post // 2) + (pre + post) // 2 -1 * (pre // 2 + post // 2) -1 pre // 2 + post // 2 pre // 2 pre 2 post // 2 post 2 (pre + post) // 2 pre + post pre post 2 pre = cnt cnt pre ans += cnt // 2 cnt // 2 ans post = cnt cnt post ans = 0 0 ans k = int(input()) int(input()) k cnt += 1 1 cnt ans += cnt // 2 cnt // 2 ans cnt = 1 1 cnt pre, post = 0, 0 0 pre n = len(s) len(s) n pre_bit = 0 0 pre_bit s = input() input() s cnt = 1 1 cnt post = 0, 0 0 post pre_bit = 1 1 pre_bit
#!/usr/bin/env python3
s = input()
n = len(s)
k = int(input())
if s.count(s[0]) == n:
    print(n * k // 2)
    exit()
# pre,post を数えた上で前から連続しているやつの長さを数えて和をとる
ans = 0  # k倍する前をおく
cnt = 1
pre, post = 0, 0
pre_bit = 1
for i in range(n - 1):
    if s[i] == s[i + 1]:
        cnt += 1
    else:
        ans += cnt // 2
        if pre_bit:
            pre = cnt
            pre_bit = 0
        cnt = 1

ans += cnt // 2
post = cnt
if s[0] != s[-1]:
    print(ans * k)
else:
    print(ans * k + (k - 1) * (-1 * (pre // 2 + post // 2) + (pre + post) // 2))
