s = input()
k = int(input())
n = len(s)
ss = set(s)
# print(ss)
ans = 0
if len(ss) == 1:
    print(k*n//2)
    # print('y')
    exit()
if n == 1:
    print(n//2)
    exit()
streaks = []
cnt = 0
now = s[0]
for i in range(n):
    if now == s[i]:
        cnt += 1
    else:
        streaks.append(cnt)
        now = s[i]
        cnt = 1
streaks.append(cnt)
# print(streaks)
m = len(streaks)
if s[0] == s[-1]:
    for i in range(1, m-1):
        ans += streaks[i]//2
    # print(ans)
    ans *= k
    # print(ans)
    ans += (streaks[0] + streaks[m-1])//2*(k-1)
    # print(ans)
    ans += streaks[0]//2 + streaks[m-1]//2
    # print(ans)
else:
    for i in range(m):
        ans += streaks[i]//2
    ans *= k

print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s ss = set(s) ss set(s) set s ans = 0 ans 0 if len(ss) == 1:
    print(k*n//2)
    # print('y')
    exit() len(ss) == 1 len(ss) len ss 1 print(k*n//2) print k*n//2 k*n k n 2 exit() exit if n == 1:
    print(n//2)
    exit() n == 1 n 1 print(n//2) print n//2 n 2 exit() exit streaks = [] streaks [] cnt = 0 cnt 0 now = s[0] now s[0] s 0 for i in range(n):
    if now == s[i]:
        cnt += 1
    else:
        streaks.append(cnt)
        now = s[i]
        cnt = 1 i range(n) range n if now == s[i]:
        cnt += 1
    else:
        streaks.append(cnt)
        now = s[i]
        cnt = 1 now == s[i] now s[i] s i cnt += 1 cnt 1 streaks.append(cnt) streaks.append streaks append cnt now = s[i] now s[i] s i cnt = 1 cnt 1 streaks.append(cnt) streaks.append streaks append cnt m = len(streaks) m len(streaks) len streaks if s[0] == s[-1]:
    for i in range(1, m-1):
        ans += streaks[i]//2
    # print(ans)
    ans *= k
    # print(ans)
    ans += (streaks[0] + streaks[m-1])//2*(k-1)
    # print(ans)
    ans += streaks[0]//2 + streaks[m-1]//2
    # print(ans)
else:
    for i in range(m):
        ans += streaks[i]//2
    ans *= k s[0] == s[-1] s[0] s 0 s[-1] s -1 for i in range(1, m-1):
        ans += streaks[i]//2
    # print(ans)
     i range(1, m-1) range 1 m-1 m 1 ans += streaks[i]//2 ans streaks[i]//2 streaks[i] streaks i 2 ans *= k ans k ans += (streaks[0] + streaks[m-1])//2*(k-1) ans (streaks[0] + streaks[m-1])//2*(k-1) (streaks[0] + streaks[m-1])//2 streaks[0] + streaks[m-1] streaks[0] streaks 0 streaks[m-1] streaks m-1 m 1 2 k-1 k 1 ans += streaks[0]//2 + streaks[m-1]//2 ans streaks[0]//2 + streaks[m-1]//2 streaks[0]//2 streaks[0] streaks 0 2 streaks[m-1]//2 streaks[m-1] streaks m-1 m 1 2 for i in range(m):
        ans += streaks[i]//2
     i range(m) range m ans += streaks[i]//2 ans streaks[i]//2 streaks[i] streaks i 2 ans *= k ans k print(ans) print ans m = len(streaks) len(streaks) m ans *= k k ans ans *= k k ans n = len(s) len(s) n k = int(input()) int(input()) k ans += streaks[i]//2 streaks[i]//2 ans cnt += 1 1 cnt ans += (streaks[0] + streaks[m-1])//2*(k-1) (streaks[0] + streaks[m-1])//2*(k-1) ans now = s[0] s[0] now ans = 0 0 ans ans += streaks[0]//2 + streaks[m-1]//2 streaks[0]//2 + streaks[m-1]//2 ans cnt = 0 0 cnt s = input() input() s ss = set(s) set(s) ss cnt = 1 1 cnt streaks = [] [] streaks now = s[i] s[i] now ans += streaks[i]//2 streaks[i]//2 ans
s = input()
k = int(input())
n = len(s)
ss = set(s)
# print(ss)
ans = 0
if len(ss) == 1:
    print(k*n//2)
    # print('y')
    exit()
if n == 1:
    print(n//2)
    exit()
streaks = []
cnt = 0
now = s[0]
for i in range(n):
    if now == s[i]:
        cnt += 1
    else:
        streaks.append(cnt)
        now = s[i]
        cnt = 1
streaks.append(cnt)
# print(streaks)
m = len(streaks)
if s[0] == s[-1]:
    for i in range(1, m-1):
        ans += streaks[i]//2
    # print(ans)
    ans *= k
    # print(ans)
    ans += (streaks[0] + streaks[m-1])//2*(k-1)
    # print(ans)
    ans += streaks[0]//2 + streaks[m-1]//2
    # print(ans)
else:
    for i in range(m):
        ans += streaks[i]//2
    ans *= k

print(ans)
